From patchwork Mon May 14 08:06:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 135675 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1439734lji; Mon, 14 May 2018 01:07:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr48oeNStVK8KUI5caT94W+Is8KGCP5qa6RSEr4Qi6i0iu6yyME+77UYdhMwfmuGSLNARGA X-Received: by 2002:a62:18d6:: with SMTP id 205-v6mr9396141pfy.242.1526285262158; Mon, 14 May 2018 01:07:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526285262; cv=none; d=google.com; s=arc-20160816; b=vMd7fPU4eLZu7g9S77lZbqdwt5LVGW/vjxMQquv2FBdhsu+lkmSXksBdqN8wfa58ad 4+ZWeTwhUWgoQb5J2xxpSe4d5y6kS/Gr4tY6/RIAkFCXGPm6xehrOZ4kGDe/lqze1eVF ium16AHXxwuGDMOW1Pv5OJb9gIKNR5B5XLdlZ3yIllYB1H13ADpnpsm7a98MvHnd4Mj8 qfAi2CsfhXKkOXgFzpqNtUS5iwa+8oLgUzRLLFPggg/ULMgBWVR8+1UYr3FhzJUHb2uv 6Ms+y1T/B5csntrCB39/0xnxHf9f36bMtlN8D6x1x5Td468BbzDKrcYtXS/eAJocvIlH uhrA== 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=w5DFBrZwEmLY1hlKVjmpTyntGWY4PBnErlDD98AIvv8=; b=fUPWlD2tKRflZUjf+eDeIYD9inPQUboxl16ScGaSGYiYUAcclVLpdZMCyWV7Rwt3Ba +rIqw0+xq5y41lYpipF89aRcmo/EiVNHb6CZ4HFaQJZWAIvXyYYh70jL2l+Ll8L2CT9S xCSjzJWzxRUbjKxmr8PfHcTN0Cmkdn7n2FAT7AeT2sF4ZCfjpo8vtboDZbHNf39OicH/ vMPjItJ2v5sQfksoowTekhD7ASD89dZ40YBds5iYgsrQHTp+gVuPvurTRx4d0YrVRoRP YqrPJX1qXNB/S8JHoGpfoOlexKYaqXs0V7y3slpUTSDHszD0T4X/RC9jnjPGB5ADGeGJ rbVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IrjPIKxn; 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 b8-v6si2014958ple.469.2018.05.14.01.07.41; Mon, 14 May 2018 01:07:42 -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=IrjPIKxn; 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 S1752096AbeENIHh (ORCPT + 29 others); Mon, 14 May 2018 04:07:37 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:42441 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752369AbeENIHb (ORCPT ); Mon, 14 May 2018 04:07:31 -0400 Received: by mail-lf0-f67.google.com with SMTP id b18-v6so15834156lfa.9 for ; Mon, 14 May 2018 01:07: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=w5DFBrZwEmLY1hlKVjmpTyntGWY4PBnErlDD98AIvv8=; b=IrjPIKxno1C4V9s/FbMoWG+ngHSpjYnrhuLOAZtXo7EBejZey1ioqtyuvLCD0pMnlM a3Qg5gFbqaG0kCVRo83bCjeu+Bo797x6XgzjxiGPma6PB+CdRCQOVq5oITGgtvfdXgc0 4r5oepTgnHw5/KJxTSTCtZE2N/PHvNjeoEFUw= 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=w5DFBrZwEmLY1hlKVjmpTyntGWY4PBnErlDD98AIvv8=; b=tCDQvD0AFCOui+nN08JcN6ZpUDbcvHTct0/hf7UQoOs75uWZS7TT0s8w99gEiopGQ6 KCXdfehUooTbKRYPY9wfsS6NEAAHyBtQe8oGHhpbvss8n7YGTmpEiFkpCgDJpplLtkk5 FW2ufhV/aAVnj3EwRMj6RzCx5SzHX+pWcQVJbK61N7Sp6o7nflboaOAI0AFPmZrxfjI3 AePuUv0/Rp+gdN1H7f3mnpATqodS6J2m72QtX53A6llBM/i+MuY3xyJAkd/JDmQqp3Z8 gvJ2FlAUUgXZckwFvCtHRb89vQFEOwv6NYHvaKtKgBDwNR9XCGZWSTjum3AvacPjIr0U iC7A== X-Gm-Message-State: ALKqPwdfCNG8DJrIDcaDuU/eH8MJw7xlFmmEWXC3ZdtQ4TN1SoxXUR2/ AamV6ZIbXt4qfijCo6sUNpIGrA== X-Received: by 2002:a2e:9f56:: with SMTP id v22-v6mr3829735ljk.42.1526285249889; Mon, 14 May 2018 01:07:29 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id s4-v6sm1725265ljh.9.2018.05.14.01.07.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 May 2018 01:07:28 -0700 (PDT) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij Subject: [PATCH 18/19 v3] regulator: gpio: Simplify probe path Date: Mon, 14 May 2018 10:06:39 +0200 Message-Id: <20180514080640.12515-19-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514080640.12515-1-linus.walleij@linaro.org> References: <20180514080640.12515-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 v2->v3: - Resending. ChangeLog v1->v2: - Rebase the patch on the other changes. --- drivers/regulator/gpio-regulator.c | 56 ++++++++++++------------------ 1 file changed, 23 insertions(+), 33 deletions(-) -- 2.17.0 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; }