Skip to content

Commit 8db3790

Browse files
covanamglemco
authored andcommitted
rv: Convert to use lock guard
Convert to use lock guard 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/dbefeb868093c40d4b29fd6b57294a6aa011b719.1763370183.git.namcao@linutronix.de Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
1 parent 69d8895 commit 8db3790

2 files changed

Lines changed: 20 additions & 45 deletions

File tree

kernel/trace/rv/rv.c

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,13 @@ static ssize_t monitor_enable_write_data(struct file *filp, const char __user *u
375375
if (retval)
376376
return retval;
377377

378-
mutex_lock(&rv_interface_lock);
378+
guard(mutex)(&rv_interface_lock);
379379

380380
if (val)
381381
retval = rv_enable_monitor(mon);
382382
else
383383
retval = rv_disable_monitor(mon);
384384

385-
mutex_unlock(&rv_interface_lock);
386-
387385
return retval ? : count;
388386
}
389387

@@ -568,7 +566,7 @@ static void disable_all_monitors(void)
568566
struct rv_monitor *mon;
569567
int enabled = 0;
570568

571-
mutex_lock(&rv_interface_lock);
569+
guard(mutex)(&rv_interface_lock);
572570

573571
list_for_each_entry(mon, &rv_monitors_list, list)
574572
enabled += __rv_disable_monitor(mon, false);
@@ -581,8 +579,6 @@ static void disable_all_monitors(void)
581579
*/
582580
tracepoint_synchronize_unregister();
583581
}
584-
585-
mutex_unlock(&rv_interface_lock);
586582
}
587583

588584
static int enabled_monitors_open(struct inode *inode, struct file *file)
@@ -623,7 +619,7 @@ static ssize_t enabled_monitors_write(struct file *filp, const char __user *user
623619
if (!len)
624620
return count;
625621

626-
mutex_lock(&rv_interface_lock);
622+
guard(mutex)(&rv_interface_lock);
627623

628624
retval = -EINVAL;
629625

@@ -644,13 +640,11 @@ static ssize_t enabled_monitors_write(struct file *filp, const char __user *user
644640
else
645641
retval = rv_disable_monitor(mon);
646642

647-
if (!retval)
648-
retval = count;
649-
650-
break;
643+
if (retval)
644+
return retval;
645+
return count;
651646
}
652647

653-
mutex_unlock(&rv_interface_lock);
654648
return retval;
655649
}
656650

@@ -737,7 +731,7 @@ static ssize_t monitoring_on_write_data(struct file *filp, const char __user *us
737731
if (retval)
738732
return retval;
739733

740-
mutex_lock(&rv_interface_lock);
734+
guard(mutex)(&rv_interface_lock);
741735

742736
if (val)
743737
turn_monitoring_on_with_reset();
@@ -750,8 +744,6 @@ static ssize_t monitoring_on_write_data(struct file *filp, const char __user *us
750744
*/
751745
tracepoint_synchronize_unregister();
752746

753-
mutex_unlock(&rv_interface_lock);
754-
755747
return count;
756748
}
757749

@@ -784,38 +776,34 @@ int rv_register_monitor(struct rv_monitor *monitor, struct rv_monitor *parent)
784776
return -EINVAL;
785777
}
786778

787-
mutex_lock(&rv_interface_lock);
779+
guard(mutex)(&rv_interface_lock);
788780

789781
list_for_each_entry(r, &rv_monitors_list, list) {
790782
if (strcmp(monitor->name, r->name) == 0) {
791783
pr_info("Monitor %s is already registered\n", monitor->name);
792-
retval = -EEXIST;
793-
goto out_unlock;
784+
return -EEXIST;
794785
}
795786
}
796787

797788
if (parent && rv_is_nested_monitor(parent)) {
798789
pr_info("Parent monitor %s is already nested, cannot nest further\n",
799790
parent->name);
800-
retval = -EINVAL;
801-
goto out_unlock;
791+
return -EINVAL;
802792
}
803793

