Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2402059imu; Sun, 18 Nov 2018 23:14:53 -0800 (PST) X-Google-Smtp-Source: AJdET5dVC7NTMQnRxIHueENATtAnsPsFqEEU0hdbPrAOF0AAvik7+zSRvFZebmxzg0VdNG6n7RVe X-Received: by 2002:a62:6143:: with SMTP id v64mr11246816pfb.142.1542611693282; Sun, 18 Nov 2018 23:14:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542611693; cv=none; d=google.com; s=arc-20160816; b=x35Vrm3Bz/C55Eyv1A+MRKJDqXRLiI7bYf2yPXDsgEhazZ6paa2i31tjkW2am1b6QV 6Z+WQVFO6xfgA4sBj3lE0nyaX8Iam68am4yBada7lRIHZOOqhSuDw+spw5kzaGhTejm6 MFs4LjgaG3tTcZQeaRJXt4rEXQgGb+v+qgeo6M+9NKFOvg6eFDKeQ0NeJvXMlAJ6tG9G n4yM7xVwIfWuka3EzLogNCMFTx3Msh101oJYgXwN/GUEiJ9jIByUX9ghi1EghmliZ0V6 PrJiJ+3UajAs6aLezAqkFIEEZI/V1gCmggb2hr/z1cpMSMa8xQur/4xXv6MKUOcEYIb2 7lLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=D+3HHA2utaAOxxvaeBViU6uUuc9KWnMizwi/QFCDndE=; b=anQ/4AbGU9z68mQWo/UP9iyZDLYiRUU15gVXbQ2oidc7E75u3amU5P1SivuWagfOsw INI7RJsuTPWQDQmwk5zYWooLiFHlxozX2z1rC8cLoifve+wJvjtHE6h2UzsowM48R7Cs XGLhcOyi86Qp9Dnbga8WW7r/PEIuFGl2Mv7tqxrIOG3Gz5zoqy9qreZMqyXrvhHwBDvZ mA3c0BJnSKi2mjPjLCoavdSArm0w94spT6MjGqa5DepxUpyrmksOfgGTFxeyfkIX0930 Dkeqzssqohli4ZPmmjO0TNwU+fttQc0QImOVix+riwWgrWwBf0VeXxq5g0uGQ1/zpQla agZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UK/JftDz"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 g184si3349651pfb.288.2018.11.18.23.14.38; Sun, 18 Nov 2018 23:14:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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="UK/JftDz"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1726479AbeKSRgn (ORCPT + 99 others); Mon, 19 Nov 2018 12:36:43 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:36059 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbeKSRgm (ORCPT ); Mon, 19 Nov 2018 12:36:42 -0500 Received: by mail-lf1-f68.google.com with SMTP id a16so1748248lfg.3 for ; Sun, 18 Nov 2018 23:13:56 -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 :mime-version:content-transfer-encoding; bh=D+3HHA2utaAOxxvaeBViU6uUuc9KWnMizwi/QFCDndE=; b=UK/JftDz+v2wFpUjHxntmp6dYZ7V7+B+3gDnJjFatuJdvxvVbVz/4tv19pshN8Jd/z mAeBfhfBDlSJK5jMC4xVAUyuKXZg1HoPARR6/ZSbEI79iljdL7U+EGp3YhN8u/RS069O fMx2JJXwkmLbKF2CbLv8xo+HBbFnS511AqvSw= 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:mime-version:content-transfer-encoding; bh=D+3HHA2utaAOxxvaeBViU6uUuc9KWnMizwi/QFCDndE=; b=bM0PbJtZUp9lmc3eBo5qoJPi6pDQjK+evK5HIPXtHpPpkCF/2LrftXPIAPAnJEiMG3 FUazHvzRokeRtxRHbt7/PmgVJ3Ek59E1X8Ho2gWk3P0uguu1xSi5t8tLF8QHdUbCmyWV rQtmjvewRO0bp16YsL0mhlwS8/uU2C0s0qCsceZQDpjWj33i3mSlK6iw8P9yyXn2zecJ PTtnBPM/EihMrWj6o1gHyRabOhsolB1WEfBnyXxVB1U8ZZWQ0q92b4cZfIZ+RlxYEbGb jh0bR3R6gY0dlBFd/n34ZJYKbdvfUbAMJCetUZVE3IH/uhh3uoCyUPaRGuv/S0BF0H65 c48w== X-Gm-Message-State: AGRZ1gIB9E5CTaFf6twmZyA4MvjRr1aXoZN19j1xO7mizi0zrg2pRICV pSIce1AjIEldpT0/kyuLsA5Geg== X-Received: by 2002:a19:a9d2:: with SMTP id s201mr9603189lfe.154.1542611635934; Sun, 18 Nov 2018 23:13:55 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id 10sm5531584lff.62.2018.11.18.23.13.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Nov 2018 23:13:54 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij Subject: [PATCH 4/5 v7] regulator: gpio: Simplify probe path Date: Mon, 19 Nov 2018 08:11:25 +0100 Message-Id: <20181119071126.8889-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119071126.8889-1-linus.walleij@linaro.org> References: <20181119071126.8889-1-linus.walleij@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use devm_* managed device resources and create a local struct device *dev variable to simplify the code inside probe(). Signed-off-by: Linus Walleij --- ChangeLog v6->v7: - Resend with the rest. ChangeLog v3->v6: - Rebase on top of the other changes. - Change numbering to fit the rest of the series. ChangeLog v2->v3: - Resending. ChangeLog v1->v2: - Rebase the patch on the other changes. --- drivers/regulator/gpio-regulator.c | 55 +++++++++++++----------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 68a6c861bcad..62ddea4a5255 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -228,31 +228,33 @@ static struct regulator_ops gpio_regulator_current_ops = { static int gpio_regulator_probe(struct platform_device *pdev) { - struct gpio_regulator_config *config = dev_get_platdata(&pdev->dev); - struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; + struct gpio_regulator_config *config = dev_get_platdata(dev); + struct device_node *np = dev->of_node; struct gpio_regulator_data *drvdata; struct regulator_config cfg = { }; enum gpiod_flags gflags; int ptr, ret, state, i; - drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), + drvdata = devm_kzalloc(dev, sizeof(struct gpio_regulator_data), GFP_KERNEL); if (drvdata == NULL) return -ENOMEM; if (np) { - config = of_get_gpio_regulator_config(&pdev->dev, np, + config = of_get_gpio_regulator_config(dev, np, &drvdata->desc); if (IS_ERR(config)) return PTR_ERR(config); } - drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); + drvdata->desc.name = devm_kstrdup(dev, config->supply_name, GFP_KERNEL); if (drvdata->desc.name == NULL) { - dev_err(&pdev->dev, "Failed to allocate supply name\n"); + dev_err(dev, "Failed to allocate supply name\n"); return -ENOMEM; } + for (i = 0; i < config->ngpios; i++) { drvdata->gpiods[i] = devm_gpiod_get_index(&pdev->dev, NULL, @@ -265,14 +267,14 @@ static int gpio_regulator_probe(struct platform_device *pdev) } drvdata->nr_gpios = config->ngpios; - drvdata->states = kmemdup(config->states, - config->nr_states * - sizeof(struct gpio_regulator_state), - GFP_KERNEL); + drvdata->states = devm_kmemdup(dev, + config->states, + config->nr_states * + sizeof(struct gpio_regulator_state), + GFP_KERNEL); if (drvdata->states == NULL) { - dev_err(&pdev->dev, "Failed to allocate state data\n"); - ret = -ENOMEM; - goto err_name; + dev_err(dev, "Failed to allocate state data\n"); + return -ENOMEM; } drvdata->nr_states = config->nr_states; @@ -291,9 +293,8 @@ static int gpio_regulator_probe(struct platform_device *pdev) drvdata->desc.ops = &gpio_regulator_current_ops; break; default: - dev_err(&pdev->dev, "No regulator type set\n"); - ret = -EINVAL; - goto err_memstate; + dev_err(dev, "No regulator type set\n"); + return -EINVAL; } /* build initial state from gpio init data. */ @@ -304,7 +305,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) } drvdata->state = state; - cfg.dev = &pdev->dev; + cfg.dev = dev; cfg.init_data = config->init_data; cfg.driver_data = drvdata; cfg.of_node = np; @@ -318,28 +319,20 @@ static int gpio_regulator_probe(struct platform_device *pdev) else gflags = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE; - cfg.ena_gpiod = devm_gpiod_get_optional(&pdev->dev, "enable", gflags); - if (IS_ERR(cfg.ena_gpiod)) { - ret = PTR_ERR(cfg.ena_gpiod); - goto err_memstate; - } + cfg.ena_gpiod = devm_gpiod_get_optional(dev, "enable", gflags); + if (IS_ERR(cfg.ena_gpiod)) + return PTR_ERR(cfg.ena_gpiod); drvdata->dev = regulator_register(&drvdata->desc, &cfg); if (IS_ERR(drvdata->dev)) { ret = PTR_ERR(drvdata->dev); - dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); - goto err_memstate; + dev_err(dev, "Failed to register regulator: %d\n", ret); + return ret; } platform_set_drvdata(pdev, drvdata); return 0; - -err_memstate: - kfree(drvdata->states); -err_name: - kfree(drvdata->desc.name); - return ret; } static int gpio_regulator_remove(struct platform_device *pdev) @@ -347,8 +340,6 @@ static int gpio_regulator_remove(struct platform_device *pdev) struct gpio_regulator_data *drvdata = platform_get_drvdata(pdev); regulator_unregister(drvdata->dev); - kfree(drvdata->states); - kfree(drvdata->desc.name); return 0; } -- 2.19.1