From patchwork Sat Dec 1 15:41:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 152638 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4934539ljp; Sat, 1 Dec 2018 07:53:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wr21Iu7883N2mUhWXnFV59myEod763koov8e1j7t/fCaMSU2hU3csFvYrBryPfwzqAn2/1 X-Received: by 2002:a63:9a09:: with SMTP id o9mr7902463pge.94.1543679602096; Sat, 01 Dec 2018 07:53:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543679602; cv=none; d=google.com; s=arc-20160816; b=QTkSXeDwOvPYFm5L1SLps/VajphhN/JrHz166Y2CH4wvoJKPR84rvLn2wy9ULHD+jO pM89/lGAHs1/j7y6pNJoXDL2EKTfShpZqHM74Ryq5jUEKemZkEVswGTb3L7NaoS/vjqY UL0866lQNVzWmxqDzrsGnsLyaC0yFEgaYSV08JqJNJVySEzOv4QoKy1kBL6pqU0PaZn5 dOJ3pVc9TXj+6OTE8Mdf3Yu5wGz9+PiSzE+dRvR3O/OmdSJBEyBd43tnrh+ITzIfCo8L QQ0YxrDNDOsBFw9jb9z0gt7ZuoScsTrSYJliCwj4CUiQzCHc2Vwq/cUJl5dS5xSjwPIN UPxQ== 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=BjCRleG8di9Pc2Z7GsEkzTD2w0QLemG0losOcCHuzcc=; b=RYtKkElpc44wa3zN0wpnk+qi2Ssb5wBROB2i2iHXlrPHqssKcrMQ+Wj/4IZFqU9C8v +xbkK6Cj0DAFegKpo3gHjOO/OWp4Qkzik6wUJ9kZJZSda0mboYMmR6vHORD6CFD8fnQO pn98TXuuPGKvcJHAjLD/HFKCAunQURbJd1vngbW+0eMeyyHiEqMS7bqRzkOxWt9Ks2CY k43NnQnDSCwmZJNgQubZeqLz2i4t1CJ3W6Hc+yFvt8N/qROYGDhbuaI6yiih/AHXX8JC uV61iMBPmUrBpdp7MV8rZz+6W3A7Thev4DTQC40niAEoQ3kZB2nqAym2czUbCEhtUN07 s0Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="cgrekM/Q"; 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 g33si7806409pgm.426.2018.12.01.07.53.21; Sat, 01 Dec 2018 07:53:22 -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="cgrekM/Q"; 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 S1727323AbeLBDGI (ORCPT + 32 others); Sat, 1 Dec 2018 22:06:08 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:33815 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727267AbeLBDGF (ORCPT ); Sat, 1 Dec 2018 22:06:05 -0500 Received: by mail-lj1-f195.google.com with SMTP id u6-v6so7649839ljd.1 for ; Sat, 01 Dec 2018 07:53: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=BjCRleG8di9Pc2Z7GsEkzTD2w0QLemG0losOcCHuzcc=; b=cgrekM/QsorFtbcUaVHMmtDLtCS1sWSFypoqEELuUVtiCLgK3yXWHP2AACh+0+eaRN cY40+f0uc107IPDbonPK8eAXiTxQ7escPATii4qaLB5RXljzRmBI/xHKfhdnwxC1ROfV t1ipStUXE+8RupmAynDtcqzPzynWEiv9D6rfk= 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=BjCRleG8di9Pc2Z7GsEkzTD2w0QLemG0losOcCHuzcc=; b=e4PBqhqAAo+Fl8PSfebpMXqVKrHKAJ8PDyko1EDE/otEB34bQg2VRlz5IBNcHPoMA0 RneUXg8RGklO43g1JL8IVbYDbFld71eePlU5SriMt5jp7uMc5iO8ckAsXwLUgMXik9oM KAQFtxw7AlTu87h1sjeVkBCxGj3wRkCkbDLo4K0IMENoehnyvRo1zBAQFUCm+C+E4kwH +4RALzdOk+14K+L2zmjSTgfJ3d6eytzDMGOjjJv4bcMGomkLer9b79g2GPwh8kWki5hz a/LARQeZg13yiTgYWSFtHFLT3zFME5zTVA2i2ROrP84gFutYn00k0s0Tw6amPDcKULNO p54A== X-Gm-Message-State: AA+aEWYdMe+QriDdAM5VBccHWiqaYIAAO58vf7351DyIa85k38VTT7dP B5NHGPHnA9Wy1HhJbcxeXJBpYA== X-Received: by 2002:a2e:917:: with SMTP id 23-v6mr6038978ljj.1.1543679594169; Sat, 01 Dec 2018 07:53:14 -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 13-v6sm1365426ljj.49.2018.12.01.07.53.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Dec 2018 07:53:13 -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 06/13 v2] regulator: max8973: Let core handle GPIO descriptor Date: Sat, 1 Dec 2018 16:41:44 +0100 Message-Id: <20181201154151.14890-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181201154151.14890-1-linus.walleij@linaro.org> References: <20181201154151.14890-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() rather than the devm_* version so that the regulator core can handle the lifecycle of these descriptors. Fixes: e7d2be696faa ("regulator: max8973: Pass descriptor instead of GPIO number") Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Drop the gpiod_put() on the errorpath after devm_regulator_register() as this will be handled by the regulator core. - Fix the second case of devm_gpiod_get() - Put a comment in the code so maintainers knows not to use managed resources (devm*) --- drivers/regulator/max8973-regulator.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) -- 2.19.1 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c index e7a58b509032..ef8f4789a517 100644 --- a/drivers/regulator/max8973-regulator.c +++ b/drivers/regulator/max8973-regulator.c @@ -632,7 +632,7 @@ static int max8973_probe(struct i2c_client *client, struct max8973_chip *max; bool pdata_from_dt = false; unsigned int chip_id; - struct gpio_desc *gpiod; + struct gpio_desc *gpiod = NULL; enum gpiod_flags gflags; int ret; @@ -759,9 +759,13 @@ static int max8973_probe(struct i2c_client *client, else gflags = GPIOD_OUT_LOW; gflags |= GPIOD_FLAGS_BIT_NONEXCLUSIVE; - gpiod = devm_gpiod_get_optional(&client->dev, - "maxim,enable", - gflags); + /* + * Do not use devm* here: the regulator core takes over the + * lifecycle management of the GPIO descriptor. + */ + gpiod = gpiod_get_optional(&client->dev, + "maxim,enable", + gflags); if (IS_ERR(gpiod)) return PTR_ERR(gpiod); if (gpiod) { @@ -775,10 +779,13 @@ static int max8973_probe(struct i2c_client *client, /* * We do not let the core switch this regulator on/off, * we just leave it on. + * + * Do not use devm* here: the regulator core takes over the + * lifecycle management of the GPIO descriptor. */ - gpiod = devm_gpiod_get_optional(&client->dev, - "maxim,enable", - GPIOD_OUT_HIGH); + gpiod = gpiod_get_optional(&client->dev, + "maxim,enable", + GPIOD_OUT_HIGH); if (IS_ERR(gpiod)) return PTR_ERR(gpiod); if (gpiod) @@ -798,6 +805,8 @@ static int max8973_probe(struct i2c_client *client, ret = max8973_init_dcdc(max, pdata); if (ret < 0) { + if (gpiod) + gpiod_put(gpiod); dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret); return ret; }