Skip to content

Commit b30f635

Browse files
covanamglemco
authored andcommitted
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>
1 parent 8db3790 commit b30f635

4 files changed

Lines changed: 46 additions & 58 deletions

File tree

kernel/trace/rv/rv.c

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -420,35 +420,27 @@ static const struct file_operations interface_desc_fops = {
420420
static int create_monitor_dir(struct rv_monitor *mon, struct rv_monitor *parent)
421421
{
422422
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);
424424
struct dentry *tmp;
425425
int retval;
426426

427-
mon->root_d = rv_create_dir(name, root);
428-
if (!mon->root_d)
427+
if (!dir)
429428
return -ENOMEM;
430429

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;
436433

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;
442437

443-
retval = reactor_populate_monitor(mon);
438+
retval = reactor_populate_monitor(mon, dir);
444439
if (retval)
445-
goto out_remove_root;
440+
return retval;
446441

442+
mon->root_d = no_free_ptr(dir);
447443
return 0;
448-
449-
out_remove_root:
450-
rv_remove(mon->root_d);
451-
return retval;
452444
}
453445

454446
/*
@@ -827,39 +819,36 @@ int __init rv_init_interface(void)
827819
{
828820
struct dentry *tmp;
829821
int retval;
822+
struct dentry *root_dir __free(rv_remove) = rv_create_dir("rv", NULL);
830823

831-
rv_root.root_dir = rv_create_dir("rv", NULL);
832-
if (!rv_root.root_dir)
833-
goto out_err;
824+
if (!root_dir)
825+
return 1;
834826

835-
rv_root.monitors_dir = rv_create_dir("monitors", rv_root.root_dir);
827+
rv_root.monitors_dir = rv_create_dir("monitors", root_dir);
836828
if (!rv_root.monitors_dir)
837-
goto out_err;
829+
return 1;
838830

839-
tmp = rv_create_file("available_monitors", RV_MODE_READ, rv_root.root_dir, NULL,
831+
tmp = rv_create_file("available_monitors", RV_MODE_READ, root_dir, NULL,
840832
&available_monitors_ops);
841833
if (!tmp)
842-
goto out_err;
834+
return 1;
843835

844-
tmp = rv_create_file("enabled_monitors", RV_MODE_WRITE, rv_root.root_dir, NULL,
836+
tmp = rv_create_file("enabled_monitors", RV_MODE_WRITE, root_dir, NULL,
845837
&enabled_monitors_ops);
846838
if (!tmp)
847-
goto out_err;
839+
return 1;
848840

849-
tmp = rv_create_file("monitoring_on", RV_MODE_WRITE, rv_root.root_dir, NULL,
841+
tmp = rv_create_file("monitoring_on", RV_MODE_WRITE, root_dir, NULL,
850842
&monitoring_on_fops);
851843
if (!tmp)
852-
goto out_err;
853-
retval = init_rv_reactors(rv_root.root_dir);
844+
return 1;
845+
retval = init_rv_reactors(root_dir);
854846
if (retval)
855-
goto out_err;
847+
return 1;
856848

857849
turn_monitoring_on();
858850

859-
return 0;
851+
rv_root.root_dir = no_free_ptr(root_dir);
860852

861-
out_err:
862-
rv_remove(rv_root.root_dir);
863-
printk(KERN_ERR "RV: Error while creating the RV interface\n");
864-
return 1;
853+
return 0;
865854
}

kernel/trace/rv/rv.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ struct rv_interface {
1717
#define rv_create_file tracefs_create_file
1818
#define rv_remove tracefs_remove
1919

20+
DEFINE_FREE(rv_remove, struct dentry *, if (_T) rv_remove(_T));
21+
2022
#define MAX_RV_MONITOR_NAME_SIZE 32
2123
#define MAX_RV_REACTOR_NAME_SIZE 32
2224

@@ -30,10 +32,10 @@ bool rv_is_container_monitor(struct rv_monitor *mon);
3032
bool rv_is_nested_monitor(struct rv_monitor *mon);
3133

3234
#ifdef CONFIG_RV_REACTORS
33-
int reactor_populate_monitor(struct rv_monitor *mon);
35+
int reactor_populate_monitor(struct rv_monitor *mon, struct dentry *root);
3436
int init_rv_reactors(struct dentry *root_dir);
3537
#else
36-
static inline int reactor_populate_monitor(struct rv_monitor *mon)
38+
static inline int reactor_populate_monitor(struct rv_monitor *mon, struct dentry *root)
3739
{
3840
return 0;
3941
}

kernel/trace/rv/rv_reactors.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,15 @@ static const struct file_operations reacting_on_fops = {
405405
/**
406406
* reactor_populate_monitor - creates per monitor reactors file
407407
* @mon: The monitor.
408+
* @root: The directory of the monitor.
408409
*
409410
* Returns 0 if successful, error otherwise.
410411
*/
411-
int reactor_populate_monitor(struct rv_monitor *mon)
412+
int reactor_populate_monitor(struct rv_monitor *mon, struct dentry *root)
412413
{
413414
struct dentry *tmp;
414415

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);
416417
if (!tmp)
417418
return -ENOMEM;
418419

@@ -439,32 +440,27 @@ static struct rv_reactor rv_nop = {
439440

440441
int init_rv_reactors(struct dentry *root_dir)
441442
{
442-
struct dentry *available, *reacting;
443443
int retval;
444444

445-
available = rv_create_file("available_reactors", RV_MODE_READ, root_dir, NULL,
446-
&available_reactors_ops);
447-
if (!available)
448-
goto out_err;
445+
struct dentry *available __free(rv_remove) =
446+
rv_create_file("available_reactors", RV_MODE_READ, root_dir,
447+
NULL, &available_reactors_ops);
449448

450-
reacting = rv_create_file("reacting_on", RV_MODE_WRITE, root_dir, NULL, &reacting_on_fops);
451-
if (!reacting)
452-
goto rm_available;
449+
struct dentry *reacting __free(rv_remove) =
450+
rv_create_file("reacting_on", RV_MODE_WRITE, root_dir, NULL, &reacting_on_fops);
451+
452+
if (!reacting || !available)
453+
return -ENOMEM;
453454

454455
retval = __rv_register_reactor(&rv_nop);
455456
if (retval)
456-
goto rm_reacting;
457+
return retval;
457458

458459
turn_reacting_on();
459460

461+
retain_and_null_ptr(available);
462+
retain_and_null_ptr(reacting);
460463
return 0;
461-
462-
rm_reacting:
463-
rv_remove(reacting);
464-
rm_available:
465-
rv_remove(available);
466-
out_err:
467-
return -ENOMEM;
468464
}
469465

470466
void rv_react(struct rv_monitor *monitor, const char *msg, ...)

kernel/trace/trace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10640,7 +10640,8 @@ static __init int tracer_init_tracefs(void)
1064010640
tracer_init_tracefs_work_func(NULL);
1064110641
}
1064210642

10643-
rv_init_interface();
10643+
if (rv_init_interface())
10644+
pr_err("RV: Error while creating the RV interface\n");
1064410645

1064510646
return 0;
1064610647
}

0 commit comments

Comments
 (0)