Thread (5 messages) 5 messages, 3 authors, 2020-11-30

Re: [PATCH net] net: fix memory leak in register_netdevice() on error path

From: Toshiaki Makita <hidden>
Date: 2020-11-29 13:57:50

On 2020/11/26 22:23, Yang Yingliang wrote:
...
quoted hunk ↗ jump to hunk
Reported-by: Hulk Robot <redacted>
Signed-off-by: Yang Yingliang <redacted>
---
  net/core/dev.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
diff --git a/net/core/dev.c b/net/core/dev.c
index 82dc6b48e45f..907204395b64 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10000,6 +10000,17 @@ int register_netdevice(struct net_device *dev)
  	ret = notifier_to_errno(ret);
  	if (ret) {
  		rollback_registered(dev);
+		/*
+		 * In common case, priv_destructor() will be
As per netdev-faq, the comment style should be

/* foobar blah blah blah
  * another line of text
  */

rather than

/*
  * foobar blah blah blah
  * another line of text
  */
+		 * called in netdev_run_todo() after calling
+		 * ndo_uninit() in rollback_registered().
+		 * But in this case, priv_destructor() will
+		 * never be called, then it causes memory
+		 * leak, so we should call priv_destructor()
+		 * here.
+		 */
+		if (dev->priv_destructor)
+			dev->priv_destructor(dev);
To be in line with netdev_run_todo(), I think priv_destructor() should be
called after "dev->reg_state = NETREG_UNREGISTERED".

Toshiaki Makita
  		rcu_barrier();
  
  		dev->reg_state = NETREG_UNREGISTERED;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help