From: Herve Codina <herve.codina@bootlin.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>, Pavel Machek <pavel@ucw.cz>,
Lee Jones <lee@kernel.org>
Cc: Saravana Kannan <saravanak@google.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-leds@vger.kernel.org,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Herve Codina <herve.codina@bootlin.com>
Subject: [PATCH RESEND 2/2] leds: gpio: Add devlinks between the gpio consumed and the gpio leds device
Date: Tue, 20 Feb 2024 14:39:49 +0100 [thread overview]
Message-ID: <20240220133950.138452-3-herve.codina@bootlin.com> (raw)
In-Reply-To: <20240220133950.138452-1-herve.codina@bootlin.com>
When a gpio is removed, the gpio leds consumer need to be removed first.
This dependency consumer/supplier can be described by devlink links.
In case of device-tree, even if some devlinks are created due to the
presence of gpio phandles in the gpio leds children, these links do not
help in removing the gpio leds device (i.e. the real consumer) before
the consumed gpio.
We can reach cases where the gpio are no more present and the gpio leds
driver continue to have leds using these gpio.
Further more, when the gpio come back, the gpio leds still use the old
removed one.
Indeed, the gpio are consumed by the parent of the consumer used in the
devlink creation due to phandles. A link is missing between the gpio and
the real gpio consumer, the gpio leds device itself.
Use the newly introduced gpiod_device_add_link() to create this
missing link between the gpio leds devices and the gpios.
With that done, if a gpio is removed, the gpio leds is removed and the
resources are correctly released.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/leds/leds-gpio.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 83fcd7b6afff..b3ec8ecbe5da 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -150,6 +150,7 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
{
struct fwnode_handle *child;
struct gpio_leds_priv *priv;
+ struct device_link *link;
int count, ret;
count = device_get_child_node_count(dev);
@@ -197,6 +198,20 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
/* Set gpiod label to match the corresponding LED name. */
gpiod_set_consumer_name(led_dat->gpiod,
led_dat->cdev.dev->kobj.name);
+
+ /*
+ * Create a link between the GPIO and the gpio-leds device.
+ * This allow to have a relationship between the gpio used and
+ * the gpio-leds device in order to automatically remove the
+ * gpio-leds device (consumer) when a GPIO (supplier) is removed.
+ */
+ link = gpiod_device_add_link(dev, led_dat->gpiod,
+ DL_FLAG_AUTOREMOVE_CONSUMER);
+ if (IS_ERR(link)) {
+ fwnode_handle_put(child);
+ return ERR_CAST(link);
+ }
+
priv->num_leds++;
}
--
2.43.0
next prev parent reply other threads:[~2024-02-20 13:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-20 13:39 [PATCH RESEND 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used Herve Codina
2024-02-20 13:39 ` [PATCH RESEND 1/2] gpiolib: Introduce gpiod_device_add_link() Herve Codina
2024-02-20 13:39 ` Herve Codina [this message]
2024-02-20 14:19 ` [PATCH RESEND 0/2] leds: gpio: Add devlink between the leds-gpio device and the gpio used Bartosz Golaszewski
2024-02-20 14:53 ` Herve Codina
2024-02-20 15:30 ` Bartosz Golaszewski
2024-02-20 15:47 ` Herve Codina
2024-02-21 3:28 ` Saravana Kannan
2024-02-27 12:06 ` Herve Codina
2024-04-08 13:44 ` Herve Codina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240220133950.138452-3-herve.codina@bootlin.com \
--to=herve.codina@bootlin.com \
--cc=brgl@bgdev.pl \
--cc=lee@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=pavel@ucw.cz \
--cc=saravanak@google.com \
--cc=thomas.petazzoni@bootlin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).