public inbox for [email protected]
 help / color / mirror / Atom feed
* [ammarfaizi2-block:netdev/net-next/main 20/29] net/core/devlink.c:6392 devlink_nl_cmd_region_new() warn: inconsistent returns '&region->snapshot_lock'.
@ 2022-08-01 11:29 Dan Carpenter
  2022-08-01 11:59 ` [PATCH] net: devlink: Fix missing mutex_unlock() call Ammar Faizi
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2022-08-01 11:29 UTC (permalink / raw)
  To: kbuild, Jiri Pirko
  Cc: lkp, kbuild-all, Ammar Faizi, GNU/Weeb Mailing List, linux-kernel

tree:   https://github.com/ammarfaizi2/linux-block netdev/net-next/main
head:   63757225a93353bc2ce4499af5501eabdbbf23f9
commit: 2dec18ad826f52658f7781ee995d236cc449b678 [20/29] net: devlink: remove region snapshots list dependency on devlink->lock
config: arc-randconfig-m041-20220731 (https://download.01.org/0day-ci/archive/20220731/[email protected]/config)
compiler: arceb-elf-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

New smatch warnings:
net/core/devlink.c:6392 devlink_nl_cmd_region_new() warn: inconsistent returns '&region->snapshot_lock'.

Old smatch warnings:
net/core/devlink.c:7284 devlink_fmsg_prepare_skb() error: uninitialized symbol 'err'.
arch/arc/include/asm/thread_info.h:62 current_thread_info() error: uninitialized symbol 'sp'.

vim +6392 net/core/devlink.c

b9a17abfde842b Jacob Keller   2020-03-26  6271  static int
b9a17abfde842b Jacob Keller   2020-03-26  6272  devlink_nl_cmd_region_new(struct sk_buff *skb, struct genl_info *info)
b9a17abfde842b Jacob Keller   2020-03-26  6273  {
b9a17abfde842b Jacob Keller   2020-03-26  6274  	struct devlink *devlink = info->user_ptr[0];
043b3e22768d5d Jakub Kicinski 2020-05-01  6275  	struct devlink_snapshot *snapshot;
544e7c33ec2f80 Andrew Lunn    2020-10-04  6276  	struct devlink_port *port = NULL;
043b3e22768d5d Jakub Kicinski 2020-05-01  6277  	struct nlattr *snapshot_id_attr;
b9a17abfde842b Jacob Keller   2020-03-26  6278  	struct devlink_region *region;
b9a17abfde842b Jacob Keller   2020-03-26  6279  	const char *region_name;
544e7c33ec2f80 Andrew Lunn    2020-10-04  6280  	unsigned int index;
b9a17abfde842b Jacob Keller   2020-03-26  6281  	u32 snapshot_id;
b9a17abfde842b Jacob Keller   2020-03-26  6282  	u8 *data;
b9a17abfde842b Jacob Keller   2020-03-26  6283  	int err;
b9a17abfde842b Jacob Keller   2020-03-26  6284  
b9a17abfde842b Jacob Keller   2020-03-26  6285  	if (!info->attrs[DEVLINK_ATTR_REGION_NAME]) {
b9a17abfde842b Jacob Keller   2020-03-26  6286  		NL_SET_ERR_MSG_MOD(info->extack, "No region name provided");
b9a17abfde842b Jacob Keller   2020-03-26  6287  		return -EINVAL;
b9a17abfde842b Jacob Keller   2020-03-26  6288  	}
b9a17abfde842b Jacob Keller   2020-03-26  6289  
b9a17abfde842b Jacob Keller   2020-03-26  6290  	region_name = nla_data(info->attrs[DEVLINK_ATTR_REGION_NAME]);
544e7c33ec2f80 Andrew Lunn    2020-10-04  6291  
544e7c33ec2f80 Andrew Lunn    2020-10-04  6292  	if (info->attrs[DEVLINK_ATTR_PORT_INDEX]) {
544e7c33ec2f80 Andrew Lunn    2020-10-04  6293  		index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]);
544e7c33ec2f80 Andrew Lunn    2020-10-04  6294  
544e7c33ec2f80 Andrew Lunn    2020-10-04  6295  		port = devlink_port_get_by_index(devlink, index);
544e7c33ec2f80 Andrew Lunn    2020-10-04  6296  		if (!port)
544e7c33ec2f80 Andrew Lunn    2020-10-04  6297  			return -ENODEV;
544e7c33ec2f80 Andrew Lunn    2020-10-04  6298  	}
544e7c33ec2f80 Andrew Lunn    2020-10-04  6299  
544e7c33ec2f80 Andrew Lunn    2020-10-04  6300  	if (port)
544e7c33ec2f80 Andrew Lunn    2020-10-04  6301  		region = devlink_port_region_get_by_name(port, region_name);
544e7c33ec2f80 Andrew Lunn    2020-10-04  6302  	else
b9a17abfde842b Jacob Keller   2020-03-26  6303  		region = devlink_region_get_by_name(devlink, region_name);
544e7c33ec2f80 Andrew Lunn    2020-10-04  6304  
b9a17abfde842b Jacob Keller   2020-03-26  6305  	if (!region) {
b9a17abfde842b Jacob Keller   2020-03-26  6306  		NL_SET_ERR_MSG_MOD(info->extack, "The requested region does not exist");
b9a17abfde842b Jacob Keller   2020-03-26  6307  		return -EINVAL;
b9a17abfde842b Jacob Keller   2020-03-26  6308  	}
b9a17abfde842b Jacob Keller   2020-03-26  6309  
b9a17abfde842b Jacob Keller   2020-03-26  6310  	if (!region->ops->snapshot) {
b9a17abfde842b Jacob Keller   2020-03-26  6311  		NL_SET_ERR_MSG_MOD(info->extack, "The requested region does not support taking an immediate snapshot");
b9a17abfde842b Jacob Keller   2020-03-26  6312  		return -EOPNOTSUPP;
b9a17abfde842b Jacob Keller   2020-03-26  6313  	}
b9a17abfde842b Jacob Keller   2020-03-26  6314  
2dec18ad826f52 Jiri Pirko     2022-07-28  6315  	mutex_lock(&region->snapshot_lock);

New locking

2dec18ad826f52 Jiri Pirko     2022-07-28  6316  
b9a17abfde842b Jacob Keller   2020-03-26  6317  	if (region->cur_snapshots == region->max_snapshots) {
b9a17abfde842b Jacob Keller   2020-03-26  6318  		NL_SET_ERR_MSG_MOD(info->extack, "The region has reached the maximum number of stored snapshots");
2dec18ad826f52 Jiri Pirko     2022-07-28  6319  		err = -ENOSPC;
2dec18ad826f52 Jiri Pirko     2022-07-28  6320  		goto unlock;
b9a17abfde842b Jacob Keller   2020-03-26  6321  	}
b9a17abfde842b Jacob Keller   2020-03-26  6322  
043b3e22768d5d Jakub Kicinski 2020-05-01  6323  	snapshot_id_attr = info->attrs[DEVLINK_ATTR_REGION_SNAPSHOT_ID];
043b3e22768d5d Jakub Kicinski 2020-05-01  6324  	if (snapshot_id_attr) {
043b3e22768d5d Jakub Kicinski 2020-05-01  6325  		snapshot_id = nla_get_u32(snapshot_id_attr);
b9a17abfde842b Jacob Keller   2020-03-26  6326  
b9a17abfde842b Jacob Keller   2020-03-26  6327  		if (devlink_region_snapshot_get_by_id(region, snapshot_id)) {
b9a17abfde842b Jacob Keller   2020-03-26  6328  			NL_SET_ERR_MSG_MOD(info->extack, "The requested snapshot id is already in use");
2dec18ad826f52 Jiri Pirko     2022-07-28  6329  			err = -EEXIST;
2dec18ad826f52 Jiri Pirko     2022-07-28  6330  			goto unlock;
b9a17abfde842b Jacob Keller   2020-03-26  6331  		}
b9a17abfde842b Jacob Keller   2020-03-26  6332  
b9a17abfde842b Jacob Keller   2020-03-26  6333  		err = __devlink_snapshot_id_insert(devlink, snapshot_id);
b9a17abfde842b Jacob Keller   2020-03-26  6334  		if (err)
2dec18ad826f52 Jiri Pirko     2022-07-28  6335  			goto unlock;
043b3e22768d5d Jakub Kicinski 2020-05-01  6336  	} else {
043b3e22768d5d Jakub Kicinski 2020-05-01  6337  		err = __devlink_region_snapshot_id_get(devlink, &snapshot_id);
043b3e22768d5d Jakub Kicinski 2020-05-01  6338  		if (err) {
043b3e22768d5d Jakub Kicinski 2020-05-01  6339  			NL_SET_ERR_MSG_MOD(info->extack, "Failed to allocate a new snapshot id");
2dec18ad826f52 Jiri Pirko     2022-07-28  6340  			goto unlock;
043b3e22768d5d Jakub Kicinski 2020-05-01  6341  		}
043b3e22768d5d Jakub Kicinski 2020-05-01  6342  	}
b9a17abfde842b Jacob Keller   2020-03-26  6343  
544e7c33ec2f80 Andrew Lunn    2020-10-04  6344  	if (port)
544e7c33ec2f80 Andrew Lunn    2020-10-04  6345  		err = region->port_ops->snapshot(port, region->port_ops,
544e7c33ec2f80 Andrew Lunn    2020-10-04  6346  						 info->extack, &data);
544e7c33ec2f80 Andrew Lunn    2020-10-04  6347  	else
544e7c33ec2f80 Andrew Lunn    2020-10-04  6348  		err = region->ops->snapshot(devlink, region->ops,
544e7c33ec2f80 Andrew Lunn    2020-10-04  6349  					    info->extack, &data);
b9a17abfde842b Jacob Keller   2020-03-26  6350  	if (err)
b9a17abfde842b Jacob Keller   2020-03-26  6351  		goto err_snapshot_capture;
b9a17abfde842b Jacob Keller   2020-03-26  6352  
b9a17abfde842b Jacob Keller   2020-03-26  6353  	err = __devlink_region_snapshot_create(region, data, snapshot_id);
b9a17abfde842b Jacob Keller   2020-03-26  6354  	if (err)
b9a17abfde842b Jacob Keller   2020-03-26  6355  		goto err_snapshot_create;
b9a17abfde842b Jacob Keller   2020-03-26  6356  
043b3e22768d5d Jakub Kicinski 2020-05-01  6357  	if (!snapshot_id_attr) {
043b3e22768d5d Jakub Kicinski 2020-05-01  6358  		struct sk_buff *msg;
043b3e22768d5d Jakub Kicinski 2020-05-01  6359  
043b3e22768d5d Jakub Kicinski 2020-05-01  6360  		snapshot = devlink_region_snapshot_get_by_id(region,
043b3e22768d5d Jakub Kicinski 2020-05-01  6361  							     snapshot_id);
043b3e22768d5d Jakub Kicinski 2020-05-01  6362  		if (WARN_ON(!snapshot))
043b3e22768d5d Jakub Kicinski 2020-05-01  6363  			return -EINVAL;

unlock before returning?

043b3e22768d5d Jakub Kicinski 2020-05-01  6364  
043b3e22768d5d Jakub Kicinski 2020-05-01  6365  		msg = devlink_nl_region_notify_build(region, snapshot,
043b3e22768d5d Jakub Kicinski 2020-05-01  6366  						     DEVLINK_CMD_REGION_NEW,
043b3e22768d5d Jakub Kicinski 2020-05-01  6367  						     info->snd_portid,
043b3e22768d5d Jakub Kicinski 2020-05-01  6368  						     info->snd_seq);
043b3e22768d5d Jakub Kicinski 2020-05-01  6369  		err = PTR_ERR_OR_ZERO(msg);
043b3e22768d5d Jakub Kicinski 2020-05-01  6370  		if (err)
043b3e22768d5d Jakub Kicinski 2020-05-01  6371  			goto err_notify;
043b3e22768d5d Jakub Kicinski 2020-05-01  6372  
043b3e22768d5d Jakub Kicinski 2020-05-01  6373  		err = genlmsg_reply(msg, info);
043b3e22768d5d Jakub Kicinski 2020-05-01  6374  		if (err)
043b3e22768d5d Jakub Kicinski 2020-05-01  6375  			goto err_notify;
043b3e22768d5d Jakub Kicinski 2020-05-01  6376  	}
043b3e22768d5d Jakub Kicinski 2020-05-01  6377  
2dec18ad826f52 Jiri Pirko     2022-07-28  6378  	mutex_unlock(&region->snapshot_lock);
b9a17abfde842b Jacob Keller   2020-03-26  6379  	return 0;
b9a17abfde842b Jacob Keller   2020-03-26  6380  
b9a17abfde842b Jacob Keller   2020-03-26  6381  err_snapshot_create:
b9a17abfde842b Jacob Keller   2020-03-26  6382  	region->ops->destructor(data);
b9a17abfde842b Jacob Keller   2020-03-26  6383  err_snapshot_capture:
b9a17abfde842b Jacob Keller   2020-03-26  6384  	__devlink_snapshot_id_decrement(devlink, snapshot_id);
2dec18ad826f52 Jiri Pirko     2022-07-28  6385  	mutex_unlock(&region->snapshot_lock);
b9a17abfde842b Jacob Keller   2020-03-26  6386  	return err;
043b3e22768d5d Jakub Kicinski 2020-05-01  6387  
043b3e22768d5d Jakub Kicinski 2020-05-01  6388  err_notify:
043b3e22768d5d Jakub Kicinski 2020-05-01  6389  	devlink_region_snapshot_del(region, snapshot);
2dec18ad826f52 Jiri Pirko     2022-07-28  6390  unlock:
2dec18ad826f52 Jiri Pirko     2022-07-28  6391  	mutex_unlock(&region->snapshot_lock);
043b3e22768d5d Jakub Kicinski 2020-05-01 @6392  	return err;
b9a17abfde842b Jacob Keller   2020-03-26  6393  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] net: devlink: Fix missing mutex_unlock() call
  2022-08-01 11:29 [ammarfaizi2-block:netdev/net-next/main 20/29] net/core/devlink.c:6392 devlink_nl_cmd_region_new() warn: inconsistent returns '&region->snapshot_lock' Dan Carpenter
@ 2022-08-01 11:59 ` Ammar Faizi
  2022-08-01 14:40   ` Jiri Pirko
  2022-08-01 19:50   ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Ammar Faizi @ 2022-08-01 11:59 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Ammar Faizi, kernel test robot, Dan Carpenter, Moshe Shemesh,
	Jiri Pirko, Fernanda Ma'rouf, netdev Mailing List,
	GNU/Weeb Mailing List, Linux Kernel Mailing List,
	kbuild Mailing List, kbuild-all Mailing List

From: Ammar Faizi <[email protected]>

Commit 2dec18ad826f forgets to call mutex_unlock() before the function
returns in the error path:

   New smatch warnings:
   net/core/devlink.c:6392 devlink_nl_cmd_region_new() warn: inconsistent \
   returns '&region->snapshot_lock'.

Make sure we call mutex_unlock() in this error path.

Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Fixes: 2dec18ad826f52658f7781ee995d236cc449b678 ("net: devlink: remove region snapshots list dependency on devlink->lock")
Signed-off-by: Ammar Faizi <[email protected]>
---
 net/core/devlink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index 889e7e3d3e8a..5da5c7cca98a 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -6315,8 +6315,10 @@ devlink_nl_cmd_region_new(struct sk_buff *skb, struct genl_info *info)
 
 		snapshot = devlink_region_snapshot_get_by_id(region,
 							     snapshot_id);
-		if (WARN_ON(!snapshot))
-			return -EINVAL;
+		if (WARN_ON(!snapshot)) {
+			err = -EINVAL;
+			goto unlock;
+		}
 
 		msg = devlink_nl_region_notify_build(region, snapshot,
 						     DEVLINK_CMD_REGION_NEW,

base-commit: 0a324c3263f1e456f54dd8dc8ce58575aea776bc
-- 
Ammar Faizi


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: devlink: Fix missing mutex_unlock() call
  2022-08-01 11:59 ` [PATCH] net: devlink: Fix missing mutex_unlock() call Ammar Faizi
