From patchwork Tue Apr 4 06:17:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 96682 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp48255qgd; Mon, 3 Apr 2017 23:18:14 -0700 (PDT) X-Received: by 10.84.148.134 with SMTP id k6mr27329211pla.128.1491286694780; Mon, 03 Apr 2017 23:18:14 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si746909pgf.57.2017.04.03.23.18.14; Mon, 03 Apr 2017 23:18:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751952AbdDDGSO (ORCPT + 6 others); Tue, 4 Apr 2017 02:18:14 -0400 Received: from mail-pg0-f48.google.com ([74.125.83.48]:36005 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750962AbdDDGSN (ORCPT ); Tue, 4 Apr 2017 02:18:13 -0400 Received: by mail-pg0-f48.google.com with SMTP id g2so140810694pge.3 for ; Mon, 03 Apr 2017 23:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vjbPVhUxjZoRmwb6Vl2TXFc9Lu4gLHzkG2m19o3s9EU=; b=TtzM7ai37nGwcnCB+H+hQMfXqynKOKG+vCrYpuTX3lL/8QcjCz5sSUdm063GNb8Wtp bLCcB46Uwm8DGzNPubK/hXYS0KIi7IYpjxr0PSrjst6Ta+l0flbI9aA1G+0GIGKgY+nx z3TQhubMC+n+w/ikoqEA7BN7gsGanoWJwyeVk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vjbPVhUxjZoRmwb6Vl2TXFc9Lu4gLHzkG2m19o3s9EU=; b=fhuWORhq/W+IMblTnQHPQIt59HsIWLYt9oQhidKReBOanizDFMByWNQhDDd2L9+vOJ ycY2SMo/jVTP8YY2pzcTa6OAn/FXzZrnfYaNjB9whCKGkyFrvq36X1vrJCU2U+iMbd20 bSa0QTjMrlzi3fruD4Jxh1Sl3AwXDZ8eaSHHizdpNYzzWaMVCyBSOJTKq2MVkCHOGlnF j7LdV5xYrmi2mYCEGQn4dSDyO9KG9z6wkX79+WCgkZxpafoBvWlU5f1l9T9Ve2WU4cor GCihPOYlAvh+vol60KNKn0ASsdSpqXemUBrOUK+z9WuGex5RdU1YrIlMuRpTALuS3WWH XwwA== X-Gm-Message-State: AFeK/H1FKY5jXR7abjnqqvewq3ymLPggi95x+EQ76zDLNLVZuPZbvSYgeEpj9b5HSunfUqiZ X-Received: by 10.98.30.3 with SMTP id e3mr20826362pfe.48.1491286692649; Mon, 03 Apr 2017 23:18:12 -0700 (PDT) Received: from localhost.localdomain ([106.51.240.246]) by smtp.gmail.com with ESMTPSA id m20sm29331500pgd.32.2017.04.03.23.18.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Apr 2017 23:18:12 -0700 (PDT) From: Amit Pundir To: gregkh@linuxfoundation.org Cc: stable@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , "David S . Miller" Subject: [PATCH 20/33] net: bgmac: allocate struct bgmac just once & don't copy it Date: Tue, 4 Apr 2017 11:47:59 +0530 Message-Id: <1491286688-31314-1-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Rafał Miłecki So far were were allocating struct bgmac in 3 places: platform code, bcma code and shared bgmac_enet_probe function. The reason for this was bgmac_enet_probe: 1) Requiring early-filled struct bgmac 2) Calling alloc_etherdev on its own in order to use netdev_priv later This solution got few drawbacks: 1) Was duplicating allocating code 2) Required copying early-filled struct 3) Resulted in platform/bcma code having access only to unused struct Solve this situation by simply extracting some probe code into the new bgmac_alloc function. Signed-off-by: Rafał Miłecki Reviewed-by: Florian Fainelli Signed-off-by: David S. Miller (cherry picked from commit 34a5102c3235c470a6c77fba16cb971964d9c136) Signed-off-by: Amit Pundir --- drivers/net/ethernet/broadcom/bgmac-bcma.c | 4 +--- drivers/net/ethernet/broadcom/bgmac-platform.c | 2 +- drivers/net/ethernet/broadcom/bgmac.c | 25 +++++++++++++++++-------- drivers/net/ethernet/broadcom/bgmac.h | 3 ++- 4 files changed, 21 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/drivers/net/ethernet/broadcom/bgmac-bcma.c b/drivers/net/ethernet/broadcom/bgmac-bcma.c index c16ec3a..5b0c7a7 100644 --- a/drivers/net/ethernet/broadcom/bgmac-bcma.c +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c @@ -99,12 +99,11 @@ static int bgmac_probe(struct bcma_device *core) u8 *mac; int err; - bgmac = kzalloc(sizeof(*bgmac), GFP_KERNEL); + bgmac = bgmac_alloc(&core->dev); if (!bgmac) return -ENOMEM; bgmac->bcma.core = core; - bgmac->dev = &core->dev; bgmac->dma_dev = core->dma_dev; bgmac->irq = core->irq; @@ -285,7 +284,6 @@ static int bgmac_probe(struct bcma_device *core) err1: bcma_mdio_mii_unregister(bgmac->mii_bus); err: - kfree(bgmac); bcma_set_drvdata(core, NULL); return err; diff --git a/drivers/net/ethernet/broadcom/bgmac-platform.c b/drivers/net/ethernet/broadcom/bgmac-platform.c index be52f27..020f487 100644 --- a/drivers/net/ethernet/broadcom/bgmac-platform.c +++ b/drivers/net/ethernet/broadcom/bgmac-platform.c @@ -93,7 +93,7 @@ static int bgmac_probe(struct platform_device *pdev) struct resource *regs; const u8 *mac_addr; - bgmac = devm_kzalloc(&pdev->dev, sizeof(*bgmac), GFP_KERNEL); + bgmac = bgmac_alloc(&pdev->dev); if (!bgmac) return -ENOMEM; diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c index 49f4cafe..537b00b 100644 --- a/drivers/net/ethernet/broadcom/bgmac.c +++ b/drivers/net/ethernet/broadcom/bgmac.c @@ -1459,22 +1459,32 @@ static int bgmac_phy_connect(struct bgmac *bgmac) return 0; } -int bgmac_enet_probe(struct bgmac *info) +struct bgmac *bgmac_alloc(struct device *dev) { struct net_device *net_dev; struct bgmac *bgmac; - int err; /* Allocation and references */ - net_dev = alloc_etherdev(sizeof(*bgmac)); + net_dev = devm_alloc_etherdev(dev, sizeof(*bgmac)); if (!net_dev) - return -ENOMEM; + return NULL; net_dev->netdev_ops = &bgmac_netdev_ops; net_dev->ethtool_ops = &bgmac_ethtool_ops; + bgmac = netdev_priv(net_dev); - memcpy(bgmac, info, sizeof(*bgmac)); + bgmac->dev = dev; bgmac->net_dev = net_dev; + + return bgmac; +} +EXPORT_SYMBOL_GPL(bgmac_alloc); + +int bgmac_enet_probe(struct bgmac *bgmac) +{ + struct net_device *net_dev = bgmac->net_dev; + int err; + net_dev->irq = bgmac->irq; SET_NETDEV_DEV(net_dev, bgmac->dev); @@ -1501,7 +1511,7 @@ int bgmac_enet_probe(struct bgmac *info) err = bgmac_dma_alloc(bgmac); if (err) { dev_err(bgmac->dev, "Unable to alloc memory for DMA\n"); - goto err_netdev_free; + goto err_out; } bgmac->int_mask = BGMAC_IS_ERRMASK | BGMAC_IS_RX | BGMAC_IS_TX_MASK; @@ -1537,8 +1547,7 @@ int bgmac_enet_probe(struct bgmac *info) phy_disconnect(net_dev->phydev); err_dma_free: bgmac_dma_free(bgmac); -err_netdev_free: - free_netdev(net_dev); +err_out: return err; } diff --git a/drivers/net/ethernet/broadcom/bgmac.h b/drivers/net/ethernet/broadcom/bgmac.h index 80836b4..69d478a 100644 --- a/drivers/net/ethernet/broadcom/bgmac.h +++ b/drivers/net/ethernet/broadcom/bgmac.h @@ -515,7 +515,8 @@ struct bgmac { u32 set); }; -int bgmac_enet_probe(struct bgmac *info); +struct bgmac *bgmac_alloc(struct device *dev); +int bgmac_enet_probe(struct bgmac *bgmac); void bgmac_enet_remove(struct bgmac *bgmac); struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);