From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796448303; b=nVmlveisSJxzNUpJlzZPpKo2gXamlyeLy4VcEtDTX/UisjC0+1jRKR2HSIxMp6rxizWK XgukNG0tsYYwV+SeFMUgHnbVK/8tO1JOVOygMbnl3o4/YuiS83DKwaBKxIP6qTxZdFBHy T3NmAFXpNnZKC6SmGOYlfKimB5ybGIFu2DO3VM6XPnSShD3/HpR884rIy7cc5buM+NSON QKW6zZfU6qz/YJZ1pmIXyIh20fLdknlocjwzqQwsp+5kfK+V/JOeIAqEpEiSxIKQevVwR sR8C1tkWfzVoAvpf02pWLLifPcidFq29741gVHiEvN6bxtiARIQrwRbTcfk9uFIJrhg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796448303; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=b5nOWmA+A9t9kOWxfp7GbwctH0+ryM+O81hLCJ6XaN0=; b=yg7sTuZSfWRXHpX8gTK1BIptPRaXLugAEFA0eHfLPrT8PfYW8g4en6TzyPRRFYa980Zh KSfByp3m1+BM+Egx6Cj4+x5TUpzkeoFbaGZ2CuXBPjSBITPX0rW9SJSmZCPzkmpGt8VDa zSCaWe0cpX/98i3pGzy6LpqIX/jydCbZs7IkbTKmxaBgQ2V4ktR13OR8V3PKG5aPSg604 iVTjQrU23XCk1B832n9q7nhF8LfaJITk02/tNBOSgYUYxzAlCX1d6k8Yv56OfARVSb3dO M5MRMBKCiaxFnUh40irWgcO5kp/BLEqGJoHd/xdKUavHo23eHY2+i/0SoCk4BHDa1ew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b="i4rxb/iX"; arc=none smtp.remote-ip=209.85.216.53 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A086606A32F for ; Sat, 5 Dec 2026 05:25:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0A086606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=i4rxb/iX Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-3b40f4d4b5dso859598a91.1 for ; Fri, 04 Dec 2026 21:25:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796448302; x=1797053102; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=b5nOWmA+A9t9kOWxfp7GbwctH0+ryM+O81hLCJ6XaN0=; b=i4rxb/iXjd7d2S21JM2NzVg5JcFdau520elYM4426Mimj8X8dPsOtxG2nkrkc/5RsF Z8nCX9KpD2a1Y3COgPkpXj0RErKZADcYkTwPZbwkZ8RkKD3Dsgr+owvqj98Irg/MvzJe u3I0h7IKDI0iBsIEZ8cAimWsDYJfVoE9J5cAqwJENwh59y9sR88xTYsoyg/3G3MUPl93 kbjf0T8D68nPxeaXdTh6FlLBPugEGn7wjf5BA+9pdheWyDZxLVewxaI8fE5IH93zQAiJ ca92EyILySRTE9LVqVpkShEb8b0nI5yGxl0H6cj6jXJzntzOjHr79ZRJsjrmiaePwsbH czSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796448302; x=1797053102; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=b5nOWmA+A9t9kOWxfp7GbwctH0+ryM+O81hLCJ6XaN0=; b=yVwKRpltB11numKaFzBlDKFVTSJSPOa7/dFFqFXPi5o+kDeWJovhCRbMYml9uzPUSz irWtK6yMAp4d5gDoxMSonD+Upo1+5t/UWwYMusS2PW9hh88ewcUNYG/MfUK9R1/jQ7Ru +qh6RY1fAd89ka4EWxuNTVnILLcC8sPZBf+4uky5xPFQUUfBDbqUnp0Ql/HT0Vfzvf/3 4fjpNZKA81PICEDkf0dvARk4IwIY9gxWVU9vYRrCgPeo1JGs7TMUcXP4ksg/YrRyhhyZ BjoVVOpNvOCjqjnLqJDI5D5wnyyzzrIKSDPsIUFlj7mzTkDozuQtyQWMs7gVzeKMSMQf l0Og== X-Forwarded-Encrypted: i=1; AL+hErGKGMOtnQfWXZm66hdPv2ibv2CHMJZUgslbWjCcy9pKtRGQebKPT4FwPgvyFx4Y5Y2rKsVT2wc=@vger.kernel.org X-Gm-Message-State: AB4q+uFN0y6r4H1VUQnqtjPwVwrdlhEPy53cIT4QtXPLrN9b4sRwiP5N gp7AHVHLLZWsUB7+BEFIwlWS0tp/J/EkbEJSN0q5CpztZjtB/iUtWsun888DPOHEYw== X-Gm-Gg: AZFdTZc+iSSqEkkLPCOgT31wjxVHz9Fc+Ydsns+2ivLx+MwyROHXRDPrNhl8qnnedn1 bJb1hddMqeVrcDh1ygsqwUzDrvaZFB8SWDkkT4s1hH9tYbN2Z4MEe47q47T5vadaNkUKwsl6izD 3y1Ey1X3VwtZ+LCiOpBzv28vO7v8JJCGCUs1K9Qi7Jiye5nUiHHt7qc+LrenGBCDCB4YBir31AT bpPhMpG/Pdpb6iW3a9BgHxEpuc5ntio5mbRNM2lAzc9oHUBEdEBqkicwoExVWSxnw9BQ69u6HcH cQHKVMD+as48tZrkyIzMpmLpYapntP9VPFyX0DFUQP4ZAEcQdzVywy+wfnvS2ve+dzJLGjrYMd/ JwsPYJNlDn6IHgTqn3UzkrNjkrohNo9Bbume3Q3kd+/ZNd/NV9CruwmmHQJTzWiGZUacGgWbORX 7L3nBj8WoWD1EbMVHxBFrJIiggnRzvGyWL9COX4d1hE/Ah5+9xHKFOcOufYq2mZfUwicmFdEwKJ yABypCacD28Z/xpXP55Ur4OOvzUbffjsqrqfO8XMuKQNsu/wFaK83uywT6o60nA9F4qX1vBksVb 3Di0c9mj3w77oKfByKrmWYMUqGqCEjtP8D2Xfnhxe9OyWJCUA1E78NH7L3OVqJyq/XULGU7zYWQ 3a+rN4Ca9DLL4Q8HPjW0NRBNwVjptSpgxHEtH+zFaMpDfyGtV0FUpxgt8m2MF4qrqgOL5eEEt9a mGdEmG8Gl9 X-Received: by 2002:a17:90b:590f:b0:3b3:b36e:8c40 with SMTP id 98e67ed59e1d1-3b5e067e6bcmr3610447a91.62.1796448301388; Fri, 04 Dec 2026 21:25:01 -0800 (PST) Received: from google.com (196.126.197.35.bc.googleusercontent.com. [35.197.126.196]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c7d9893asm12378959a91.16.2026.12.04.21.24.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 21:24:59 -0800 (PST) Date: Fri, 4 Dec 2026 21:24:56 -0800 From: Benson Leung To: Dmitry Torokhov Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , Benson Leung , Guenter Roeck , Stephen Boyd , 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 Message-ID: References: <20261202-gpio-arizona-fwnode-fix-v1-0-3899179bf9d1@gmail.com> <20261202-gpio-arizona-fwnode-fix-v1-6-3899179bf9d1@gmail.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="BSZNOvbqVpHSGCqg" Content-Disposition: inline In-Reply-To: <20261202-gpio-arizona-fwnode-fix-v1-6-3899179bf9d1@gmail.com> --BSZNOvbqVpHSGCqg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > 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(). >=20 > 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. >=20 > Fixes: f837fe1bffe6 ("gpio: Add ChromeOS EC GPIO driver") > Cc: stable@vger.kernel.org > Signed-off-by: Dmitry Torokhov Reviewed-by: Benson Leung > --- > drivers/gpio/gpio-cros-ec.c | 26 ++++++++++++++++++++++++-- > 1 file changed, 24 insertions(+), 2 deletions(-) >=20 > 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_devic= e *cros_ec) > return response.get_count.val; > } > =20 > +static void cros_ec_gpio_put_fwnode(void *data) > +{ > + struct device *dev =3D data; > + struct fwnode_handle *fwnode =3D 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 =3D &pdev->dev; > struct device *parent =3D dev->parent; > struct cros_ec_dev *ec_dev =3D dev_get_drvdata(parent); > struct cros_ec_device *cros_ec =3D ec_dev->ec_dev; > + struct fwnode_handle *fwnode =3D dev_fwnode(cros_ec->dev); > struct gpio_chip *gc; > int ngpios; > int ret; > =20 > - /* 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 =3D devm_add_action_or_reset(dev, cros_ec_gpio_put_fwnode, > + dev); > + if (ret) > + return ret; > + } > =20 > ngpios =3D cros_ec_gpio_ngpios(cros_ec); > if (ngpios < 0) { > @@ -180,6 +201,7 @@ static int cros_ec_gpio_probe(struct platform_device = *pdev) > =20 > gc->ngpio =3D ngpios; > gc->parent =3D dev; > + gc->fwnode =3D fwnode; > ret =3D cros_ec_gpio_init_names(cros_ec, gc); > if (ret) > return ret; >=20 > --=20 > 2.56.1.915.g69d5ec7298-goog >=20 >=20 --BSZNOvbqVpHSGCqg Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQQCtZK6p/AktxXfkOlzbaomhzOwwgUCaxOgKAAKCRBzbaomhzOw wohvAQDSiLlFpD/OG8BAZlcL05ynlkv6m93xKhomlYbbvifk6gEA9uadbKyPMICD ihc6skQ8dz1KtU33EgJQVyd7ShSeJQI= =7Smg -----END PGP SIGNATURE----- --BSZNOvbqVpHSGCqg--