Skip to content

Commit 4f038a6

Browse files
minimaxwellPaolo Abeni
authored andcommitted
net: ethtool: Don't call .cleanup_data when prepare_data fails
There's a consistent pattern where the .cleanup_data() callback is called when .prepare_data() fails, when it should really be called to clean after a successful .prepare_data() as per the documentation. Rewrite the error-handling paths to make sure we don't cleanup un-prepared data. Fixes: c781ff1 ("ethtool: Allow network drivers to dump arbitrary EEPROM data") Reviewed-by: Kory Maincent <kory.maincent@bootlin.com> Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Michal Kubecek <mkubecek@suse.cz> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> Link: https://patch.msgid.link/20250407130511.75621-1-maxime.chevallier@bootlin.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 369609f commit 4f038a6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

net/ethtool/netlink.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
500500
netdev_unlock_ops(req_info->dev);
501501
rtnl_unlock();
502502
if (ret < 0)
503-
goto err_cleanup;
503+
goto err_dev;
504504
ret = ops->reply_size(req_info, reply_data);
505505
if (ret < 0)
506506
goto err_cleanup;
@@ -560,7 +560,7 @@ static int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev,
560560
netdev_unlock_ops(dev);
561561
rtnl_unlock();
562562
if (ret < 0)
563-
goto out;
563+
goto out_cancel;
564564
ret = ethnl_fill_reply_header(skb, dev, ctx->ops->hdr_attr);
565565
if (ret < 0)
566566
goto out;
@@ -569,6 +569,7 @@ static int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev,
569569
out:
570570
if (ctx->ops->cleanup_data)
571571
ctx->ops->cleanup_data(ctx->reply_data);
572+
out_cancel:
572573
ctx->reply_data->dev = NULL;
573574
if (ret < 0)
574575
genlmsg_cancel(skb, ehdr);
@@ -793,7 +794,7 @@ static void ethnl_default_notify(struct net_device *dev, unsigned int cmd,
793794
ethnl_init_reply_data(reply_data, ops, dev);
794795
ret = ops->prepare_data(req_info, reply_data, &info);
795796
if (ret < 0)
796-
goto err_cleanup;
797+
goto err_rep;
797798
ret = ops->reply_size(req_info, reply_data);
798799
if (ret < 0)
799800
goto err_cleanup;
@@ -828,6 +829,7 @@ static void ethnl_default_notify(struct net_device *dev, unsigned int cmd,
828829
err_cleanup:
829830
if (ops->cleanup_data)
830831
ops->cleanup_data(reply_data);
832+
err_rep:
831833
kfree(reply_data);
832834
kfree(req_info);
833835
return;

0 commit comments

Comments
 (0)