From patchwork Sun Feb 25 12:51:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 129518 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp2580649lja; Sun, 25 Feb 2018 04:54:04 -0800 (PST) X-Google-Smtp-Source: AH8x225dhcgx7jQjw8geI3A46e1pfXYc6rmDyh1cToKSnxInLCh5NIm12WgklploQ5AtqjEwtO0m X-Received: by 10.101.101.78 with SMTP id a14mr5939486pgw.368.1519563243938; Sun, 25 Feb 2018 04:54:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519563243; cv=none; d=google.com; s=arc-20160816; b=SCADZVlU1xjVISIxsnhwOSmEVw/8zjS+wm28JqBou7fMbOxYcN5+SRxfKj1Z/IXzhV NPf2tdYxC3EHlch21rRWPWsjjY4YAN860bHf+xtUYaKzxAar6eu2Jl8Rl+mTVtM6AAwb xUisa6FwxrN2KjfgkHxWTDmYj6DAaS5CwpZY46n09SL7Chp7dQCHXg5TsVBcW888qdGL cBOq0NQITl6zUSj9FuKs2e1FgnLOAsWeVJXo2zTgx4R4KRfec8vjawJH4z17VMroWPpK MEmfSQMh7Y548Z7qtJE8rcM1Szk33nqAAoXRmSFPHS8xtedN2kONWdpgYaakbjXQ9IRg kZeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=3yrUy3EnPsdo/7mgRKoHBojWTaDXFqAwhxxVWfcVdac=; b=uO75BQCB0SJwEraBzv/m1kEdHonCYU3farZMiUpLXT9FORuTFa8zSlQpjCNwDp4B9k 3Td7zcz53q1FDHH+fXoLF205bx3V9fzTh8vtaHFNSt5UWPl6yauFA8kgFF2JmJRF6pt2 dfStmSFBPuIMZk/uN7gsbVICa914Ak1q+WtX8Pv1F8nFZhd2YNpKfrox1UrNMsR9Tj+Q Aj0O6keOEo2FNxLmG6LAn4QyF9tU9Gntsfa8BtQLn5XWuvEjD4+HQEwwHnU2yguerYyO hCoeCovd3lUbXMJTx3tQCcITlBKhKIcLle9ntpNePQQ4o6LBbs8tP7TQpFIXmUNm3Uad 6hZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jaHAcH8w; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s4si4218252pgf.390.2018.02.25.04.54.03; Sun, 25 Feb 2018 04:54:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of netdev-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 header.s=google header.b=jaHAcH8w; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 S1751761AbeBYMyA (ORCPT + 8 others); Sun, 25 Feb 2018 07:54:00 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:38944 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751732AbeBYMx6 (ORCPT ); Sun, 25 Feb 2018 07:53:58 -0500 Received: by mail-lf0-f67.google.com with SMTP id f75so13409979lfg.6 for ; Sun, 25 Feb 2018 04:53:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3yrUy3EnPsdo/7mgRKoHBojWTaDXFqAwhxxVWfcVdac=; b=jaHAcH8wumM+D4FjIn2DhhKFPE2oi1+At5s9gBe3ZLk13DQgftewHdcjizjtBN8Pr0 H2CRFNJkasO8jHQSnP17ZVHSfA7dLvuOTgnkF3H2lj8a7DVJHq7PBnloCtlH/GYN7163 C/kNkiGgqBw4drvG8NBvQHDWNPwHbQiYy+dQE= 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:in-reply-to :references; bh=3yrUy3EnPsdo/7mgRKoHBojWTaDXFqAwhxxVWfcVdac=; b=k8rfTyrM1YYhduF5EwWaVcLajKV8/3d+ro0h3fKDZllaI9lZrqgvfwQh3aAMiJDoqv 3Z3W9gaOIu9tVtt7jC+cJHMuEigU2lYPQ3XBiGWMlcQKFu2Ni9YZ20TYRO8zy9BILfkX rgfWKwDeVqbxMOloXBtTQ1V8IjJtgjhIN7dtTr9yqCsxzPAtIXyig4+puFf01/bj0qQl LiGTRDWfBl1IxXF8K7l9EKkAsZu+yso+XH9fRTi+27e937K6b2byvanhvqCHCm1BXxks UVIs8bMXaaPkdBbZRCORaWC49Ax9O1TnBKjZEESYV6FD5rMpPTAHMAm3EG/bJmAjYeHP 0Pdg== X-Gm-Message-State: APf1xPDze9kdOoEUpRf5ppbemZLVI9EjBVnxWSRjXra0yi5Pv1dII1b8 28Y6UrjRyhEId0Av5uNJPeBMyA== X-Received: by 10.46.58.2 with SMTP id h2mr5571223lja.95.1519563237079; Sun, 25 Feb 2018 04:53:57 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id 5sm1456574lfp.17.2018.02.25.04.53.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 25 Feb 2018 04:53:56 -0800 (PST) From: Linus Walleij To: Andrew Lunn , Florian Fainelli , "David S . Miller" Cc: netdev@vger.kernel.org, Laurent Pinchart , Linus Walleij Subject: [PATCH net-next 2/5] net: mdio-gpio: Allocate state in probe() Date: Sun, 25 Feb 2018 13:51:29 +0100 Message-Id: <20180225125132.25275-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180225125132.25275-1-linus.walleij@linaro.org> References: <20180225125132.25275-1-linus.walleij@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Allocate the state container for the driver, struct mdio_gpio_info inside the probe() function instead of in the mdio_gpio_bus_init() function. Create the local struct device *dev variable in probe() and pass that around instead of constantly dereferencing the struct platform_data. Signed-off-by: Linus Walleij --- drivers/net/phy/mdio-gpio.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) -- 2.14.3 diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c index 6d669f24c0e6..d95bb45eb67b 100644 --- a/drivers/net/phy/mdio-gpio.c +++ b/drivers/net/phy/mdio-gpio.c @@ -52,14 +52,14 @@ struct mdio_gpio_info { struct gpio_desc *mdc, *mdio, *mdo; }; -static void *mdio_gpio_of_get_data(struct platform_device *pdev) +static void *mdio_gpio_of_get_data(struct device *dev) { - struct device_node *np = pdev->dev.of_node; + struct device_node *np = dev->of_node; struct mdio_gpio_platform_data *pdata; enum of_gpio_flags flags; int ret; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) return NULL; @@ -142,21 +142,17 @@ static const struct mdiobb_ops mdio_gpio_ops = { }; static struct mii_bus *mdio_gpio_bus_init(struct device *dev, + struct mdio_gpio_info *bitbang, struct mdio_gpio_platform_data *pdata, int bus_id) { struct mii_bus *new_bus; - struct mdio_gpio_info *bitbang; int i; int mdc, mdio, mdo; unsigned long mdc_flags = GPIOF_OUT_INIT_LOW; unsigned long mdio_flags = GPIOF_DIR_IN; unsigned long mdo_flags = GPIOF_OUT_INIT_HIGH; - bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL); - if (!bitbang) - goto out; - bitbang->ctrl.ops = &mdio_gpio_ops; bitbang->ctrl.reset = pdata->reset; mdc = pdata->mdc; @@ -234,35 +230,41 @@ static void mdio_gpio_bus_destroy(struct device *dev) static int mdio_gpio_probe(struct platform_device *pdev) { struct mdio_gpio_platform_data *pdata; + struct device *dev = &pdev->dev; + struct mdio_gpio_info *bitbang; struct mii_bus *new_bus; int ret, bus_id; + bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL); + if (!bitbang) + return -ENOMEM; + if (pdev->dev.of_node) { - pdata = mdio_gpio_of_get_data(pdev); - bus_id = of_alias_get_id(pdev->dev.of_node, "mdio-gpio"); + pdata = mdio_gpio_of_get_data(dev); + bus_id = of_alias_get_id(dev->of_node, "mdio-gpio"); if (bus_id < 0) { - dev_warn(&pdev->dev, "failed to get alias id\n"); + dev_warn(dev, "failed to get alias id\n"); bus_id = 0; } } else { - pdata = dev_get_platdata(&pdev->dev); + pdata = dev_get_platdata(dev); bus_id = pdev->id; } if (!pdata) return -ENODEV; - new_bus = mdio_gpio_bus_init(&pdev->dev, pdata, bus_id); + new_bus = mdio_gpio_bus_init(dev, bitbang, pdata, bus_id); if (!new_bus) return -ENODEV; - if (pdev->dev.of_node) - ret = of_mdiobus_register(new_bus, pdev->dev.of_node); + if (dev->of_node) + ret = of_mdiobus_register(new_bus, dev->of_node); else ret = mdiobus_register(new_bus); if (ret) - mdio_gpio_bus_deinit(&pdev->dev); + mdio_gpio_bus_deinit(dev); return ret; }