Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rv: Convert to use __free

Convert to use __free to tidy up the code.

Signed-off-by: Nam Cao <namcao@linutronix.de>
Reviewed-by: Gabriele Monaco <gmonaco@redhat.com>
Link: https://lore.kernel.org/r/62854e2fcb8f8dd2180a98a9700702dcf89a6980.1763370183.git.namcao@linutronix.de
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>

authored by

Nam Cao and committed by
Gabriele Monaco
b30f635b 8db3790c

+46 -58
+26 -37
kernel/trace/rv/rv.c
··· 420 420 static int create_monitor_dir(struct rv_monitor *mon, struct rv_monitor *parent) 421 421 { 422 422 struct dentry *root = parent ? parent->root_d : get_monitors_root(); 423 - const char *name = mon->name; 423 + struct dentry *dir __free(rv_remove) = rv_create_dir(mon->name, root); 424 424 struct dentry *tmp; 425 425 int retval; 426 426 427 - mon->root_d = rv_create_dir(name, root); 428 - if (!mon->root_d) 427 + if (!dir) 429 428 return -ENOMEM; 430 429 431 - tmp = rv_create_file("enable", RV_MODE_WRITE, mon->root_d, mon, &interface_enable_fops); 432 - if (!tmp) { 433 - retval = -ENOMEM; 434 - goto out_remove_root; 435 - } 430 + tmp = rv_create_file("enable", RV_MODE_WRITE, dir, mon, &interface_enable_fops); 431 + if (!tmp) 432 + return -ENOMEM; 436 433 437 - tmp = rv_create_file("desc", RV_MODE_READ, mon->root_d, mon, &interface_desc_fops); 438 - if (!tmp) { 439 - retval = -ENOMEM; 440 - goto out_remove_root; 441 - } 434 + tmp = rv_create_file("desc", RV_MODE_READ, dir, mon, &interface_desc_fops); 435 + if (!tmp) 436 + return -ENOMEM; 442 437 443 - retval = reactor_populate_monitor(mon); 438 + retval = reactor_populate_monitor(mon, dir); 444 439 if (retval) 445 - goto out_remove_root; 440 + return retval; 446 441 442 + mon->root_d = no_free_ptr(dir); 447 443 return 0; 448 - 449 - out_remove_root: 450 - rv_remove(mon->root_d); 451 - return retval; 452 444 } 453 445 454 446 /* ··· 819 827 { 820 828 struct dentry *tmp; 821 829 int retval; 830 + struct dentry *root_dir __free(rv_remove) = rv_create_dir("rv", NULL); 822 831 823 - rv_root.root_dir = rv_create_dir("rv", NULL); 824 - if (!rv_root.root_dir) 825 - goto out_err; 832 + if (!root_dir) 833 + return 1; 826 834 827 - rv_root.monitors_dir = rv_create_dir("monitors", rv_root.root_dir); 835 + rv_root.monitors_dir = rv_create_dir("monitors", root_dir); 828 836 if (!rv_root.monitors_dir) 829 - goto out_err; 837 + return 1; 830 838 831 - tmp = rv_create_file("available_monitors", RV_MODE_READ, rv_root.root_dir, NULL, 839 + tmp = rv_create_file("available_monitors", RV_MODE_READ, root_dir, NULL, 832 840 &available_monitors_ops); 833 841 if (!tmp) 834 - goto out_err; 842 + return 1; 835 843 836 - tmp = rv_create_file("enabled_monitors", RV_MODE_WRITE, rv_root.root_dir, NULL, 844 + tmp = rv_create_file("enabled_monitors", RV_MODE_WRITE, root_dir, NULL, 837 845 &enabled_monitors_ops); 838 846 if (!tmp) 839 - goto out_err; 847 + return 1; 840 848 841 - tmp = rv_create_file("monitoring_on", RV_MODE_WRITE, rv_root.root_dir, NULL, 849 + tmp = rv_create_file("monitoring_on", RV_MODE_WRITE, root_dir, NULL, 842 850 &monitoring_on_fops); 843 851 if (!tmp) 844 - goto out_err; 845 - retval = init_rv_reactors(rv_root.root_dir); 852 + return 1; 853 + retval = init_rv_reactors(root_dir); 846 854 if (retval) 847 - goto out_err; 855 + return 1; 848 856 849 857 turn_monitoring_on(); 850 858 851 - return 0; 859 + rv_root.root_dir = no_free_ptr(root_dir); 852 860 853 - out_err: 854 - rv_remove(rv_root.root_dir); 855 - printk(KERN_ERR "RV: Error while creating the RV interface\n"); 856 - return 1; 861 + return 0; 857 862 }
+4 -2
kernel/trace/rv/rv.h
··· 17 17 #define rv_create_file tracefs_create_file 18 18 #define rv_remove tracefs_remove 19 19 20 + DEFINE_FREE(rv_remove, struct dentry *, if (_T) rv_remove(_T)); 21 + 20 22 #define MAX_RV_MONITOR_NAME_SIZE 32 21 23 #define MAX_RV_REACTOR_NAME_SIZE 32 22 24 ··· 32 30 bool rv_is_nested_monitor(struct rv_monitor *mon); 33 31 34 32 #ifdef CONFIG_RV_REACTORS 35 - int reactor_populate_monitor(struct rv_monitor *mon); 33 + int reactor_populate_monitor(struct rv_monitor *mon, struct dentry *root); 36 34 int init_rv_reactors(struct dentry *root_dir); 37 35 #else 38 - static inline int reactor_populate_monitor(struct rv_monitor *mon) 36 + static inline int reactor_populate_monitor(struct rv_monitor *mon, struct dentry *root) 39 37 { 40 38 return 0; 41 39 }
+14 -18
kernel/trace/rv/rv_reactors.c
··· 405 405 /** 406 406 * reactor_populate_monitor - creates per monitor reactors file 407 407 * @mon: The monitor. 408 + * @root: The directory of the monitor. 408 409 * 409 410 * Returns 0 if successful, error otherwise. 410 411 */ 411 - int reactor_populate_monitor(struct rv_monitor *mon) 412 + int reactor_populate_monitor(struct rv_monitor *mon, struct dentry *root) 412 413 { 413 414 struct dentry *tmp; 414 415 415 - tmp = rv_create_file("reactors", RV_MODE_WRITE, mon->root_d, mon, &monitor_reactors_ops); 416 + tmp = rv_create_file("reactors", RV_MODE_WRITE, root, mon, &monitor_reactors_ops); 416 417 if (!tmp) 417 418 return -ENOMEM; 418 419 ··· 440 439 441 440 int init_rv_reactors(struct dentry *root_dir) 442 441 { 443 - struct dentry *available, *reacting; 444 442 int retval; 445 443 446 - available = rv_create_file("available_reactors", RV_MODE_READ, root_dir, NULL, 447 - &available_reactors_ops); 448 - if (!available) 449 - goto out_err; 444 + struct dentry *available __free(rv_remove) = 445 + rv_create_file("available_reactors", RV_MODE_READ, root_dir, 446 + NULL, &available_reactors_ops); 450 447 451 - reacting = rv_create_file("reacting_on", RV_MODE_WRITE, root_dir, NULL, &reacting_on_fops); 452 - if (!reacting) 453 - goto rm_available; 448 + struct dentry *reacting __free(rv_remove) = 449 + rv_create_file("reacting_on", RV_MODE_WRITE, root_dir, NULL, &reacting_on_fops); 450 + 451 + if (!reacting || !available) 452 + return -ENOMEM; 454 453 455 454 retval = __rv_register_reactor(&rv_nop); 456 455 if (retval) 457 - goto rm_reacting; 456 + return retval; 458 457 459 458 turn_reacting_on(); 460 459 460 + retain_and_null_ptr(available); 461 + retain_and_null_ptr(reacting); 461 462 return 0; 462 - 463 - rm_reacting: 464 - rv_remove(reacting); 465 - rm_available: 466 - rv_remove(available); 467 - out_err: 468 - return -ENOMEM; 469 463 } 470 464 471 465 void rv_react(struct rv_monitor *monitor, const char *msg, ...)
+2 -1
kernel/trace/trace.c
··· 10640 10640 tracer_init_tracefs_work_func(NULL); 10641 10641 } 10642 10642 10643 - rv_init_interface(); 10643 + if (rv_init_interface()) 10644 + pr_err("RV: Error while creating the RV interface\n"); 10644 10645 10645 10646 return 0; 10646 10647 }