diff mbox

[v7,4/8] can: m_can: Move allocation of net device to probe

Message ID 1515581725-29242-5-git-send-email-faiz_abbas@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Faiz Abbas Jan. 10, 2018, 10:55 a.m. UTC
With the version no longer required to allocate the net device, it can
be moved to probe and the alloc_m_can_dev() function can be simplified.

Therefore, move the allocation of net device to probe and change
alloc_m_can_dev() to setup_m_can_dev().

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
---
 drivers/net/can/m_can/m_can.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

Comments

Marc Kleine-Budde Jan. 15, 2018, 1:52 p.m. UTC | #1
On 01/10/2018 11:55 AM, Faiz Abbas wrote:
> With the version no longer required to allocate the net device, it can
> be moved to probe and the alloc_m_can_dev() function can be simplified.
> 
> Therefore, move the allocation of net device to probe and change
> alloc_m_can_dev() to setup_m_can_dev().

The error handling is broken with this patch,

Have a look at the switch (priv->version) in setup_m_can_dev(), you free
the m_can_dev in case of error, but exit with -EINVAL in the beginning
of the function. setup_m_can_dev() should not free if it doesn't allocate.

The error handling in m_can_plat_probe() is broken, too. If
pm_runtime_get_sync(&pdev->dev) fails, you don't free the candev.

Marc
Faiz Abbas Jan. 16, 2018, 9:03 a.m. UTC | #2
Hi,

On Monday 15 January 2018 07:22 PM, Marc Kleine-Budde wrote:
> On 01/10/2018 11:55 AM, Faiz Abbas wrote:
>> With the version no longer required to allocate the net device, it can
>> be moved to probe and the alloc_m_can_dev() function can be simplified.
>>
>> Therefore, move the allocation of net device to probe and change
>> alloc_m_can_dev() to setup_m_can_dev().
> 
> The error handling is broken with this patch,
> 
> Have a look at the switch (priv->version) in setup_m_can_dev(), you free
> the m_can_dev in case of error, but exit with -EINVAL in the beginning
> of the function. setup_m_can_dev() should not free if it doesn't allocate.
> 
> The error handling in m_can_plat_probe() is broken, too. If
> pm_runtime_get_sync(&pdev->dev) fails, you don't free the candev.
> 

Will fix.

Thanks,
Faiz
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 893edbb..07ebe7f 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1207,25 +1207,20 @@  static bool m_can_niso_supported(const struct m_can_priv *priv)
 	return !niso_timeout;
 }
 
-static struct net_device *alloc_m_can_dev(struct platform_device *pdev,
-					  void __iomem *addr, u32 tx_fifo_size)
+static int setup_m_can_dev(struct platform_device *pdev, struct net_device *dev,
+			   void __iomem *addr)
 {
-	struct net_device *dev;
 	struct m_can_priv *priv;
 	int m_can_version;
 
 	m_can_version = m_can_check_core_release(addr);
 	/* return if unsupported version */
 	if (!m_can_version) {
-		dev = NULL;
-		goto return_dev;
+		dev_err(&pdev->dev, "Unsupported version number: %2d",
+			m_can_version);
+		return -EINVAL;
 	}
 
-	dev = alloc_candev(sizeof(*priv), tx_fifo_size);
-	if (!dev) {
-		dev = NULL;
-		goto return_dev;
-	}
 	priv = netdev_priv(dev);
 	netif_napi_add(dev, &priv->napi, m_can_poll, M_CAN_NAPI_WEIGHT);
 
@@ -1271,12 +1266,10 @@  static struct net_device *alloc_m_can_dev(struct platform_device *pdev,
 		free_m_can_dev(dev);
 		dev_err(&pdev->dev, "Unsupported version number: %2d",
 			priv->version);
-		dev = NULL;
-		break;
+		return -EINVAL;
 	}
 
-return_dev:
-	return dev;
+	return 0;
 }
 
 static int m_can_open(struct net_device *dev)
@@ -1616,11 +1609,16 @@  static int m_can_plat_probe(struct platform_device *pdev)
 	tx_fifo_size = mram_config_vals[7];
 
 	/* allocate the m_can device */
-	dev = alloc_m_can_dev(pdev, addr, tx_fifo_size);
+	dev = alloc_candev(sizeof(*priv), tx_fifo_size);
 	if (!dev) {
 		ret = -ENOMEM;
 		goto disable_cclk_ret;
 	}
+
+	ret = setup_m_can_dev(pdev, dev, addr);
+	if (ret)
+		goto disable_cclk_ret;
+
 	priv = netdev_priv(dev);
 	dev->irq = irq;
 	priv->device = &pdev->dev;