From: Ma Ke <make24@iscas.ac.cn>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, jdamato@fastly.com,
aleksander.lobakin@intel.com, make24@iscas.ac.cn,
quic_zijuhu@quicinc.com, andriy.shevchenko@linux.intel.com,
wanghai26@huawei.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH] net-sysfs: fix error handling in netdev_register_kobject()
Date: Thu, 13 Mar 2025 15:55:28 +0800 [thread overview]
Message-ID: <20250313075528.306019-1-make24@iscas.ac.cn> (raw)
Once device_add() failed, we should call put_device() to decrement
reference count for cleanup. Or it could cause memory leak.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 8ed633b9baf9 ("Revert "net-sysfs: Fix memory leak in netdev_register_kobject"")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
net/core/net-sysfs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 07cb99b114bd..f443eacc9237 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -2169,6 +2169,7 @@ int netdev_register_kobject(struct net_device *ndev)
error = device_add(dev);
if (error)
+ put_device(dev);
return error;
error = register_queue_kobjects(ndev);
--
2.25.1
next reply other threads:[~2025-03-13 7:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 7:55 Ma Ke [this message]
2025-03-13 9:01 ` Andy Shevchenko
2025-03-13 9:02 ` Andy Shevchenko
2025-03-13 9:58 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250313075528.306019-1-make24@iscas.ac.cn \
--to=make24@iscas.ac.cn \
--cc=aleksander.lobakin@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jdamato@fastly.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=quic_zijuhu@quicinc.com \
--cc=stable@vger.kernel.org \
--cc=wanghai26@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®