From patchwork Wed Dec 5 12:47:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 152903 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp9256545ljp; Wed, 5 Dec 2018 04:48:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/WYz4q/WRgoVJ5jMpWXTKfsSmZ92+x+vVpST7543TFDG8Pm3JnI+VSuvf5gfuhUxr6VTb49 X-Received: by 2002:a17:902:850c:: with SMTP id bj12mr23657751plb.46.1544014120510; Wed, 05 Dec 2018 04:48:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544014120; cv=none; d=google.com; s=arc-20160816; b=yoygF3rKD6uMfEvZpissMwbl0h9rfMKX04uZ+Hi3omWpWpshvSvnICquso7hULEuZg fSX9a72fduX/XwCwa4mlWWA6N2wAPxZVmk0xCp8M7tnZW74CnJsb+IwMA5qWp3zZD41t 3sa1oc3OB20vNz7OjlFE/yOHdmYAhYSPAEJ9DMKVzwss+JJUV5ow//egT0nmne9qDhIO qkJSUaYZAJZVkBrdIFfMR0AAYb05/roMfXiB2K2WHTO72Z8VaNxBFDm6pB54zbTOrQaF HPgYYAqstTRRKEGM5RMaZg0MY7ZQ7UO3O4B0M5wJEKMLT3b/iojU1KqJ1w/jyBokPXrv /+3Q== 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=0XQGPplmAxsoD4Fqk/HW1LiiDkGUJY5wCq//IJHDs0c=; b=tyV8YPmGkD4oGW909je6I2zMOnnmEI0q1PBiIhZhXOrxTe8plfMAp+0chhgIpkThIk dA62YpFGsF4+w+vm+GZQ2i6gDmxL2EhFWlH1hEvqtocZvrR/xy+y6f/M18TufmraeWk1 IVHQ4lFugMBiVVDem/ix4rt04DuJ/nG/cUXV2VtTcPZIo7sDb4Ps2PUJ1IqwKzhxMKts 8tTSPK5zwf2bz+PgBiQgfDYvuzFre/2BWClbXigblRRkuP/GQSsIACjJ9YAdISYZ8PZe 5KIooZ3JzWbsamivga4BaSEld3w6dP6sIKq7dAzfG8mPYmBGtgxUNKySYYgrP3WnuJxT B37A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kfmHo1KO; 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 b4si16345958pgk.350.2018.12.05.04.48.40; Wed, 05 Dec 2018 04:48:40 -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=kfmHo1KO; 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 S1728059AbeLEMsj (ORCPT + 31 others); Wed, 5 Dec 2018 07:48:39 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:34801 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727864AbeLEMro (ORCPT ); Wed, 5 Dec 2018 07:47:44 -0500 Received: by mail-lj1-f195.google.com with SMTP id u6-v6so18207050ljd.1 for ; Wed, 05 Dec 2018 04:47:42 -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=0XQGPplmAxsoD4Fqk/HW1LiiDkGUJY5wCq//IJHDs0c=; b=kfmHo1KOzEnmzFEOh7qMnVB3y5geh2cSYRas9Pmgq/F00yi299pjmRKr4F0hBms4JA UJmId8NqwaV9zdbaPckLglKvZwfumXUP79dA6WfrmpXkWJS0Xks06+//Y8aEzDdeouRP d9UkzZdjHGQ7YyuLSc0EMKcEussauxs+s1YmQ= 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=0XQGPplmAxsoD4Fqk/HW1LiiDkGUJY5wCq//IJHDs0c=; b=qVQrgwIeEjyCbnuzBZJA5BvybJy8kWKzINwB9boAN3zGNxf1DM+mkhma1T8rjvOyba DkUdLmWfIpYRp2AS8Yl1SFKkdQ7EFecPnhEOkzCRB8aWS8xPdV1E8sVbKQNMQoSn0bg8 xORbKhliQBO6kIiUnZhP1XaNvxn+jh7EI8GAMjOYsJY0lUrTyn2sT2aMevasjchnS6Kp MAFp/C970cuOHjm8KFEs1kcGHRNB2tuPaFle60GA9Rk7uAsVXWBFR+MsPSAGL5MgCBT/ l4GEPHpeqf2YTFNWWtyU9qE1TgRjZJ/B+tPO4raZZL9TmiGbLEjwmHApgliqM0QFLqMM P5qA== X-Gm-Message-State: AA+aEWaa64lHxLs0fAu+3GVFBsSChlZl/pjjAzuWOLNjfl5zAXpcEVkf 3HWlfT5dkNdc2/UsoOcBo6ADmw== X-Received: by 2002:a2e:9d86:: with SMTP id c6-v6mr15235740ljj.146.1544014062231; Wed, 05 Dec 2018 04:47:42 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id e19-v6sm3797125ljf.67.2018.12.05.04.47.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Dec 2018 04:47:41 -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/15 v3] regulator: max8973: Let core handle GPIO descriptor Date: Wed, 5 Dec 2018 13:47:12 +0100 Message-Id: <20181205124721.26624-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181205124721.26624-1-linus.walleij@linaro.org> References: <20181205124721.26624-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 v2->v3: - Resending. 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.2 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; }