Skip to content

Commit 6d081a0

Browse files
committed
net: ethtool: Don't call .cleanup_data when prepare_data fails
JIRA: https://issues.redhat.com/browse/RHEL-75603 commit 4f038a6 Author: Maxime Chevallier <maxime.chevallier@bootlin.com> Date: Mon Apr 7 15:05:10 2025 +0200 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> Signed-off-by: Mohammad Heib <mheib@redhat.com>
1 parent e2160b7 commit 6d081a0

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
@@ -493,7 +493,7 @@ static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
493493
ret = ops->prepare_data(req_info, reply_data, info);
494494
rtnl_unlock();
495495
if (ret < 0)
496-
goto err_cleanup;
496+
goto err_dev;
497497
ret = ops->reply_size(req_info, reply_data);
498498
if (ret < 0)
499499
goto err_cleanup;
@@ -551,7 +551,7 @@ static int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev,
551551
ret = ctx->ops->prepare_data(ctx->req_info, ctx->reply_data, info);
552552
rtnl_unlock();
553553
if (ret < 0)
554-
goto out;
554+
goto out_cancel;
555555
ret = ethnl_fill_reply_header(skb, dev, ctx->ops->hdr_attr);
556556
if (ret < 0)
557557
goto out;
@@ -560,6 +560,7 @@ static int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev,
560560
out:
561561
if (ctx->ops->cleanup_data)
562562
ctx->ops->cleanup_data(ctx->reply_data);
563+
out_cancel:
563564
ctx->reply_data->dev = NULL;
564565
if (ret < 0)
565566
genlmsg_cancel(skb, ehdr);
@@ -780,7 +781,7 @@ static void ethnl_default_notify(struct net_device *dev, unsigned int cmd,
780781
ethnl_init_reply_data(reply_data, ops, dev);
781782
ret = ops->prepare_data(req_info, reply_data, &info);
782783
if (ret < 0)
783-
goto err_cleanup;
784+
goto err_rep;
784785
ret = ops->reply_size(req_info, reply_data);
785786
if (ret < 0)
786787
goto err_cleanup;
@@ -815,6 +816,7 @@ static void ethnl_default_notify(struct net_device *dev, unsigned int cmd,
815816
err_cleanup:
816817
if (ops->cleanup_data)
817818
ops->cleanup_data(reply_data);
819+
err_rep:
818820
kfree(reply_data);
819821
kfree(req_info);
820822
return;

0 commit comments

Comments
 (0)