Re: [PATCH] media: v4l2-dev: fix media controller registration error handling

From: Laurent Pinchart

Date: Tue Jun 30 2026 - 06:32:30 EST


On Tue, Jun 30, 2026 at 05:54:56PM +0800, Shih-Sheng Yang wrote:
> Hi Laurent,
>
> Thank you for the review.
>
> I've addressed this in v2 by moving the NULL check into
> media_devnode_remove() and by using device_unregister() in
> __video_register_device(), as device_register() has already succeeded
> there.
>
> I also checked the other media_devnode_remove() callers. I didn't find
> another caller with the same failure pattern or an immediate risk that
> requires changing the helper API. Since changing media_devnode_remove()
> to take a pointer-to-pointer would affect a wider set of callers, I have
> left that out of v2. I can add it if you prefer.

Sakari, Hans, to you have an opinion on that pattern ? If you forget the
context, the idea is to turn

void media_devnode_remove(struct media_intf_devnode *devnode)
{
media_remove_intf_links(&devnode->intf);
media_gobj_destroy(&devnode->intf.graph_obj);
kfree(devnode);
}

into

void media_devnode_remove(struct media_intf_devnode **devnode)
{
struct media_intf_devnode *node = *devnode;

if (!node)
return;

media_remove_intf_links(&node->intf);
media_gobj_destroy(&node->intf.graph_obj);
kfree(node);

*devnode = NULL;
}

(bikeshedding on whether or not we need a local variable is left for
later)

I think the pattern is safer, but it's not common in V4L2 at the moment.

--
Regards,

Laurent Pinchart