From patchwork Wed Nov 28 10:43:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 152247 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp923686ljp; Wed, 28 Nov 2018 02:44:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/WC0SJF+MMIF6lunPo5tuUvwKjisTU6trp+XCb+ZA/g2bgCKEcI7QmIoG2XZE4hbHiyBMPG X-Received: by 2002:a63:9809:: with SMTP id q9mr32731864pgd.109.1543401859621; Wed, 28 Nov 2018 02:44:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543401859; cv=none; d=google.com; s=arc-20160816; b=kioDM1W+R4qzjyr8mKGiDN+ibS1SuCXJv9m25TVZrWIqptJSpGyfzq/FckXRAKDGCU /YEb/bQW4vLnc0W8MT+ZIvZvR5t/AkDar0dzc2amMH8CrkR8s76U6NfRYysLhXTtSwaz u0Ck6ibIQZ5w8HWNy6NkVc9nYvU8M3oewGroDNoQJjQoItewbkwlXsO9p1zLQUq0xxyA /zl+5jsJQ1+QyipXdO2hKOa6Cg/eB9XYTlCnYqFCwHX6EKyIHWSSIHehpbogpAF/Q9B8 02BwAmQzlzw+jp/GQmF6CCdKc0fjuAeW6HYvn/N7CnQ0VpeSDQJUYZQE/+p8kaix5K+F 1kmg== 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=NYiM9hsLAwjDtY6nnK0M2ohtbKlx4iqaNDXUO8IxYxE=; b=PMLMNfYcZ2gRWJcyLjAygqbe783NP6NxIkHd+Q8if+2IKpLOi8MplKJheBdL/urS9p 4m56nqKJUBrHLSvMrHPG1CBWvEZA/0+Hprh4Wx5UpqROmVcJviLkJMgl7bP5h2adqC7T YXef6fspcYJgXg4RDciTXjPm7Uvq62xNav/XIDilyiyXEg8gLlXC5vzJVNO9fCnIN2fX TFgpYao2d68P9LoNiYl68cj9we5UXtCqMcMb+vGAZ4tHm+W5fh9YV43HrJVgLPKEW7Ty RJBq0Xi8Qe21ysFA4IqZU0WiL5CIStYvTEj7nMuofGJK/m4f9s+2jv64L3WPPMv7QpiM nbZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HcJP4fbq; 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 k11si6837725pgh.132.2018.11.28.02.44.19; Wed, 28 Nov 2018 02:44:19 -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=HcJP4fbq; 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 S1728352AbeK1Vpa (ORCPT + 32 others); Wed, 28 Nov 2018 16:45:30 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:37004 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728300AbeK1Vp3 (ORCPT ); Wed, 28 Nov 2018 16:45:29 -0500 Received: by mail-lf1-f68.google.com with SMTP id p17so18978934lfh.4 for ; Wed, 28 Nov 2018 02:44:15 -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=NYiM9hsLAwjDtY6nnK0M2ohtbKlx4iqaNDXUO8IxYxE=; b=HcJP4fbq2N7Qxt3f1FdI/Sjnzz0LP4Hb4PYty22w1YFJE2KjFeuXaUte5yhiURHTU1 hNgOrbejD9xUDBvEfN1F6XmphAvXPGJxyeMzg4fYKkxod9pUE5fT/GL4JGg8++HEGBex 4ldFonVtUGGgQUye+6Uw47YHDdpj0UajWw4dU= 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=NYiM9hsLAwjDtY6nnK0M2ohtbKlx4iqaNDXUO8IxYxE=; b=LUHfL2Feqpe4O4BHTwLr7wIwGzQjUgpdUSBwk/7bktbDHECQV/YuHF4/eif4UCpTSu GnLd/oPQfNf5GaYAU8o4auxXsLYbyv4N6hG9YHZwSA3BkX7GVuj/v2Uh86ZJpGeIC5Es PSNg1NYVsrPNzvaVEewohJPKq5RMl1oGB6Su663oTlnNalZtVFKE52tbVbRq0eTftTey 76klYm+wGnAOpyiFA5wsuqVlUQi5dfbJp9kY6AJxP9rps3kP2/PE7SlpZJdKXrcwGNkP E+vhc7rWMwIvd4L3NBiB09Et+IQd0xgbLhK1WvDYe14WxIAVl6U/u8CKQI+JhjYeg/91 cEhw== X-Gm-Message-State: AGRZ1gIOwMx2rJU+FBzvBCdR9TPXFcVBg15Xhx812J8MA0146UoD5Frm FxB/wPjcf6nvP2Q+uHmj/Zr6tYp4/FuPFg== X-Received: by 2002:a19:94d5:: with SMTP id o82mr19908179lfk.155.1543401854599; Wed, 28 Nov 2018 02:44:14 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id c20sm1095101lfj.67.2018.11.28.02.44.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Nov 2018 02:44:13 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Charles Keepax , Bartosz Golaszewski , Linus Walleij Subject: [PATCH 09/10] regulator: s5m8767: Let core handle GPIO descriptors Date: Wed, 28 Nov 2018 11:43:49 +0100 Message-Id: <20181128104350.31902-10-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181128104350.31902-1-linus.walleij@linaro.org> References: <20181128104350.31902-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 the gpiod_get_from_of_node() rather than the devm_* version so that the regulator core can handle the lifecycle of these descriptors. Introduce an errorpath so we free any retrieved descriptors properly. This patch requires "gpio: Export gpiod_get_from_of_node()" to be applied first. Fixes: 9ae5cc75ceaa ("regulator: s5m8767: Pass descriptor instead of GPIO number") Signed-off-by: Linus Walleij --- drivers/regulator/s5m8767.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) -- 2.19.1 diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 219b9afda0cb..2d8f6cd4f142 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -528,7 +528,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, struct device_node *pmic_np, *regulators_np, *reg_np; struct sec_regulator_data *rdata; struct sec_opmode_data *rmode; - unsigned int i, dvs_voltage_nr = 8, ret; + unsigned int i, j, dvs_voltage_nr = 8, ret; pmic_np = iodev->dev->of_node; if (!pmic_np) { @@ -559,6 +559,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, pdata->regulators = rdata; pdata->opmode = rmode; + j = 0; /* Keeps track of populated elements for errorpath */ for_each_child_of_node(regulators_np, reg_np) { for (i = 0; i < ARRAY_SIZE(regulators); i++) if (!of_node_cmp(reg_np->name, regulators[i].name)) @@ -571,9 +572,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, continue; } - rdata->ext_control_gpiod = devm_gpiod_get_from_of_node( - &pdev->dev, - reg_np, + rdata->ext_control_gpiod = gpiod_get_from_of_node(reg_np, "s5m8767,pmic-ext-control-gpios", 0, GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE, @@ -597,6 +596,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, rmode->mode = S5M8767_OPMODE_NORMAL_MODE; } rmode++; + j++; } of_node_put(regulators_np); @@ -608,7 +608,8 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, "s5m8767,pmic-buck2-dvs-voltage", pdata->buck2_voltage, dvs_voltage_nr)) { dev_err(iodev->dev, "buck2 voltages not specified\n"); - return -EINVAL; + ret = -EINVAL; + goto err_gpiod_put; } } @@ -619,7 +620,8 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, "s5m8767,pmic-buck3-dvs-voltage", pdata->buck3_voltage, dvs_voltage_nr)) { dev_err(iodev->dev, "buck3 voltages not specified\n"); - return -EINVAL; + ret = -EINVAL; + goto err_gpiod_put; } } @@ -630,15 +632,18 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, "s5m8767,pmic-buck4-dvs-voltage", pdata->buck4_voltage, dvs_voltage_nr)) { dev_err(iodev->dev, "buck4 voltages not specified\n"); - return -EINVAL; + ret = -EINVAL; + goto err_gpiod_put; } } if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) { ret = s5m8767_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np); - if (ret) - return -EINVAL; + if (ret) { + ret = -EINVAL; + goto err_gpiod_put; + } if (of_property_read_u32(pmic_np, "s5m8767,pmic-buck-default-dvs-idx", @@ -654,8 +659,10 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, } ret = s5m8767_pmic_dt_parse_ds_gpio(iodev, pdata, pmic_np); - if (ret) - return -EINVAL; + if (ret) { + ret = -EINVAL; + goto err_gpiod_put; + } if (of_get_property(pmic_np, "s5m8767,pmic-buck2-ramp-enable", NULL)) pdata->buck2_ramp_enable = true; @@ -674,6 +681,14 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, } return 0; + +err_gpiod_put: + while (j) { + gpiod_put(rdata->ext_control_gpiod); + rdata--; + j--; + } + return ret; } #else static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,