[v2] can: etas_es58x: free netdev when register_candev() failed in es58x_init_netdev()

Message ID 1668413685-23354-1-git-send-email-zhangchangzhong@huawei.com
State New
Headers
Series [v2] can: etas_es58x: free netdev when register_candev() failed in es58x_init_netdev() |

Commit Message

Zhang Changzhong Nov. 14, 2022, 8:14 a.m. UTC
  In case of register_candev() fails, clear es58x_dev->netdev[channel_idx]
and add free_candev(). Otherwise es58x_free_netdevs() will unregister
the netdev that has never been registered.

Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
---
v1 -> v2: change to the correct 'Fixes' tag according to Vincent Mailhol

 drivers/net/can/usb/etas_es58x/es58x_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Arunachalam Santhanam (MS/ETA-ETAS) Nov. 14, 2022, 8:32 a.m. UTC | #1
Hi Zhang,

Thank you for the update and patch.

-----Original Message-----
From: Zhang Changzhong <zhangchangzhong@huawei.com> 
Sent: 14 November 2022 13:45
To: Vincent Mailhol <mailhol.vincent@wanadoo.fr>; Wolfgang Grandegger <wg@grandegger.com>; EXTERNAL Kleine-Budde Marc (Pengutronix, XC-CT/ECP2) <mkl@pengutronix.de>; David S. Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Arunachalam Santhanam (MS/ETA-ETAS) <arunachalam.santhanam@in.bosch.com>
Cc: Zhang Changzhong <zhangchangzhong@huawei.com>; linux-can@vger.kernel.org; netdev@vger.kernel.org; linux-kernel@vger.kernel.org
Subject: [PATCH v2] can: etas_es58x: free netdev when register_candev() failed in es58x_init_netdev()

In case of register_candev() fails, clear es58x_dev->netdev[channel_idx] and add free_candev(). Otherwise es58x_free_netdevs() will unregister the netdev that has never been registered.

Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
Signed-off-by: Zhang Changzhong <mailto:zhangchangzhong@huawei.com>
---
v1 -> v2: change to the correct 'Fixes' tag according to Vincent Mailhol

Acked-by: <arunachalam.santhanam@in.bosch.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 25f863b..ddb7c57 100644
--- a/drivers/net/can/usb/etas_es58x/es58x_core.c
+++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
@@ -2091,8 +2091,11 @@ static int es58x_init_netdev(struct es58x_device *es58x_dev, int channel_idx)
 	netdev->dev_port = channel_idx;
 
 	ret = register_candev(netdev);
-	if (ret)
+	if (ret) {
+		es58x_dev->netdev[channel_idx] = NULL;
+		free_candev(netdev);
 		return ret;
+	}
 
 	netdev_queue_set_dql_min_limit(netdev_get_tx_queue(netdev, 0),
 				       es58x_dev->param->dql_min_limit);
--
2.9.5
  

Patch

diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c
index 25f863b..ddb7c57 100644
--- a/drivers/net/can/usb/etas_es58x/es58x_core.c
+++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
@@ -2091,8 +2091,11 @@  static int es58x_init_netdev(struct es58x_device *es58x_dev, int channel_idx)
 	netdev->dev_port = channel_idx;
 
 	ret = register_candev(netdev);
-	if (ret)
+	if (ret) {
+		es58x_dev->netdev[channel_idx] = NULL;
+		free_candev(netdev);
 		return ret;
+	}
 
 	netdev_queue_set_dql_min_limit(netdev_get_tx_queue(netdev, 0),
 				       es58x_dev->param->dql_min_limit);