804794
monitor->parent = parent;
805795

806796
retval = create_monitor_dir(monitor, parent);
807797
if (retval)
808-
goto out_unlock;
798+
return retval;
809799

810800
/* keep children close to the parent for easier visualisation */
811801
if (parent)
812802
list_add(&monitor->list, &parent->list);
813803
else
814804
list_add_tail(&monitor->list, &rv_monitors_list);
815805

816-
out_unlock:
817-
mutex_unlock(&rv_interface_lock);
818-
return retval;
806+
return 0;
819807
}
820808

821809
/**
@@ -826,13 +814,12 @@ int rv_register_monitor(struct rv_monitor *monitor, struct rv_monitor *parent)
826814
*/
827815
int rv_unregister_monitor(struct rv_monitor *monitor)
828816
{
829-
mutex_lock(&rv_interface_lock);
817+
guard(mutex)(&rv_interface_lock);
830818

831819
rv_disable_monitor(monitor);
832820
list_del(&monitor->list);
833821
destroy_monitor_dir(monitor);
834822

835-
mutex_unlock(&rv_interface_lock);
836823
return 0;
837824
}
838825

kernel/trace/rv/rv_reactors.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -233,23 +233,18 @@ monitor_reactors_write(struct file *file, const char __user *user_buf,
233233
seq_f = file->private_data;
234234
mon = seq_f->private;
235235

236-
mutex_lock(&rv_interface_lock);
237-
238-
retval = -EINVAL;
236+
guard(mutex)(&rv_interface_lock);
239237

240238
list_for_each_entry(reactor, &rv_reactors_list, list) {
241239
if (strcmp(ptr, reactor->name) != 0)
242240
continue;
243241

244242
monitor_swap_reactors(mon, reactor);
245243

246-
retval = count;
247-
break;
244+
return count;
248245
}
249246

250-
mutex_unlock(&rv_interface_lock);
251-
252-
return retval;
247+
return -EINVAL;
253248
}
254249

255250
/*
@@ -310,18 +305,14 @@ static int __rv_register_reactor(struct rv_reactor *reactor)
310305
*/
311306
int rv_register_reactor(struct rv_reactor *reactor)
312307
{
313-
int retval = 0;
314-
315308
if (strlen(reactor->name) >= MAX_RV_REACTOR_NAME_SIZE) {
316309
pr_info("Reactor %s has a name longer than %d\n",
317310
reactor->name, MAX_RV_MONITOR_NAME_SIZE);
318311
return -EINVAL;
319312
}
320313

321-
mutex_lock(&rv_interface_lock);
322-
retval = __rv_register_reactor(reactor);
323-
mutex_unlock(&rv_interface_lock);
324-
return retval;
314+
guard(mutex)(&rv_interface_lock);
315+
return __rv_register_reactor(reactor);
325316
}
326317

327318
/**
@@ -332,9 +323,8 @@ int rv_register_reactor(struct rv_reactor *reactor)
332323
*/
333324
int rv_unregister_reactor(struct rv_reactor *reactor)
334325
{
335-
mutex_lock(&rv_interface_lock);
326+
guard(mutex)(&rv_interface_lock);
336327
list_del(&reactor->list);
337-
mutex_unlock(&rv_interface_lock);
338328
return 0;
339329
}
340330

@@ -390,7 +380,7 @@ static ssize_t reacting_on_write_data(struct file *filp, const char __user *user
390380
if (retval)
391381
return retval;
392382

393-
mutex_lock(&rv_interface_lock);
383+
guard(mutex)(&rv_interface_lock);
394384

395385
if (val)
396386
turn_reacting_on();
@@ -403,8 +393,6 @@ static ssize_t reacting_on_write_data(struct file *filp, const char __user *user
403393
*/
404394
tracepoint_synchronize_unregister();
405395

406-
mutex_unlock(&rv_interface_lock);
407-
408396
return count;
409397
}
410398

0 commit comments

Comments
 (0)