From patchwork Mon Jan 7 16:27:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 154900 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3666665ljp; Mon, 7 Jan 2019 08:31:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vl9GfkwZn3vLywZh6p0O5UVU3uSSAtHfc9yAPACv/EleKCovxpeRxNiMqCf0SiM/CxUVwC X-Received: by 2002:a62:3c1:: with SMTP id 184mr64258512pfd.56.1546878664531; Mon, 07 Jan 2019 08:31:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546878664; cv=none; d=google.com; s=arc-20160816; b=VGhk0lufHWLYgNHTJymTZC8S8OAbRMcf6TxK9uVFDigElFnGwyeQDLDHG32jI7AVpz MhUw6svy6o6B7DeuZAxpSID521k3OVKruqTmJ8nn27QSKWXK7zGW6eHMPDS0N0vV4Zmk /sCYIFrEAzXGTqZce68UCpWWwxYDoGPhMX4jYrM6TxpRdYo51PuIH7Kl/gMwowY2itoI TfxYvPv9Cf7rvYx6GR6wm9PbV0zLK8oq8b6IZbQdlKfazV4UoY9WJWiVl3xPmLlvDNgk qScWMfKMgG1UWIl2qPsWvwm7uoOg3fAXOxZikRanB7a9H/Uyt9/Xt+q/zi3qSug2nnn2 +ICg== 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=+rvNWr8qhAwTT9uCU3yUy08DF4gzzlfFsqLWiWHL/S0=; b=vKFR9cT3rKxKLzShsJNox6yu56NsirxxPtvz0G77nGAwbGBvGQAQzBO20s7I+ips1p CrQimy1qPhGve/iYJOQtOJExyeZ/BCkY0ZR4X1OgG2PfyBSdwpekMjDUSkDj2qKxmtNV yxIFWbYijjsfDxXFEVIFceffCbOp0YiSXpE9BDr3jDyQfoLrQtrRqVBvsUskecI7J/5v eOEe7hjWuPeDNnic8u+ex1JYal26IywBawExnvHGH/vBT10z9PLckOBK7wV/sOouknHp XxyUDf94IG1Tq2TioN6R0vqjg7HMrImmeSTLIJrd1X5cIMy8I9owJYolAB/Ku8W8dca7 EO7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iG5BPQon; 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 w11si17719652pfk.210.2019.01.07.08.31.04; Mon, 07 Jan 2019 08:31:04 -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=iG5BPQon; 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 S1727190AbfAGQbD (ORCPT + 31 others); Mon, 7 Jan 2019 11:31:03 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39646 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727090AbfAGQbA (ORCPT ); Mon, 7 Jan 2019 11:31:00 -0500 Received: by mail-lj1-f196.google.com with SMTP id t9-v6so859374ljh.6 for ; Mon, 07 Jan 2019 08:30:59 -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=+rvNWr8qhAwTT9uCU3yUy08DF4gzzlfFsqLWiWHL/S0=; b=iG5BPQonQ/ixGzfZ0z0ejLysF2TW8TIvzhyrSAx4b8wBESXxWycs0k+P3WYLL55dzl q5ug/0cxqLEbTrB1DhiPW0rvSI086uqDTaA5U8LJr3otIXaYS8TdHLATWkT+ekrtKW4w fBPVeMyItwJbaEqXgGHZlKOEV5ybiXAEh7e9w= 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=+rvNWr8qhAwTT9uCU3yUy08DF4gzzlfFsqLWiWHL/S0=; b=Sxv8CFKuDuxTDyerpr/0nD36OdPeN6iFEzEm2Z01jdwKFA+b5j1869nNlapbJF0sHT r31cfFOOALc2OEgWGXS0V15FhuHdqdHIjku7dDzObxqqcX6KOKZqR5RaOc3fIx/s5wf2 Mi7tR6SNMV2Y0wXy19cybnIxCQTOiNJeU8NYp82zCwBE2FbLgy4zI5eK6MKZC9cJ1v8i Pps/XgDBGe+toLH1rHY22JdgtHo1Zan+/6uCObnLvkrHZwHQNyhtQLauzRM3ohu4NPD7 fpnqvUy5E8dNMZccEiyJZU1hMSrQ7LE728Jkh3XoNGoIdqq/wg+7ggqUvD4nGz4bE6DA 80CQ== X-Gm-Message-State: AJcUukftQVq837bHah35tj/3uv2BzXvJiWiWl3vHXiWg8c5kUYc9oyp+ ffZwHY5A9bLJerh/4gItvaHppQ== X-Received: by 2002:a2e:3a04:: with SMTP id h4-v6mr33510374lja.81.1546878658777; Mon, 07 Jan 2019 08:30:58 -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 b69sm12936594lfl.28.2019.01.07.08.30.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Jan 2019 08:30:57 -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 v8] regulator: gpio: Simplify probe path Date: Mon, 7 Jan 2019 17:27:45 +0100 Message-Id: <20190107162746.4444-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190107162746.4444-1-linus.walleij@linaro.org> References: <20190107162746.4444-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(). Signed-off-by: Linus Walleij --- 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 | 55 +++++++++++++----------------- 1 file changed, 23 insertions(+), 32 deletions(-) -- 2.19.2 diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 0cec163200c8..2d4459d747aa 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 = 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) @@ -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; }