netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: etas_es58x: fix error handling
@ 2021-11-14 20:58 Pavel Skripkin
  2021-11-15  5:27 ` Vincent MAILHOL
  0 siblings, 1 reply; 12+ messages in thread
From: Pavel Skripkin @ 2021-11-14 20:58 UTC (permalink / raw)
  To: mailhol.vincent, wg, mkl, davem, kuba
  Cc: linux-can, netdev, linux-kernel, Pavel Skripkin

When register_candev() fails there are 2 possible device states:
NETREG_UNINITIALIZED and NETREG_UNREGISTERED. None of them are suitable
for calling unregister_candev(), because of following checks in
unregister_netdevice_many():

	if (dev->reg_state == NETREG_UNINITIALIZED)
		WARN_ON(1);
...
	BUG_ON(dev->reg_state != NETREG_REGISTERED);

To avoid possible BUG_ON or WARN_ON let's free current netdev before
returning from es58x_init_netdev() and leave others (registered)
net devices for es58x_free_netdevs().

Fixes: 004653f0abf2 ("can: etas_es58x: add es58x_free_netdevs() to factorize code")
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 drivers/net/can/usb/etas_es58x/es58x_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c
index 96a13c770e4a..41c721f2fbbe 100644
--- a/drivers/net/can/usb/etas_es58x/es58x_core.c
+++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
@@ -2098,8 +2098,11 @@ static int es58x_init_netdev(struct es58x_device *es58x_dev, int channel_idx)
 	netdev->flags |= IFF_ECHO;	/* We support local echo */
 
 	ret = register_candev(netdev);
-	if (ret)
+	if (ret) {
+		free_candev(netdev);
+		es58x_dev->netdev[channel_idx] = NULL;
 		return ret;
+	}
 
 	netdev_queue_set_dql_min_limit(netdev_get_tx_queue(netdev, 0),
 				       es58x_dev->param->dql_min_limit);
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-11-15  9:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-14 20:58 [PATCH] can: etas_es58x: fix error handling Pavel Skripkin
2021-11-15  5:27 ` Vincent MAILHOL
2021-11-15  7:40   ` Pavel Skripkin
2021-11-15  7:51   ` [PATCH v2] " Pavel Skripkin
2021-11-15  8:11     ` Johan Hovold
2021-11-15  8:15       ` Pavel Skripkin
2021-11-15  8:16         ` Johan Hovold
2021-11-15  8:30           ` Pavel Skripkin
2021-11-15  9:24             ` Vincent MAILHOL
2021-11-15  9:26               ` Pavel Skripkin
2021-11-15  8:37       ` [PATCH v3] " Pavel Skripkin
2021-11-15  9:15         ` Vincent MAILHOL

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).