Skip to contentSkip to conversation

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

PATCH Applied Dan Carpenter 4 participants 4 messages Jul 31, 2022 – Aug 1, 2022

Subsystems (2)
lore
Share & tools
lore

Dan Carpenter

author build bot
#0 lore raw

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
CC: Ammar Faizi <[email protected]>
CC: "GNU/Weeb Mailing List" <[email protected]>
CC: linux-kernel(a)vger.kernel.org
TO: Jiri Pirko <[email protected]>
CC: Jakub Kicinski <[email protected]>

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

:::::: branch date: 27 hours ago
:::::: commit date: 2 days ago
config: arc-randconfig-m041-20220731 (https://download.01.org/0day-ci/archive/20220731/202207311503.QBFSGqiL-lkp(a)intel.com/config)
compiler: arceb-elf-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable

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

866319bb943761 Alex Vesker    2018-07-12  6270  
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);
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;
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  }
b9a17abfde842b Jacob Keller   2020-03-26  6394  

:::::: The code at line 6392 was first introduced by commit
:::::: 043b3e22768d5d909cb1474fc21ae2fbaf026c0c devlink: let kernel allocate region snapshot id

:::::: TO: Jakub Kicinski <[email protected]>
:::::: CC: David S. Miller <[email protected]>

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#1 lore raw

PATCH 1/1 net: devlink: Fix missing mutex_unlock() call

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.

Fixes 2dec18ad826f52658f7781ee995d236cc449b678 ("net: devlink: remove region snapshots list dependency on devlink->lock")
---
 net/core/devlink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/core/devlink.c +4 -2
index 889e7e3d3e8a..5da5c7cca98a 100644
@@ -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

Signature · 1 line
Ammar Faizi
Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH] net: devlink: Fix missing mutex_unlock() call

Quoted 9 lines · Mon, Aug 01, 2022 at 01:59:56PM CEST, ammarfaizi2(a)gnuweeb.org 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'.
Quoted 6 lines

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

Fixes 2dec18ad826f52658f7781ee995d236cc449b678 ("net: devlink: remove region snapshots list dependency on devlink->lock")

Thanks for the fix!

#3 lore raw

Re: [PATCH] net: devlink: Fix missing mutex_unlock() call

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

Hello:

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

Quoted 10 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html