Re: [PATCH 03/12] pinctrl: Add optional fwnode to struct pinctrl_desc

From: Andy Shevchenko

Date: Sat Dec 05 2026 - 07:07:53 EST


On Fri, Dec 04, 2026 at 10:38:31PM -0800, Dmitry Torokhov wrote:
> Pin controller drivers for MFD or auxiliary sub-devices often need to
> associate their controller with a parent or child firmware node for DT
> lookups and hog parsing. Attaching that node directly to the live
> device during probe mutates dev->fwnode and dev->of_node concurrently
> with readers such as uevent_show() and leads to reference count
> underflows, leaks, or rebind conflicts on release.
>
> Add an optional fwnode field to struct pinctrl_desc so drivers can
> supply a controller firmware node directly, mirroring struct gpio_chip.
> Keep the pinctrl core DT-agnostic by holding firmware node references
> in struct pinctrl_dev and struct pinctrl, replacing
> get_pinctrl_dev_from_of_node() with get_pinctrl_dev_from_fwnode(), and
> updating devicetree.c to convert between struct device_node and struct
> fwnode_handle. Release both references before freeing the structs on
> teardown.

...

> -struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np)
> +struct pinctrl_dev *get_pinctrl_dev_from_fwnode(const struct fwnode_handle *fwnode)
> {
> struct pinctrl_dev *pctldev;
>
> + if (!fwnode)
> + return NULL;

Theoretically fwnode may contain an error pointer. So the better test is
IS_ERR_OR_NULL().

--
With Best Regards,
Andy Shevchenko