Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6053533imu; Sun, 2 Dec 2018 09:03:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/ULvSstx5dfRqVBbgE3dkQHIre7v3Tjz5URbBc0z6OVvv+KTUx1NmGS0Ytfx6fNGjmzT+3U X-Received: by 2002:a63:5c22:: with SMTP id q34mr10701143pgb.417.1543770234178; Sun, 02 Dec 2018 09:03:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543770234; cv=none; d=google.com; s=arc-20160816; b=WE1EeaEdUpMk2txiEGYLkOCCvCibGRP0uhofbv44eJKlwslYnj0+bC1pA77oQT+zrB eFsN5eiMSSV4ssj6wOXAGDzoCcVbPpP7ifRpOVxm1ruyXXyiTkF8wHUmb5R91wM93oJq GZASqJ0jybDhwwWZhOREkXazhHrUCQOWIoY9AZUXxi8WpiuHTz8G6XS7UhPuvExAJkpY SvAM4xGKojKIG2sz6VaZsguCnrQvQc2J8MNiekG6Xw7aoZbruGSG8ykJvddg8Nqo65OS UdjRJ/rSK+fvedOvTImNCzOdBoWUl/TKHYcr/C32tS24xV68o5CJlr4mVExXfqfMJeHG 7uZA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=00HLrtqm8W1r9ik78WiiDuK7C6SV9SWCZPAJkFAh0Dk=; b=rImLASgcgk8wu2QsEtJAbrxiEXAzCbc7oK9tqqqGldyvcgvvR6gUnk6pa8O4juXut5 ylju4ctJxJhtGx+o832cKsoemfiyC3/AiUDqY6DU76xtK/dZg3zi5FDt8ygztnEVd6zH yIYhk98Pu6KpP0Wa186uUaR+arMkcDho0bRXyUVvz5KN1VFqAFc0NqI23sKqltWC3AOm ewUA3QQRbTNibkcJS8O103IDfUmlZ4pigtp8j6cHwihsjJp0cQIEA63xaP4zM7bccNwB UMRdRSmSrOF4r5WTLuBmJW6pPdHXV6zf2UY/qrKq156dfADEEJgwnY87024OIvTIllb9 EWBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="Xb/E+0Cm"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 69si8984207pgd.290.2018.12.02.09.03.38; Sun, 02 Dec 2018 09:03:54 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="Xb/E+0Cm"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725764AbeLBRC4 (ORCPT + 99 others); Sun, 2 Dec 2018 12:02:56 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:46457 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725379AbeLBRC4 (ORCPT ); Sun, 2 Dec 2018 12:02:56 -0500 Received: by mail-ot1-f68.google.com with SMTP id w25so9457462otm.13 for ; Sun, 02 Dec 2018 09:02:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=00HLrtqm8W1r9ik78WiiDuK7C6SV9SWCZPAJkFAh0Dk=; b=Xb/E+0Cm9MxD0kpZ7MXIgeC5mh8I5f3m+iCRR2jhqDDme+7mcRpx0SR3fa2/xJmbxq rMreYrDh1KQWKBp5oJg8Q/LhbkgeNWjcSlj4DIPQpsddv9YJwx9R9VAt3ByTJXneOLMz hD1yFnVhR9galQAyMJo7L12n65TY3CQRNv3emSdVdCPh+SMjQNVUZdR1GSUH8xaacMG9 UfDgMhTlj/gd+DHCZJMwrsET/IvNMCOYBnZ65QttMd53GGmx5f/tmrwiksQJFBxEl+4K KbQnyCwCtCXzwyzCJdZwhcZdkrj8FjVxmFihyiL7U+7CGbO8x0ga7PVZujpdXQC1WNiX JpwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=00HLrtqm8W1r9ik78WiiDuK7C6SV9SWCZPAJkFAh0Dk=; b=BB9EJPgEuod0llSvAfvmi8GMlYWCSo9xCDNnafk5wdj3LSITRNr3P9zcZO/uyLMU6a u/M0GlrgTjrwo4neErDuDh+05pvJIZO9YFUNge5Ujt4YW9XRjDElL+fzRNd5uF8Q6dig LjrKXvc7E1mxcfWEeZ2clkGrn+j13yx5rqEili1tuuaqGw3ldHsUoZpY6vOrUerDzGXF UALu0UkctNs9R8UvPeNZlgGDB5r4AyjCf6597zm4bcVwwC5YgNi1SSbm9OvJ2uoXCmTA DIwuPL4Wz0yMCtRbITSwBpbdppDc6zNoLFeCyASHsyQX1Xk91sS8ynlxgN1IJeI5RHOR JZHA== X-Gm-Message-State: AA+aEWYpa/SQeqK8TQtVMWwF/dlrx0dSivBJx1e7z2DkPzK0KtytXz8Y khX5XVwtHfzo8f0S74OpQ3NC3EaRNZOefZJZRzSWeQ== X-Received: by 2002:a9d:4595:: with SMTP id x21mr8022866ote.234.1543770173456; Sun, 02 Dec 2018 09:02:53 -0800 (PST) MIME-Version: 1.0 References: <20181201154151.14890-1-linus.walleij@linaro.org> <20181201154151.14890-10-linus.walleij@linaro.org> In-Reply-To: <20181201154151.14890-10-linus.walleij@linaro.org> From: Bartosz Golaszewski Date: Sun, 2 Dec 2018 18:02:42 +0100 Message-ID: Subject: Re: [PATCH 09/13 v2] gpio: Add devm_gpiod_unhinge() To: Linus Walleij Cc: Liam Girdwood , Mark Brown , LKML , ckeepax@opensource.cirrus.com, m.szyprowski@samsung.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org sob., 1 gru 2018 o 16:53 Linus Walleij napisa=C5= =82(a): > > This adds a function named devm_gpiod_unhinge() that removes > the resource management from a GPIO descriptor. > > I am not sure if this is the best anglosaxon name for the > function, no other managed resources have an equivalent > currently, but I chose "unhinge" as the closest intuitive > thing I could imagine that fits Rusty Russell's API design > criterions "the obvious use is the correct one" and > "the name tells you how to use it". > > The idea came out of a remark from Mark Brown that it should > be possible to handle over management of a resource from > devres to the regulator core, and indeed we can do that. > > Cc: Bartosz Golaszewski > Signed-off-by: Linus Walleij > --- > ChangeLog v1->v2: > - New patch to be able to hand over GPIO descriptors to > the regulator core. > - Mark: feel free to apply this to the regulator tree with > the regulator tree with the rest. > --- > Documentation/driver-model/devres.txt | 1 + > drivers/gpio/gpiolib-devres.c | 17 +++++++++++++++++ > include/linux/gpio/consumer.h | 10 ++++++++++ > 3 files changed, 28 insertions(+) > > diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver= -model/devres.txt > index 43681ca0837f..fc4cc24dfb97 100644 > --- a/Documentation/driver-model/devres.txt > +++ b/Documentation/driver-model/devres.txt > @@ -254,6 +254,7 @@ GPIO > devm_gpiod_get_index_optional() > devm_gpiod_get_optional() > devm_gpiod_put() > + devm_gpiod_unhinge() > devm_gpiochip_add_data() > devm_gpiochip_remove() > devm_gpio_request() > diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.= c > index 01959369360b..5864e758d7f2 100644 > --- a/drivers/gpio/gpiolib-devres.c > +++ b/drivers/gpio/gpiolib-devres.c > @@ -320,6 +320,23 @@ void devm_gpiod_put(struct device *dev, struct gpio_= desc *desc) > } > EXPORT_SYMBOL(devm_gpiod_put); > > +/** > + * devm_gpiod_unhinge - Remove resource management from a gpio descripto= r > + * @dev: GPIO consumer > + * @desc: GPIO descriptor to remove resource management from > + * > + * Remove resource management from a GPIO descriptor. This is needed whe= n > + * you want to hand over lifecycle management of a descriptor to another > + * mechanism. > + */ > + > +void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc) > +{ > + WARN_ON(devres_destroy(dev, devm_gpiod_release, > + devm_gpiod_match, desc)); > +} > +EXPORT_SYMBOL(devm_gpiod_unhinge); > + > /** > * devm_gpiod_put_array - Resource-managed gpiod_put_array() > * @dev: GPIO consumer > diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.= h > index 348885f2f3d3..8aebcf822082 100644 > --- a/include/linux/gpio/consumer.h > +++ b/include/linux/gpio/consumer.h > @@ -104,6 +104,7 @@ struct gpio_descs *__must_check > devm_gpiod_get_array_optional(struct device *dev, const char *con_id, > enum gpiod_flags flags); > void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); > +void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc); > void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs); > > int gpiod_get_direction(struct gpio_desc *desc); > @@ -249,6 +250,15 @@ static inline void gpiod_put(struct gpio_desc *desc) > WARN_ON(1); > } > > +static inline void devm_gpiod_unhinge(struct device *dev, > + struct gpio_desc *desc) > +{ > + might_sleep(); > + > + /* GPIO can never have been requested */ > + WARN_ON(1); > +} > + > static inline void gpiod_put_array(struct gpio_descs *descs) > { > might_sleep(); > -- > 2.19.1 > Yes! This is much better than simply using non-devm variants of gpiod_get()= . Reviewed-by: Bartosz Golaszewski