From patchwork Mon Feb 12 13:17:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 128066 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3201604ljc; Mon, 12 Feb 2018 05:18:36 -0800 (PST) X-Google-Smtp-Source: AH8x225//em035tUTEURgqffVdZpssbImR+Hu7Ew4MADa6S9TWAI9bpDOGFhVvh/lBkLaDms4DrE X-Received: by 2002:a17:902:34e:: with SMTP id 72-v6mr1416972pld.277.1518441516271; Mon, 12 Feb 2018 05:18:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518441516; cv=none; d=google.com; s=arc-20160816; b=ZiIYu862CoFeUOTQ4eS7gbjGykyueEFJznyMArJSnnRgtBMfJ4r7vbYeH1mwLVqXOn jNjckj//cce63PcUQ0+EEGp9H9zH/T3RU8aTTidRuDaOefNdEyZA0XfPpG96Dls/q1TC feoFxMojtt5okuUhxEEbU5kgO9XOaj5veKCL3wnY11G+7ZhpgHIPDBsyDCEaM1hTfWQe 1H0KCQ+1EuTAbF1CLXcs1ZfS9OF25VInX7lKuFAIEPbQAMJiVP04KVY1Suz+jlbzlgac I9YMaaGKGvhOdeZIF2yByb/KUrduzt0LmAMNeWYTAaI2wCgvw48Xr+74A0CO5jGxOga4 DvZA== 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=12wbP2PkUK9SWwXUn7ItipXduToiJIVpyn+lgGw7hjg=; b=SPKp7NshwSBgDayNEHE19UVir2bd35Flbqblz6DXsH2njoQ5cC8FtfhHtGjpxddSfx C3Syx4xPOQpShEo52xfUAVnMKi1ayg+14mKxhEGuWCoO+bVSwpNUuCGNSsHNLgmGTGpF 00s/4NwI24Ae2gW8HO8N9ionjBjwdYah8DIj14QBQg+P95zLJUEjftU0xEc0X2zVJkbz 5mo5mdiFamrSposROJQtq9/XQzDIDAu1tJOjow0SWIJtOcnuehDkODNHPQqiPil07fs+ U/32hKFS7cOdYdBvPr4erIsHtTFbcB+C0rnudhwqf/jt/o6a+QVFBZM56PDUxWSeqCZU 8OFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VAWn1/vE; 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 n6-v6si1217488pla.619.2018.02.12.05.18.36; Mon, 12 Feb 2018 05:18:36 -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=VAWn1/vE; 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 S935379AbeBLNSc (ORCPT + 13 others); Mon, 12 Feb 2018 08:18:32 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:43145 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935350AbeBLNSP (ORCPT ); Mon, 12 Feb 2018 08:18:15 -0500 Received: by mail-lf0-f66.google.com with SMTP id q69so2535771lfi.10 for ; Mon, 12 Feb 2018 05:18:14 -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=12wbP2PkUK9SWwXUn7ItipXduToiJIVpyn+lgGw7hjg=; b=VAWn1/vEusqwPWnTbQBmjcBqkEqqP3GOz5dgGqLx57v4JvJkVOLFeYZDf81Zf11K/L AOLJ0Huf+iSbmZayBQD32ZMRVgbxPfQRVTLWw6qJIbhAnt54bnMG4P3UFdFE0vfS9WkB qc0ANznd1Rvq3EoaX5IsQRp6pndqFNB/PFQh8= 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=12wbP2PkUK9SWwXUn7ItipXduToiJIVpyn+lgGw7hjg=; b=Bkpj6fSglydBmYVgQdwvxECvT09aPuL0VNTwuYa+ANvtk2BPfYT9bffyKwWTqaUJkx 3lBk3vl58g6mom0+dgrS4lHvMmeIhzbiMQhtWkeq/QF1CWlmHRKgFW3bokoGmRkr4Fhs 2Oo0zKZ1TZTVAsyCc3k4tt3yPIEnv63fDHctmY6vOZ2FDO9EaDECvLpFglC8IFisn9H7 cemSteNTozF8u1p4lNFTVpyLIxx6dqUUEPfreHsS5ZnpKPxlJMr/IXqrUj8s8IPpmUz0 U4wBPA8cMqIu8mUusYK77za9khGSDU+K7unkAz5CvyorS8hHfvJ4yHlLnAxdspGjO2pJ Jl1w== X-Gm-Message-State: APf1xPBDEHAQcMFmU0u6J4glqERZ8qESrUJuyZj/QyGlnxzlYqpPcugv YMrOA0Nmc+aFISFcP9imxK/Uag== X-Received: by 10.46.17.208 with SMTP id 77mr5253371ljr.87.1518441493852; Mon, 12 Feb 2018 05:18:13 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r88sm1584648lje.30.2018.02.12.05.18.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Feb 2018 05:18:13 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Linus Walleij Subject: [PATCH 21/21] regulator: gpio: Simplify probe path Date: Mon, 12 Feb 2018 14:17:17 +0100 Message-Id: <20180212131717.27193-22-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180212131717.27193-1-linus.walleij@linaro.org> References: <20180212131717.27193-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 --- drivers/regulator/gpio-regulator.c | 60 +++++++++++++++----------------------- 1 file changed, 24 insertions(+), 36 deletions(-) -- 2.14.3 diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index aecdd3f211ba..38a283252aaf 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, NULL, i, config->gflags[i]); @@ -257,21 +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"); - ret = -ENOMEM; - goto err; + 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; @@ -290,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. */ @@ -303,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; @@ -317,29 +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); -err: - return ret; } static int gpio_regulator_remove(struct platform_device *pdev) @@ -347,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; }