From: Benson Leung <bleung@google.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Benson Leung <bleung@chromium.org>,
Guenter Roeck <groeck@chromium.org>,
Stephen Boyd <swboyd@chromium.org>,
patches@opensource.cirrus.com, linux-gpio@vger.kernel.org,
chrome-platform@lists.linux.dev, stable@vger.kernel.org
Subject: Re: [PATCH 6/6] gpio: cros-ec: Fix firmware node reference count underflow
Date: Fri, 4 Dec 2026 21:24:56 -0800 [thread overview]
Message-ID: <axOgJ-HVH6bam_qk@google.com> (raw)
In-Reply-To: <20261202-gpio-arizona-fwnode-fix-v1-6-3899179bf9d1@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3506 bytes --]
On Wed, Dec 02, 2026 at 10:45:51PM -0800, Dmitry Torokhov wrote:
> cros_ec_gpio_probe() attaches the underlying EC protocol device's
> firmware node to the child platform device using device_set_node()
> without taking a reference. On teardown, platform_device_release() drops
> a firmware node reference and removes any attached software node,
> underflowing the protocol device's reference count and prematurely
> tearing down an attached software node.
>
> Take a reference with fwnode_handle_get() when attaching the protocol
> device's firmware node if the platform device does not already have one,
> and register cros_ec_gpio_put_fwnode() via devm_add_action_or_reset()
> before devm_gpiochip_add_data() to clear the platform device's node and
> drop the reference. Because devres runs in LIFO order, the GPIO chip and
> acpi_gpiochip_remove() on the parent device finish before the node is
> cleared, and device_del() unbinds the driver before
> device_platform_notify_remove() and platform_device_release().
>
> This preserves ACPI companion attachment for acpi_gpiochip_add(), which
> inspects the parent device while cros-ec-dev does not propagate it,
> while gpio_chip.fwnode is also assigned explicitly.
>
> Fixes: f837fe1bffe6 ("gpio: Add ChromeOS EC GPIO driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Benson Leung <bleung@chromium.org>
> ---
> drivers/gpio/gpio-cros-ec.c | 26 ++++++++++++++++++++++++--
> 1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-cros-ec.c b/drivers/gpio/gpio-cros-ec.c
> index d06d74bd86d8..4a77ff3acd54 100644
> --- a/drivers/gpio/gpio-cros-ec.c
> +++ b/drivers/gpio/gpio-cros-ec.c
> @@ -155,18 +155,39 @@ static int cros_ec_gpio_ngpios(struct cros_ec_device *cros_ec)
> return response.get_count.val;
> }
>
> +static void cros_ec_gpio_put_fwnode(void *data)
> +{
> + struct device *dev = data;
> + struct fwnode_handle *fwnode = dev_fwnode(dev);
> +
> + device_set_node(dev, NULL);
> + fwnode_handle_put(fwnode);
> +}
> +
> static int cros_ec_gpio_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> struct device *parent = dev->parent;
> struct cros_ec_dev *ec_dev = dev_get_drvdata(parent);
> struct cros_ec_device *cros_ec = ec_dev->ec_dev;
> + struct fwnode_handle *fwnode = dev_fwnode(cros_ec->dev);
> struct gpio_chip *gc;
> int ngpios;
> int ret;
>
> - /* Use the fwnode from the protocol device, e.g. cros-ec-spi */
> - device_set_node(dev, dev_fwnode(cros_ec->dev));
> + if (!dev_fwnode(dev) && fwnode) {
> + /*
> + * Use the fwnode from the protocol device, e.g. cros-ec-spi,
> + * so acpi_gpiochip_add() sees its ACPI companion. Clear it on
> + * unbind so platform_device_release() does not drop a parent
> + * reference or tear down a shared software node.
> + */
> + device_set_node(dev, fwnode_handle_get(fwnode));
> + ret = devm_add_action_or_reset(dev, cros_ec_gpio_put_fwnode,
> + dev);
> + if (ret)
> + return ret;
> + }
>
> ngpios = cros_ec_gpio_ngpios(cros_ec);
> if (ngpios < 0) {
> @@ -180,6 +201,7 @@ static int cros_ec_gpio_probe(struct platform_device *pdev)
>
> gc->ngpio = ngpios;
> gc->parent = dev;
> + gc->fwnode = fwnode;
> ret = cros_ec_gpio_init_names(cros_ec, gc);
> if (ret)
> return ret;
>
> --
> 2.56.1.915.g69d5ec7298-goog
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-12-05 5:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 6:45 [PATCH 0/6] gpio: fix firmware node reference count underflows Dmitry Torokhov
2026-12-03 6:45 ` [PATCH 1/6] gpio: arizona: Fix firmware node reference count underflow Dmitry Torokhov
2026-12-03 11:28 ` Charles Keepax
2026-12-03 6:45 ` [PATCH 2/6] gpio: tps6586x: " Dmitry Torokhov
2026-12-03 6:45 ` [PATCH 3/6] gpio: tps65910: " Dmitry Torokhov
2026-12-03 6:45 ` [PATCH 4/6] gpio: twl6040: " Dmitry Torokhov
2026-12-03 6:45 ` [PATCH 5/6] gpio: wm831x: " Dmitry Torokhov
2026-12-03 11:28 ` Charles Keepax
2026-12-03 6:45 ` [PATCH 6/6] gpio: cros-ec: " Dmitry Torokhov
2026-12-03 12:11 ` Andy Shevchenko
2026-12-05 5:24 ` Benson Leung [this message]
2026-12-03 12:09 ` [PATCH 0/6] gpio: fix firmware node reference count underflows Andy Shevchenko
2026-12-03 19:58 ` Dmitry Torokhov
2026-12-04 9:36 ` Andy Shevchenko
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=axOgJ-HVH6bam_qk@google.com \
--to=bleung@google.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bleung@chromium.org \
--cc=brgl@kernel.org \
--cc=chrome-platform@lists.linux.dev \
--cc=dmitry.torokhov@gmail.com \
--cc=groeck@chromium.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=stable@vger.kernel.org \
--cc=swboyd@chromium.org \
/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