aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFaiz Abbas <faiz_abbas@ti.com>2018-01-16 06:37:12 -0500
committerMarc Kleine-Budde <mkl@pengutronix.de>2018-01-16 09:11:33 -0500
commit5e520edd91f0cd52f8f9f855bc2c1558e85d30da (patch)
treeb7d0660465b3fe427f56e919925ec3d87a798449
parentb25abca6aa4fd2fcdafc214d489ccd57df67e88e (diff)
can: m_can: Move allocation of net device to probe
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> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r--drivers/net/can/m_can/m_can.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 4f7de0b07c9b..6c2011bbafb3 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1247,25 +1247,20 @@ static bool m_can_niso_supported(const struct m_can_priv *priv)
1247 return !niso_timeout; 1247 return !niso_timeout;
1248} 1248}
1249 1249
1250static struct net_device *alloc_m_can_dev(struct platform_device *pdev, 1250static int m_can_dev_setup(struct platform_device *pdev, struct net_device *dev,
1251 void __iomem *addr, u32 tx_fifo_size) 1251 void __iomem *addr)
1252{ 1252{
1253 struct net_device *dev;
1254 struct m_can_priv *priv; 1253 struct m_can_priv *priv;
1255 int m_can_version; 1254 int m_can_version;
1256 1255
1257 m_can_version = m_can_check_core_release(addr); 1256 m_can_version = m_can_check_core_release(addr);
1258 /* return if unsupported version */ 1257 /* return if unsupported version */
1259 if (!m_can_version) { 1258 if (!m_can_version) {
1260 dev = NULL; 1259 dev_err(&pdev->dev, "Unsupported version number: %2d",
1261 goto return_dev; 1260 m_can_version);
1261 return -EINVAL;
1262 } 1262 }
1263 1263
1264 dev = alloc_candev(sizeof(*priv), tx_fifo_size);
1265 if (!dev) {
1266 dev = NULL;
1267 goto return_dev;
1268 }
1269 priv = netdev_priv(dev); 1264 priv = netdev_priv(dev);
1270 netif_napi_add(dev, &priv->napi, m_can_poll, M_CAN_NAPI_WEIGHT); 1265 netif_napi_add(dev, &priv->napi, m_can_poll, M_CAN_NAPI_WEIGHT);
1271 1266
@@ -1307,16 +1302,12 @@ static struct net_device *alloc_m_can_dev(struct platform_device *pdev,
1307 : 0); 1302 : 0);
1308 break; 1303 break;
1309 default: 1304 default:
1310 /* Unsupported device: free candev */
1311 free_m_can_dev(dev);
1312 dev_err(&pdev->dev, "Unsupported version number: %2d", 1305 dev_err(&pdev->dev, "Unsupported version number: %2d",
1313 priv->version); 1306 priv->version);
1314 dev = NULL; 1307 return -EINVAL;
1315 break;
1316 } 1308 }
1317 1309
1318return_dev: 1310 return 0;
1319 return dev;
1320} 1311}
1321 1312
1322static int m_can_open(struct net_device *dev) 1313static int m_can_open(struct net_device *dev)
@@ -1656,11 +1647,16 @@ static int m_can_plat_probe(struct platform_device *pdev)
1656 tx_fifo_size = mram_config_vals[7]; 1647 tx_fifo_size = mram_config_vals[7];
1657 1648
1658 /* allocate the m_can device */ 1649 /* allocate the m_can device */
1659 dev = alloc_m_can_dev(pdev, addr, tx_fifo_size); 1650 dev = alloc_candev(sizeof(*priv), tx_fifo_size);
1660 if (!dev) { 1651 if (!dev) {
1661 ret = -ENOMEM; 1652 ret = -ENOMEM;
1662 goto disable_cclk_ret; 1653 goto disable_cclk_ret;
1663 } 1654 }
1655
1656 ret = m_can_dev_setup(pdev, dev, addr);
1657 if (ret)
1658 goto failed_free_dev;
1659
1664 priv = netdev_priv(dev); 1660 priv = netdev_priv(dev);
1665 dev->irq = irq; 1661 dev->irq = irq;
1666 priv->device = &pdev->dev; 1662 priv->device = &pdev->dev;