From patchwork Tue Jan 16 11:37:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Faiz Abbas X-Patchwork-Id: 861419 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="VbiG+QaP"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zLSrc1Jmbz9t2Q for ; Tue, 16 Jan 2018 22:37:52 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752004AbeAPLg7 (ORCPT ); Tue, 16 Jan 2018 06:36:59 -0500 Received: from fllnx209.ext.ti.com ([198.47.19.16]:61117 "EHLO fllnx209.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751983AbeAPLg4 (ORCPT ); Tue, 16 Jan 2018 06:36:56 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id w0GBaen5026335; Tue, 16 Jan 2018 05:36:40 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1516102600; bh=VXHnMOOSBHkGXlTrlobruBzu+2ZbpuU+YzgF+7hwErU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=VbiG+QaPbotkwkUL9lIwAenJ3V28UrXUff+xtIZr+y6yzIUE8WZIcM2JbYZ6Dh/Yp 3vJQ0/Vmo/q6R6004fbZTTKtRkulOUCOyDDYEWjyDddyRpTApmvMwXywU1Xe0VVzGN JlBzLKhrqoe9eceIPgp4VyFHUBMDIcPhd8JATjtc= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0GBaejr003715; Tue, 16 Jan 2018 05:36:40 -0600 Received: from DLEE109.ent.ti.com (157.170.170.41) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Tue, 16 Jan 2018 05:36:40 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Tue, 16 Jan 2018 05:36:40 -0600 Received: from a0230074-OptiPlex-7010.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0GBaLDx026868; Tue, 16 Jan 2018 05:36:36 -0600 From: Faiz Abbas To: , , , CC: , , , , , , , , , , , Subject: [PATCH v8 3/5] can: m_can: Move allocation of net device to probe Date: Tue, 16 Jan 2018 17:07:12 +0530 Message-ID: <1516102634-6771-4-git-send-email-faiz_abbas@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516102634-6771-1-git-send-email-faiz_abbas@ti.com> References: <1516102634-6771-1-git-send-email-faiz_abbas@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- drivers/net/can/m_can/m_can.c | 30 +++++++++++++----------------- 1 file 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 893edbb..ebb74de 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); @@ -1267,16 +1262,12 @@ static struct net_device *alloc_m_can_dev(struct platform_device *pdev, : 0); break; default: - /* Unsupported device: free candev */ - 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 +1607,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 failed_free_dev; + priv = netdev_priv(dev); dev->irq = irq; priv->device = &pdev->dev;