From patchwork Thu Nov 22 16:04:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 151801 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp929488ljp; Thu, 22 Nov 2018 08:06:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/XTuyXe2XG1+4SZirgp9pCKvqOcgxbf+W3MwXRzjkvH2woePvExLTSmPhGMx3EIw8FYefbm X-Received: by 2002:a17:902:9047:: with SMTP id w7mr11944425plz.270.1542902793202; Thu, 22 Nov 2018 08:06:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542902793; cv=none; d=google.com; s=arc-20160816; b=DUyrXElU1/1MgOHlN0akt03K0vbNvKkYwDmyzMvVFc9dmwAc00P6mfE2f1tSX+oHOm hsXXmo54bg+lRIaWfldhiJMiiXCsMLMFA8U8byFOhAF8GKQYIm0AGhsZ04AeMoosDKfs tyrwsGM8SZnDRWC+tg43/xBiCMhXLWjtnQEfOqmN8o2E9jREGUxkzmW4olg+tRvyE2wk al/V7aKEJjAa1L+5uGIp9gI2REDktl3gl1oYCwLWuEGoxCtNoPznwlgJpudg/TBYWhYv QUMDtZDdlS60w53/w2n3xQ45Sga97qChrwVJX/rwV3aqXaEf1Cn+GXF8ficrLoOI+C/w PJhg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=+nuwurduJbbd/l3+2ThhClajDsChdjDwF/WBDQ2w50A=; b=fw9JykrKlkni8/7wrKcPqSP2okjKfOqyUzemA4zHrUaoIo3aQGr58C0cimPylMMyV9 QpFcSPk/+RVEqis6GkwK3qQ5wlj1Ikmd0qWxj6I97BvkkxIMZCKaRuZkXdvXzxth3UTX z8wMcxaACZWQesWP0/FjfdCorcyuRPYLBOaKF89NSwdxazr+htm1Jf5eU4k4gu9MI4k8 MEFw11OONVUMG8zK+zFpGUV8kQWHQOA/nXreeq5i/JYvAAYlydqjMKXym44xzvmuMWEx ++7jIHq+LCf/kEuiGqReMvbly4q/qkh5L6bIc5z8nEXUrNDqLpq7wWNYrvAZ02PNREYR ux8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DLOyFMMK; 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 197si43547597pgb.564.2018.11.22.08.06.32; Thu, 22 Nov 2018 08:06:33 -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=DLOyFMMK; 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 S2438090AbeKWCqa (ORCPT + 32 others); Thu, 22 Nov 2018 21:46:30 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:43497 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729773AbeKWCq3 (ORCPT ); Thu, 22 Nov 2018 21:46:29 -0500 Received: by mail-lj1-f195.google.com with SMTP id 83-v6so8369869ljf.10 for ; Thu, 22 Nov 2018 08:06:29 -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:mime-version :content-transfer-encoding; bh=+nuwurduJbbd/l3+2ThhClajDsChdjDwF/WBDQ2w50A=; b=DLOyFMMKM+xm9ePOIPlh8WA3oN+vCgl2gcIMl8YEt2YyVHzlhTRskoMbgdFvYSCY3+ OP3Vw01t82y754wH6gMqMgrGTGIcuEZVjoszV1o2DpclsKoLchE1q5mleTKBJEcngsOi QcPEvRzG4fq32scnW8OKMYYnE718kYhpi+sys= 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:mime-version :content-transfer-encoding; bh=+nuwurduJbbd/l3+2ThhClajDsChdjDwF/WBDQ2w50A=; b=dOmxQoHi+JEL0FZRFTsKuXR3DA53saoOyQhJj22MtBpzbUyLiEwHNa3Iy6BPglnAbE vuKGYT9M2/w8q8koM/PWB2xgAty4agTrEQZ2EsCI4vt+CRMgXB7pzD4FVpxkpwUs0Zo+ RSl3ZUkGS3FQFXlDz28oGgZ3KMqHdUZlMjj3RSBRgLIn3Bysxb9XnmL/sjHD9TwpODFY xFfE2h9dJuYDJP5raIeuSySfIyI7dRr70dRCpMlVbLCYCfSxC2qMB9e3CXGI6rX8w8d4 27odf47zdGecorVggjiv0PlBOlFx9qHUWe8E8bz01VijZ853sCgqkvFqoDJSM8pSX1KW onQg== X-Gm-Message-State: AGRZ1gJ24uC92zneBf71ifji1+KDJ4Q2iI5ISAfw+LnGUQxMX5jKk2dn 0kh3lAIpEi6+tTpXkqpMgdTxEA== X-Received: by 2002:a2e:9181:: with SMTP id f1-v6mr7241532ljg.64.1542902788919; Thu, 22 Nov 2018 08:06:28 -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 r27-v6sm7561035lja.65.2018.11.22.08.06.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Nov 2018 08:06:27 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij , Marek Szyprowski , Charles Keepax Subject: [PATCH] regulator: core: do not put managed GPIOd:s Date: Thu, 22 Nov 2018 17:04:21 +0100 Message-Id: <20181122160421.9658-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some drivers have been converted to pass GPIO descriptors rather than GPIO numbers to the regulator core. We should not issue gpiod_put() on those descriptors, but rather let the driver reference count it with devm_* if they so desire. Currently the regulator core issues gpiod_put() on all descriptors as it assumes it was obtained with the sequence gpio_request_one()/gpio_to_desc(), as gpio_request_one() will be equivalent to gpiod_get(). We introduce a helper bool that deal with this situation by making sure the core only issue gpiod_put() if the GPIO was requested from within the core itself. A subsequent patch set will delete legacy GPIO handling and get rid of this ugliness, so it is a stepgap patch. Fixes: e45e290a882e ("regulator: core: Support passing an initialized GPIO enable descriptor") Cc: Marek Szyprowski Cc: Charles Keepax Reported-by: Marek Szyprowski Reported-by: Charles Keepax Signed-off-by: Linus Walleij --- Mark: I will rebase my v7 series for removing legacy GPIO on this if it solves Marek's probel, it can be applied for fixes if need be but I don't know how big this problem is. --- drivers/regulator/core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.19.1 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 03a03763457c..05bb2db6cff5 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -80,6 +80,7 @@ struct regulator_map { struct regulator_enable_gpio { struct list_head list; struct gpio_desc *gpiod; + bool gpiod_needs_put; u32 enable_count; /* a number of enabled shared GPIO */ u32 request_count; /* a number of requested shared GPIO */ unsigned int ena_gpio_invert:1; @@ -2247,6 +2248,8 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev, } pin->gpiod = gpiod; + if (!config->ena_gpiod) + pin->gpiod_needs_put = true; pin->ena_gpio_invert = config->ena_gpio_invert; list_add(&pin->list, ®ulator_ena_gpio_list); @@ -2268,7 +2271,8 @@ static void regulator_ena_gpio_free(struct regulator_dev *rdev) if (pin->gpiod == rdev->ena_pin->gpiod) { if (pin->request_count <= 1) { pin->request_count = 0; - gpiod_put(pin->gpiod); + if (pin->gpiod_needs_put) + gpiod_put(pin->gpiod); list_del(&pin->list); kfree(pin); rdev->ena_pin = NULL;