Skip to contentSkip to conversation

devlink: Add missing genlmsg_cancel() in devlink_nl_sb_port_pool_fill()

PATCH Superseded Wang Hai 2 participants 3 messages Nov 11, 2020 – Nov 13, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wang Hai

author
#0 lore raw

PATCH 1/1 devlink: Add missing genlmsg_cancel() in devlink_nl_sb_port_pool_fill()

If sb_occ_port_pool_get() failed in devlink_nl_sb_port_pool_fill(), msg should be canceled by genlmsg_cancel().

Fixes df38dafd2559 ("devlink: implement shared buffer occupancy monitoring interface")
---
 net/core/devlink.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/devlink.c +3 -1
index a932d95be798..83b4e7f51b35 100644
@@ -1447,8 +1447,10 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
 
 		err = ops->sb_occ_port_pool_get(devlink_port, devlink_sb->index,
 						pool_index, &cur, &max);
-		if (err && err != -EOPNOTSUPP)
+		if (err && err != -EOPNOTSUPP) {
+			genlmsg_cancel(msg, hdr);
 			return err;
+		}
 		if (!err) {
 			if (nla_put_u32(msg, DEVLINK_ATTR_SB_OCC_CUR, cur))
 				goto nla_put_failure;
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 15 lines · On Wed, 11 Nov 2020 21:58:53 +0800 Wang Hai wrote:

If sb_occ_port_pool_get() failed in devlink_nl_sb_port_pool_fill(), msg should be canceled by genlmsg_cancel().

Fixes df38dafd2559 ("devlink: implement shared buffer occupancy monitoring interface")
---
 net/core/devlink.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/devlink.c +0 -0
index a932d95be798..83b4e7f51b35 100644

net/core/devlink.c static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg, · line 1452

Quoted 7 lines
net/core/devlink.c +2 -1
@@ -1447,8 +1447,10 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
 
 		err = ops->sb_occ_port_pool_get(devlink_port, devlink_sb->index,
 						pool_index, &cur, &max);
-		if (err && err != -EOPNOTSUPP)
+		if (err && err != -EOPNOTSUPP) {
+			genlmsg_cancel(msg, hdr);
 			return err;

I guess the driver would have to return -EMSGSIZE for this to matter, which is quite unlikely but we should indeed fix.

Still, returning in the middle of the function with an epilogue is what got use here in the first place, so please use a goto. E.g. like this:

net/core/devlink.c +4 -2
index a932d95be798..be8ee96ad188 100644
@@ -1448,7 +1448,7 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
                err = ops->sb_occ_port_pool_get(devlink_port, devlink_sb->index,
                                                pool_index, &cur, &max);
                if (err && err != -EOPNOTSUPP)
-                       return err;
+                       goto sb_occ_get_failure;
                if (!err) {
                        if (nla_put_u32(msg, DEVLINK_ATTR_SB_OCC_CUR, cur))
                                goto nla_put_failure;
@@ -1461,8 +1461,10 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
        return 0;
 
 nla_put_failure:
+       err = -EMSGSIZE;
+sb_occ_get_failure:
        genlmsg_cancel(msg, hdr);
-       return -EMSGSIZE;
+       return err;
 }
 
 static int devlink_nl_cmd_sb_port_pool_get_doit(struct sk_buff *skb,
#2 lore raw
Quoted 5 lines · Jakub Kicinski
Quoted 4 lines · On Wed, 11 Nov 2020 21:58:53 +0800 Wang Hai wrote:

If sb_occ_port_pool_get() failed in devlink_nl_sb_port_pool_fill(), msg should be canceled by genlmsg_cancel().
+++ b/net/core/devlink.c

(quoted diff) +0 -0
@@ -1447,8 +1447,10 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,

[...]

Quoted 7 lines
Quoted 1 line

return err;

I guess the driver would have to return -EMSGSIZE for this to matter, which is quite unlikely but we should indeed fix.

Still, returning in the middle of the function with an epilogue is what got use here in the first place, so please use a goto. E.g. like this:

[...]

Quoted 3 lines

static int devlink_nl_cmd_sb_port_pool_get_doit(struct sk_buff *skb,

.

Thanks for your review,  I just sent v2

[PATCH v2 net] devlink: Add missing genlmsg_cancel() in devlink_nl_sb_port_pool_fill()