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

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>

authored by

Nam Cao and committed by
Gabriele Monaco
8db3790c 69d8895c

+20 -45
+13 -26
kernel/trace/rv/rv.c
··· 375 375 if (retval) 376 376 return retval; 377 377 378 - mutex_lock(&rv_interface_lock); 378 + guard(mutex)(&rv_interface_lock); 379 379 380 380 if (val) 381 381 retval = rv_enable_monitor(mon); 382 382 else 383 383 retval = rv_disable_monitor(mon); 384 - 385 - mutex_unlock(&rv_interface_lock); 386 384 387 385 return retval ? : count; 388 386 } ··· 566 568 struct rv_monitor *mon; 567 569 int enabled = 0; 568 570 569 - mutex_lock(&rv_interface_lock); 571 + guard(mutex)(&rv_interface_lock); 570 572 571 573 list_for_each_entry(mon, &rv_monitors_list, list) 572 574 enabled += __rv_disable_monitor(mon, false); ··· 579 581 */ 580 582 tracepoint_synchronize_unregister(); 581 583 } 582 - 583 - mutex_unlock(&rv_interface_lock); 584 584 } 585 585 586 586 static int enabled_monitors_open(struct inode *inode, struct file *file) ··· 619 623 if (!len) 620 624 return count; 621 625 622 - mutex_lock(&rv_interface_lock); 626 + guard(mutex)(&rv_interface_lock); 623 627 624 628 retval = -EINVAL; 625 629 ··· 640 644 else 641 645 retval = rv_disable_monitor(mon); 642 646 643 - if (!retval) 644 - retval = count; 645 - 646 - break; 647 + if (retval) 648 + return retval; 649 + return count; 647 650 } 648 651 649 - mutex_unlock(&rv_interface_lock); 650 652 return retval; 651 653 } 652 654 ··· 731 737 if (retval) 732 738 return retval; 733 739 734 - mutex_lock(&rv_interface_lock); 740 + guard(mutex)(&rv_interface_lock); 735 741 736 742 if (val) 737 743 turn_monitoring_on_with_reset(); ··· 743 749 * before returning to user-space. 744 750 */ 745 751 tracepoint_synchronize_unregister(); 746 - 747 - mutex_unlock(&rv_interface_lock); 748 752 749 753 return count; 750 754 } ··· 776 784 return -EINVAL; 777 785 } 778 786 779 - mutex_lock(&rv_interface_lock); 787 + guard(mutex)(&rv_interface_lock); 780 788 781 789 list_for_each_entry(r, &rv_monitors_list, list) { 782 790 if (strcmp(monitor->name, r->name) == 0) { 783 791 pr_info("Monitor %s is already registered\n", monitor->name); 784 - retval = -EEXIST; 785 - goto out_unlock; 792 + return -EEXIST; 786 793 } 787 794 } 788 795 789 796 if (parent && rv_is_nested_monitor(parent)) { 790 797 pr_info("Parent monitor %s is already nested, cannot nest further\n", 791 798 parent->name); 792 - retval = -EINVAL; 793 - goto out_unlock; 799 + return -EINVAL; 794 800 } 795 801 796 802 monitor->parent = parent; 797 803 798 804 retval = create_monitor_dir(monitor, parent); 799 805 if (retval) 800 - goto out_unlock; 806 + return retval; 801 807 802 808 /* keep children close to the parent for easier visualisation */ 803 809 if (parent) ··· 803 813 else 804 814 list_add_tail(&monitor->list, &rv_monitors_list); 805 815 806 - out_unlock: 807 - mutex_unlock(&rv_interface_lock); 808 - return retval; 816 + return 0; 809 817 } 810 818 811 819 /** ··· 814 826 */ 815 827 int rv_unregister_monitor(struct rv_monitor *monitor) 816 828 { 817 - mutex_lock(&rv_interface_lock); 829 + guard(mutex)(&rv_interface_lock); 818 830 819 831 rv_disable_monitor(monitor); 820 832 list_del(&monitor->list); 821 833 destroy_monitor_dir(monitor); 822 834 823 - mutex_unlock(&rv_interface_lock); 824 835 return 0; 825 836 } 826 837
+7 -19
kernel/trace/rv/rv_reactors.c
··· 233 233 seq_f = file->private_data; 234 234 mon = seq_f->private; 235 235 236 - mutex_lock(&rv_interface_lock); 237 - 238 - retval = -EINVAL; 236 + guard(mutex)(&rv_interface_lock); 239 237 240 238 list_for_each_entry(reactor, &rv_reactors_list, list) { 241 239 if (strcmp(ptr, reactor->name) != 0) ··· 241 243 242 244 monitor_swap_reactors(mon, reactor); 243 245 244 - retval = count; 245 - break; 246 + return count; 246 247 } 247 248 248 - mutex_unlock(&rv_interface_lock); 249 - 250 - return retval; 249 + return -EINVAL; 251 250 } 252 251 253 252 /* ··· 305 310 */ 306 311 int rv_register_reactor(struct rv_reactor *reactor) 307 312 { 308 - int retval = 0; 309 - 310 313 if (strlen(reactor->name) >= MAX_RV_REACTOR_NAME_SIZE) { 311 314 pr_info("Reactor %s has a name longer than %d\n", 312 315 reactor->name, MAX_RV_MONITOR_NAME_SIZE); 313 316 return -EINVAL; 314 317 } 315 318 316 - mutex_lock(&rv_interface_lock); 317 - retval = __rv_register_reactor(reactor); 318 - mutex_unlock(&rv_interface_lock); 319 - return retval; 319 + guard(mutex)(&rv_interface_lock); 320 + return __rv_register_reactor(reactor); 320 321 } 321 322 322 323 /** ··· 323 332 */ 324 333 int rv_unregister_reactor(struct rv_reactor *reactor) 325 334 { 326 - mutex_lock(&rv_interface_lock); 335 + guard(mutex)(&rv_interface_lock); 327 336 list_del(&reactor->list); 328 - mutex_unlock(&rv_interface_lock); 329 337 return 0; 330 338 } 331 339 ··· 380 390 if (retval) 381 391 return retval; 382 392 383 - mutex_lock(&rv_interface_lock); 393 + guard(mutex)(&rv_interface_lock); 384 394 385 395 if (val) 386 396 turn_reacting_on(); ··· 392 402 * before returning to user-space. 393 403 */ 394 404 tracepoint_synchronize_unregister(); 395 - 396 - mutex_unlock(&rv_interface_lock); 397 405 398 406 return count; 399 407 }