Re: [PATCH v3 4/8] software node: ignore primary nodes in device_remove_software_node()

From: Andy Shevchenko

Date: Tue Nov 17 2026 - 09:02:02 EST


On Tue, Nov 17, 2026 at 11:13:32AM +0100, Johan Hovold wrote:
> device_remove_software_node() should only be used to remove secondary
> firmware nodes added by device_add_software_node() but will currently
> drop a reference also if a device has a primary software node.
>
> Bail out early if device_remove_software_node() is called for a device
> whose primary firmware node is a software node and fix up the two
> callers that currently work around this themselves.

...

> +++ b/drivers/i2c/i2c-core-base.c

> void i2c_unregister_device(struct i2c_client *client)
> {
> struct fwnode_handle *fwnode;
> - bool fwnode_is_software_node;
>
> if (IS_ERR_OR_NULL(client))
> return;

> - fwnode_is_software_node = is_software_node(fwnode);
> device_remove_software_node(&client->dev);
> /*
> - * If the firmware node is a software node, its reference count
> - * was decremented by device_remove_software_node().
> + * Must be done after device_remove_software_node() which may have
> + * freed a secondary firmware node and cleared the fwnode pointer.
> */
> - if (!fwnode_is_software_node)
> - fwnode_handle_put(fwnode);
> + fwnode_handle_put(client->dev.fwnode);

We have fwnode getter, so better use it

fwnode_handle_put(dev_fwnode(&client->dev));

Same can be applied to the platform device case above (in this patch).

> device_unregister(&client->dev);
> }

--
With Best Regards,
Andy Shevchenko