Re: kernel/trace/rv/rv.c:812:2-8: preceding lock on line 790 (fwd)

From: Gabriele Monaco
Date: Wed Apr 02 2025 - 02:25:42 EST


On Sun, 2025-03-30 at 20:37 +0200, Julia Lawall wrote:
> Please check on whether line 812 needs an unlock.
>

Hi,

thanks for reporting!
Indeed that needs an unlock, I missed it after moving some code around,
preparing the fix.

Gabriele


> julia
>
> ---------- Forwarded message ----------
> Date: Mon, 31 Mar 2025 02:25:17 +0800
> From: kernel test robot <lkp@xxxxxxxxx>
> To: oe-kbuild@xxxxxxxxxxxxxxx
> Cc: lkp@xxxxxxxxx, Julia Lawall <julia.lawall@xxxxxxxx>
> Subject: kernel/trace/rv/rv.c:812:2-8: preceding lock on line 790
>
> BCC: lkp@xxxxxxxxx
> CC: oe-kbuild-all@xxxxxxxxxxxxxxx
> CC: linux-kernel@xxxxxxxxxxxxxxx
> TO: Gabriele Monaco <gmonaco@xxxxxxxxxx>
> CC: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>
>
> tree:  
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ma
> ster
> head:   7f2ff7b6261742ed52aa973ccdf99151b7cc3a50
> commit: cb85c660fcd4b3a03ed993affa0b2d1a8af2f06b rv: Add option for
> nested monitors and include sched
> date:   6 days ago
> :::::: branch date: 17 hours ago
> :::::: commit date: 6 days ago
> config: loongarch-randconfig-r061-20250330
> (https://download.01.org/0day-ci/archive/20250331/202503310200.UBXGit
> B4-lkp@xxxxxxxxx/config)
> compiler: loongarch64-linux-gcc (GCC) 14.2.0
>
> If you fix the issue in a separate patch/commit (i.e. not just a new
> version of
> the same patch/commit), kindly add following tags
> > Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > Reported-by: Julia Lawall <julia.lawall@xxxxxxxx>
> > Closes:
> > https://lore.kernel.org/r/202503310200.UBXGitB4-lkp@xxxxxxxxx/
>
> cocci warnings: (new ones prefixed by >>)
> > > kernel/trace/rv/rv.c:812:2-8: preceding lock on line 790
>
> vim +812 kernel/trace/rv/rv.c
>
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  771
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  772  /**
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  773   *
> rv_register_monitor - register a rv monitor.
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  774   *
> @monitor:    The rv_monitor to be registered.
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  775   *
> @parent:     The parent of the monitor to be registered, NULL if not
> nested.
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  776   *
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  777   *
> Returns 0 if successful, error otherwise.
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  778   */
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  779  int
> rv_register_monitor(struct rv_monitor *monitor, struct rv_monitor
> *parent)
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  780  {
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 781   struct rv_monitor_def *r, *p = NULL;
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  782   int
> retval = 0;
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  783
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  784   if
> (strlen(monitor->name) >= MAX_RV_MONITOR_NAME_SIZE) {
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 785   pr_info("Monitor %s has a name longer than %d\n", monitor->name,
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 786   MAX_RV_MONITOR_NAME_SIZE);
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 787   return -EINVAL;
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  788   }
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  789
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29
> @790   mutex_lock(&rv_interface_lock);
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  791
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 792   list_for_each_entry(r, &rv_monitors_list, list) {
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 793   if (strcmp(monitor->name, r->monitor->name) == 0) {
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 794   pr_info("Monitor %s is already registered\n", monitor->name);
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 795   retval = -EEXIST;
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 796   goto out_unlock;
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 797   }
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  798   }
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  799
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  800   if
> (parent) {
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 801   list_for_each_entry(r, &rv_monitors_list, list) {
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 802   if (strcmp(parent->name, r->monitor->name) == 0) {
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 803   p = r;
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 804   break;
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 805   }
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 806   }
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  807   }
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  808
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  809   if
> (p && rv_is_nested_monitor(p)) {
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 810   pr_info("Parent monitor %s is already nested, cannot nest further\n",
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 811   parent->name);
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05
> @812   return -EINVAL;
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  813   }
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  814
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  815   r =
> kzalloc(sizeof(struct rv_monitor_def), GFP_KERNEL);
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  816   if
> (!r) {
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 817   retval = -ENOMEM;
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 818   goto out_unlock;
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  819   }
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  820
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  821   r-
> >monitor = monitor;
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  822   r-
> >parent = parent;
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  823
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 824   retval = create_monitor_dir(r, p);
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  825   if
> (retval) {
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 826   kfree(r);
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 827   goto out_unlock;
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  828   }
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  829
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  830   /*
> keep children close to the parent for easier visualisation */
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  831   if
> (p)
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05 
> 832   list_add(&r->list, &p->list);
> cb85c660fcd4b3a Gabriele Monaco            2025-03-05  833   else
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 834   list_add_tail(&r->list, &rv_monitors_list);
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  835
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  836 
> out_unlock:
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 837   mutex_unlock(&rv_interface_lock);
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29 
> 838   return retval;
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  839  }
> 102227b970a1525 Daniel Bristot de Oliveira 2022-07-29  840
>