From patchwork Tue Jan 29 10:31:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 156955 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4490904jaa; Tue, 29 Jan 2019 02:32:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN6VtKPVuoW1pEx4ZfQlShQRJIgT86o3oNsFRsT9lE0/zzEqxcSUGZKLqs1Dw3erSgDXu1al X-Received: by 2002:a63:193:: with SMTP id 141mr23326685pgb.136.1548757944983; Tue, 29 Jan 2019 02:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548757944; cv=none; d=google.com; s=arc-20160816; b=ijBDPhRBzBIF/ys2yAaxHvqyJqzH5lDZLd/xJFXMffI33vaqUqzDMGDiAE1gy3xCnV Fp8+BjBYJp3aYUym6i+IAB6bMi0202RXNx53+JVnCyCBJwomXQ9nE1hoW9Y91U2ZCRVs IKzs0aD8kFwfCyJoQXbMoSDh6vEagf5oJU5Gjp2qvgaldoa5Q4VVV5GAgcZqcQr3C+50 esXZgBCWx7DFyibZvzQJr14pjw88KT6vqxjCA2MZgWUEwpv/5wUzDH0tBoIrDY442kdF /9wAZyJGgd4xbhSD/5I8x9kLhEOmodVoZbRViaUzB/fhWFsGmi46gSBuvOKQlQUjzzxw D0hg== 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=V5UvtJ3mX5DrioHKtn7NF8k5S+MYyfiW4iemDDngUmk=; b=Doh1k++p/BHSgppEV1QwVJBZF5jGJzzG+H4kEbgzeOpF7WWLUWP/EA9eyOeQamN4qn +uZzoBX29vbp3KJT3vqe/QVPPaESrdpIkakWg+W926fWLvaqbNBZwNrAdfKKS3yvewlT zz/xhlQ845aoAOEP7CktfenQYvt6COr0Qn2+mnXu+ovZy6HkHEGRbEqYTmTzbqaCD4Vz vH81g3A+BZqaAwvVY2GI/0Taprj9JZN2m710E8l6T+3s1mcEVInLe1FCWwBQffqxV3BX 0XoXFkPX3swRRy+X5KRB35t0Sa9ApXgFVFKAqLrHO9incaoMSArn4HhvPkBBjBC7uCFw YwPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cu6xwnVB; 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 c1si9997836pld.194.2019.01.29.02.32.24; Tue, 29 Jan 2019 02:32:24 -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=cu6xwnVB; 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 S1728506AbfA2KcR (ORCPT + 31 others); Tue, 29 Jan 2019 05:32:17 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:38002 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728456AbfA2KcO (ORCPT ); Tue, 29 Jan 2019 05:32:14 -0500 Received: by mail-lf1-f67.google.com with SMTP id a8so14222418lfk.5 for ; Tue, 29 Jan 2019 02:32:12 -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=V5UvtJ3mX5DrioHKtn7NF8k5S+MYyfiW4iemDDngUmk=; b=cu6xwnVBbn4OCRaoVmoASeOMq9tuDYqYMI12GrfgklfPYjxz4r/arJ1X/Ndm3JI52A SavJr5iJpKgy8zIaVtLZb5t3Q+F85O7W5qyr/nBeYV2zmFO3poZP5h6I9Qd55rdB0J+r inJvZAWGbvmJkNmLvAtl5RkD3+1oqKGPWDAVI= 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=V5UvtJ3mX5DrioHKtn7NF8k5S+MYyfiW4iemDDngUmk=; b=MFec7UL/xMu0UCVBV2UQje0332uRB4OOrBybha3tTn3mm3b06NniPF9CEq4MVPlIWc KMfnV0rWkdnHW6fMPxt+r6r0iT1bDJyIiO0C3B8e32Vvkgak/34n60WXh3jD5JJA9EmT KxgLne/iPctpH5ry4Auq2J7hOyxdRaljgg7/fEPbSuCTPqAuQ4LyEPkROVmN0cprCeU6 8bNsghBwrwv7Xuvkwj6YA9yuuoXtNxcVX4/0Q0TojSuKgFiipT3WRAy0NEzxtRnlVMG4 vE73fyn/RPpvCtW06Hup7K0AC+OsLSujRT+Q05EZ9J7OfHB3NhSoBv5lDi6QEVvy3LTo c3CQ== X-Gm-Message-State: AJcUukd+tRMl6P8hxFhWrtmSka19yeLjDomW5Lxk6c+rDL+lVPt3LGDG tbhlb9XbFZ6YX0CB4/L7Xv7nsw== X-Received: by 2002:a19:ced3:: with SMTP id e202mr20829827lfg.13.1548757931492; Tue, 29 Jan 2019 02:32:11 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id y9sm3471540lfe.75.2019.01.29.02.32.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 02:32:10 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Charles Keepax , Bartosz Golaszewski , Marek Szyprowski , Linus Walleij Subject: [PATCH 4/5 v10] regulator: gpio: Simplify probe path Date: Tue, 29 Jan 2019 11:31:55 +0100 Message-Id: <20190129103156.10139-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129103156.10139-1-linus.walleij@linaro.org> References: <20190129103156.10139-1-linus.walleij@linaro.org> MIME-Version: 1.0 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(). Tested-by: Marek Szyprowski Signed-off-by: Linus Walleij --- ChangeLog v9->v10: - Properly change &pdev->dev to local dev pointer in this patch, this was acccidentally exploited in patch 1. - Rebase on other changes. ChangeLog v8->v9: - Rebased on other changes. - Collected Marek's Tested-by. ChangeLog v7->v8: - Rebase on v5.0-rc1. 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 | 58 +++++++++++++----------------- 1 file changed, 24 insertions(+), 34 deletions(-) -- 2.20.1 diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 07fb41abd4e8..6157001df0a4 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -228,37 +228,38 @@ 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; } - drvdata->gpiods = devm_kzalloc(&pdev->dev, sizeof(struct gpio_desc *), + drvdata->gpiods = devm_kzalloc(dev, sizeof(struct gpio_desc *), GFP_KERNEL); if (!drvdata->gpiods) return -ENOMEM; for (i = 0; i < config->ngpios; i++) { - drvdata->gpiods[i] = devm_gpiod_get_index(&pdev->dev, + drvdata->gpiods[i] = devm_gpiod_get_index(dev, NULL, i, config->gflags[i]); @@ -269,14 +270,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; @@ -295,9 +296,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. */ @@ -308,7 +308,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; @@ -322,28 +322,20 @@ static int gpio_regulator_probe(struct platform_device *pdev) else gflags = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE; - cfg.ena_gpiod = 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 = 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) @@ -351,8 +343,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; }