]> Gentwo Git Trees - linux/.git/commitdiff
rv: Convert to use __free
authorNam Cao <namcao@linutronix.de>
Mon, 17 Nov 2025 09:06:03 +0000 (09:06 +0000)
committerGabriele Monaco <gmonaco@redhat.com>
Tue, 2 Dec 2025 06:28:32 +0000 (07:28 +0100)
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>
kernel/trace/rv/rv.c
kernel/trace/rv/rv.h
kernel/trace/rv/rv_reactors.c
kernel/trace/trace.c

index b1059a3cf4fa55f489a8e090576c2a805fde1f56..ee4e68102f17591e3116a205019de5e3569bf61a 100644 (file)
@@ -420,35 +420,27 @@ static const struct file_operations interface_desc_fops = {
 static int create_monitor_dir(struct rv_monitor *mon, struct rv_monitor *parent)
 {
        struct dentry *root = parent ? parent->root_d : get_monitors_root();
-       const char *name = mon->name;
+       struct dentry *dir __free(rv_remove) = rv_create_dir(mon->name, root);
        struct dentry *tmp;
        int retval;
 
-       mon->root_d = rv_create_dir(name, root);
-       if (!mon->root_d)
+       if (!dir)
                return -ENOMEM;
 
-       tmp = rv_create_file("enable", RV_MODE_WRITE, mon->root_d, mon, &interface_enable_fops);
-       if (!tmp) {
-               retval = -ENOMEM;
-               goto out_remove_root;
-       }
+       tmp = rv_create_file("enable", RV_MODE_WRITE, dir, mon, &interface_enable_fops);
+       if (!tmp)
+               return -ENOMEM;
 
-       tmp = rv_create_file("desc", RV_MODE_READ, mon->root_d, mon, &interface_desc_fops);
-       if (!tmp) {
-               retval = -ENOMEM;
-               goto out_remove_root;
-       }
+       tmp = rv_create_file("desc", RV_MODE_READ, dir, mon, &interface_desc_fops);
+       if (!tmp)
+               return -ENOMEM;
 
-       retval = reactor_populate_monitor(mon);
+       retval = reactor_populate_monitor(mon, dir);
        if (retval)
-               goto out_remove_root;
+               return retval;
 
+       mon->root_d = no_free_ptr(dir);
        return 0;
-
-out_remove_root:
-       rv_remove(mon->root_d);
-       return retval;
 }
 
 /*
@@ -827,39 +819,36 @@ int __init rv_init_interface(void)
 {
        struct dentry *tmp;
        int retval;
+       struct dentry *root_dir __free(rv_remove) = rv_create_dir("rv", NULL);
 
-       rv_root.root_dir = rv_create_dir("rv", NULL);
-       if (!rv_root.root_dir)
-               goto out_err;
+       if (!root_dir)
+               return 1;
 
-       rv_root.monitors_dir = rv_create_dir("monitors", rv_root.root_dir);
+       rv_root.monitors_dir = rv_create_dir("monitors", root_dir);
        if (!rv_root.monitors_dir)
-               goto out_err;
+               return 1;
 
-       tmp = rv_create_file("available_monitors", RV_MODE_READ, rv_root.root_dir, NULL,
+       tmp = rv_create_file("available_monitors", RV_MODE_READ, root_dir, NULL,
                             &available_monitors_ops);
        if (!tmp)
-               goto out_err;
+               return 1;
 
-       tmp = rv_create_file("enabled_monitors", RV_MODE_WRITE, rv_root.root_dir, NULL,
+       tmp = rv_create_file("enabled_monitors", RV_MODE_WRITE, root_dir, NULL,
                             &enabled_monitors_ops);
        if (!tmp)
-               goto out_err;
+               return 1;
 
-       tmp = rv_create_file("monitoring_on", RV_MODE_WRITE, rv_root.root_dir, NULL,
+       tmp = rv_create_file("monitoring_on", RV_MODE_WRITE, root_dir, NULL,
                             &monitoring_on_fops);
        if (!tmp)
-               goto out_err;
-       retval = init_rv_reactors(rv_root.root_dir);
+               return 1;
+       retval = init_rv_reactors(root_dir);
        if (retval)
-               goto out_err;
+               return 1;
 
        turn_monitoring_on();
 
-       return 0;
+       rv_root.root_dir = no_free_ptr(root_dir);
 
-out_err:
-       rv_remove(rv_root.root_dir);
-       printk(KERN_ERR "RV: Error while creating the RV interface\n");
-       return 1;
+       return 0;
 }
index 1485a70c1bf4f2932331c3dac28373de041fb905..2c0f51ff9d5caad139e1f973b4c749564344635d 100644 (file)
@@ -17,6 +17,8 @@ struct rv_interface {
 #define rv_create_file                 tracefs_create_file
 #define rv_remove                      tracefs_remove
 
+DEFINE_FREE(rv_remove, struct dentry *, if (_T) rv_remove(_T));
+
 #define MAX_RV_MONITOR_NAME_SIZE       32
 #define MAX_RV_REACTOR_NAME_SIZE       32
 
@@ -30,10 +32,10 @@ bool rv_is_container_monitor(struct rv_monitor *mon);
 bool rv_is_nested_monitor(struct rv_monitor *mon);
 
 #ifdef CONFIG_RV_REACTORS
-int reactor_populate_monitor(struct rv_monitor *mon);
+int reactor_populate_monitor(struct rv_monitor *mon, struct dentry *root);
 int init_rv_reactors(struct dentry *root_dir);
 #else
-static inline int reactor_populate_monitor(struct rv_monitor *mon)
+static inline int reactor_populate_monitor(struct rv_monitor *mon, struct dentry *root)
 {
        return 0;
 }
index efbff30ee3101c0146251eb0a319f421ab572300..460af07f7abac783dea1931b39f905618f89edd5 100644 (file)
@@ -405,14 +405,15 @@ static const struct file_operations reacting_on_fops = {
 /**
  * reactor_populate_monitor - creates per monitor reactors file
  * @mon:       The monitor.
+ * @root:      The directory of the monitor.
  *
  * Returns 0 if successful, error otherwise.
  */
-int reactor_populate_monitor(struct rv_monitor *mon)
+int reactor_populate_monitor(struct rv_monitor *mon, struct dentry *root)
 {
        struct dentry *tmp;
 
-       tmp = rv_create_file("reactors", RV_MODE_WRITE, mon->root_d, mon, &monitor_reactors_ops);
+       tmp = rv_create_file("reactors", RV_MODE_WRITE, root, mon, &monitor_reactors_ops);
        if (!tmp)
                return -ENOMEM;
 
@@ -439,32 +440,27 @@ static struct rv_reactor rv_nop = {
 
 int init_rv_reactors(struct dentry *root_dir)
 {
-       struct dentry *available, *reacting;
        int retval;
 
-       available = rv_create_file("available_reactors", RV_MODE_READ, root_dir, NULL,
-                                  &available_reactors_ops);
-       if (!available)
-               goto out_err;
+       struct dentry *available __free(rv_remove) =
+               rv_create_file("available_reactors", RV_MODE_READ, root_dir,
+                               NULL, &available_reactors_ops);
 
-       reacting = rv_create_file("reacting_on", RV_MODE_WRITE, root_dir, NULL, &reacting_on_fops);
-       if (!reacting)
-               goto rm_available;
+       struct dentry *reacting __free(rv_remove) =
+               rv_create_file("reacting_on", RV_MODE_WRITE, root_dir, NULL, &reacting_on_fops);
+
+       if (!reacting || !available)
+               return -ENOMEM;
 
        retval = __rv_register_reactor(&rv_nop);
        if (retval)
-               goto rm_reacting;
+               return retval;
 
        turn_reacting_on();
 
+       retain_and_null_ptr(available);
+       retain_and_null_ptr(reacting);
        return 0;
-
-rm_reacting:
-       rv_remove(reacting);
-rm_available:
-       rv_remove(available);
-out_err:
-       return -ENOMEM;
 }
 
 void rv_react(struct rv_monitor *monitor, const char *msg, ...)
index d1e527cf2aae07c3ab97cf89e11e71f4a9c0946c..cd209598d670f2086e260347b280524e742d9427 100644 (file)
@@ -10640,7 +10640,8 @@ static __init int tracer_init_tracefs(void)
                tracer_init_tracefs_work_func(NULL);
        }
 
-       rv_init_interface();
+       if (rv_init_interface())
+               pr_err("RV: Error while creating the RV interface\n");
 
        return 0;
 }