From patchwork Sun Apr 22 23:07:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 133938 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp368999lji; Sun, 22 Apr 2018 16:11:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+Vyyr5WrN+Bfj1Atei/1k0g3VLfaVM9B4Qv6QilXzyBIo7vWORhr2RUHRkAfdl7/u7kFIW X-Received: by 10.99.160.106 with SMTP id u42mr14736163pgn.389.1524438677952; Sun, 22 Apr 2018 16:11:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524438677; cv=none; d=google.com; s=arc-20160816; b=xAuKvDN4itQt92vGqeLomXk6PvBZzF6UEKvk8/TvLJtUpaz0upxjCkHJAS1oqSGuC8 c6F/zQZ1S6fLXorLvYgqXGVfqfvPiJpIldymh2y4YYQDOvCiACxdyzVPl3goVtmDUhXu YxFa9qBdOlHfwzQjTJ0byz8y4YMy/gdPg3pd3RGcu+uJXAnNX3jq4iwlOoNmZqydBWcc vBsUBEToXtOSvYUFr/LdMYn2yBUcqTEUmlNIRBQzoP1uUvuaVOZSaaq2qLOK6uLPMl+X fcb0aUxarnt3vTSdfkNnRcO//PBdgVd8jvFPLtNuZXrLyD5VCL3cB2N8RIw6GdAHvWsO kFcw== 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=QEw14JMUgGrqO20JULTN0mCeOahs6b8QHm5uQv/Q7zU=; b=W7ipARgaIRTa6KfaYgdHfl1ystt3ldXfbP5NqIZsltZATd1tzddiNEG7ySx7mjQsql E0Do7zSn9nmsZWO4IXowIjwPdpVhQEbFzMsyhtryyYHUdCVdhcWYsflKCiPuR/nka+FK DlXfgbpZ/bRkNGjpscK4vtH08eo1UyHi8YCCPlbhiJ+YFurepPUh5rrrNp1ccbSHb1eX U6oJki+ZoY+iLMDEvZswwEvmltkbjYmG/gzer0AZ8CDhX3tRMi7TaE6HzzNV/9QahMgO UE2nzSXAE8U2PXDtRz0cu5T/4YhC1IoncMP6zT2btJRZrN35A5wfVPKmWHA1ZDTmFYvG amEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B77RDkm/; 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 r129si10270705pfc.202.2018.04.22.16.11.17; Sun, 22 Apr 2018 16:11:17 -0700 (PDT) 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=B77RDkm/; 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 S1754015AbeDVXLO (ORCPT + 29 others); Sun, 22 Apr 2018 19:11:14 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:33516 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753943AbeDVXKb (ORCPT ); Sun, 22 Apr 2018 19:10:31 -0400 Received: by mail-lf0-f66.google.com with SMTP id y15-v6so4103718lfj.0 for ; Sun, 22 Apr 2018 16:10:30 -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:in-reply-to:references; bh=QEw14JMUgGrqO20JULTN0mCeOahs6b8QHm5uQv/Q7zU=; b=B77RDkm/2ppEMx4GMMUKO0XwZYcvwYBdabbI1psS9z3nYoHgFMkzrkr0uqvYT5bLCm CtzXij9jpK2rYow0rDl5oelTwlWjXUoRyGQIQsXNtjRZ8ahPzxTBin9XxKNW2Vm3rGTA /5dEJG/2XmMj9esCCEtkLiZtB4eElqnDoTCwU= 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=QEw14JMUgGrqO20JULTN0mCeOahs6b8QHm5uQv/Q7zU=; b=K3EWwrnlpeihiQl7KiSXaDARpxxWCFq/B0bF/CSj6NYCJ3RmebSXnNHY2Xvnf+VDig ekD5NyqR7FluS+dkBE6opTHe9KH1weLVx5AltejqOt4U/5kqMg8e3J1c1fSENc6IjAbJ 3hlxP5mvGCyr2ZTBGxQ+l0+xq9EQNaqKJ7M1tpSd7FJRlKjhdxXHWNhYKLdtoAFn5mrk RHkkpYFVUbElmevYCm6Mz6PIY6iCpBnKL/pNzBeU5qt3mI1B8A4/+p2mrwZSIs7AA9It 8J14l/ZoV7NtW98/TOIB9np64cfVx3VUhCUwAdulGlKzNXlB0uWQ4NHilw5eQHxMEVfg 972Q== X-Gm-Message-State: ALQs6tAzxncFSBhWlcaxmLKjT7Ig5gmH94S4lDBQKKJN1Rx3+nndJwj/ e1jdceobpKcyX1lJ66Oz7HRIAg== X-Received: by 10.46.118.22 with SMTP id r22mr11841094ljc.144.1524438630235; Sun, 22 Apr 2018 16:10:30 -0700 (PDT) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id r25sm2036291ljc.8.2018.04.22.16.10.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Apr 2018 16:10:29 -0700 (PDT) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij Subject: [PATCH 18/18 v2] regulator: gpio: Simplify probe path Date: Mon, 23 Apr 2018 01:07:42 +0200 Message-Id: <20180422230742.3729-18-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180422230742.3729-1-linus.walleij@linaro.org> References: <20180422230742.3729-1-linus.walleij@linaro.org> 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 v1->v2: - Rebase the patch on the other changes. --- drivers/regulator/gpio-regulator.c | 56 ++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 33 deletions(-) -- 2.14.3 diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 756b7b50ffba..e4b573bf8b99 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -228,27 +228,28 @@ 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); } for (i = 0; i < config->ngpios; i++) { - drvdata->gpiods[i] = devm_gpiod_get_index(&pdev->dev, + drvdata->gpiods[i] = devm_gpiod_get_index(dev, config->supply_name, i, config->gflags[i]); @@ -257,20 +258,20 @@ static int gpio_regulator_probe(struct platform_device *pdev) } drvdata->nr_gpios = config->ngpios; - 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; } - 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; @@ -289,9 +290,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. */ @@ -302,7 +302,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; @@ -316,28 +316,20 @@ static int gpio_regulator_probe(struct platform_device *pdev) else gflags = GPIOD_OUT_LOW; - 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) @@ -345,8 +337,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; }