@ 2022-08-01 14:40   ` Jiri Pirko
  2022-08-01 19:50   ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Pirko @ 2022-08-01 14:40 UTC (permalink / raw)
  To: Ammar Faizi
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	kernel test robot, Dan Carpenter, Moshe Shemesh, Jiri Pirko,
	Fernanda Ma'rouf, netdev Mailing List, GNU/Weeb Mailing List,
	Linux Kernel Mailing List, kbuild Mailing List,
	kbuild-all Mailing List

Mon, Aug 01, 2022 at 01:59:56PM CEST, [email protected] wrote:
>From: Ammar Faizi <[email protected]>
>
>Commit 2dec18ad826f forgets to call mutex_unlock() before the function
>returns in the error path:
>
>   New smatch warnings:
>   net/core/devlink.c:6392 devlink_nl_cmd_region_new() warn: inconsistent \
>   returns '&region->snapshot_lock'.
>
>Make sure we call mutex_unlock() in this error path.
>
>Reported-by: kernel test robot <[email protected]>
>Reported-by: Dan Carpenter <[email protected]>
>Fixes: 2dec18ad826f52658f7781ee995d236cc449b678 ("net: devlink: remove region snapshots list dependency on devlink->lock")
>Signed-off-by: Ammar Faizi <[email protected]>

Reviewed-by: Jiri Pirko <[email protected]>

Thanks for the fix!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: devlink: Fix missing mutex_unlock() call
  2022-08-01 11:59 ` [PATCH] net: devlink: Fix missing mutex_unlock() call Ammar Faizi
  2022-08-01 14:40   ` Jiri Pirko
@ 2022-08-01 19:50   ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-01 19:50 UTC (permalink / raw)
  To: Ammar Faizi
  Cc: davem, edumazet, kuba, pabeni, lkp, dan.carpenter, moshe, jiri,
	fernandafmr12, netdev, gwml, linux-kernel, kbuild, kbuild-all

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <[email protected]>:

On Mon,  1 Aug 2022 18:59:56 +0700 you wrote:
> From: Ammar Faizi <[email protected]>
> 
> Commit 2dec18ad826f forgets to call mutex_unlock() before the function
> returns in the error path:
> 
>    New smatch warnings:
>    net/core/devlink.c:6392 devlink_nl_cmd_region_new() warn: inconsistent \
>    returns '&region->snapshot_lock'.
> 
> [...]

Here is the summary with links:
  - net: devlink: Fix missing mutex_unlock() call
    https://git.kernel.org/netdev/net-next/c/80ef928643c1

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-01 19:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-01 11:29 [ammarfaizi2-block:netdev/net-next/main 20/29] net/core/devlink.c:6392 devlink_nl_cmd_region_new() warn: inconsistent returns '&region->snapshot_lock' Dan Carpenter
2022-08-01 11:59 ` [PATCH] net: devlink: Fix missing mutex_unlock() call Ammar Faizi
2022-08-01 14:40   ` Jiri Pirko
2022-08-01 19:50   ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox