From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Maurizio Casciano <mauriziocasciano7@gmail.com>
Cc: linux-media@vger.kernel.org,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
Nicholas Roth <nicholas@rothemail.net>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Bingbu Cao <bingbu.cao@amd.com>,
Dan Scally <dan.scally@ideasonboard.com>,
Hans de Goede <hansg@kernel.org>,
Andy Shevchenko <andy@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andy Shevchenko <andriy.shevchenko@intel.com>,
linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev
Subject: Re: [PATCH v11 01/14] media: v4l2-core: Preserve existing subdevice nodes on rollback
Date: Sat, 21 Nov 2026 15:53:49 +0200 [thread overview]
Message-ID: <20261121135349.GE2472094@killaraus.ideasonboard.com> (raw)
In-Reply-To: <48240d57d86e78cce814822360c1b22cea80268b.1795267528.git.mauriziocasciano7@gmail.com>
On Sat, Nov 21, 2026 at 02:31:31PM +0100, Maurizio Casciano wrote:
> Subdevice node registration skips nodes which already exist. On failure,
> however, it walks the subdevice list from the beginning and unregisters
> nodes regardless of whether the current call created them. On AtomISP
> this can remove the camera sensor nodes when a lens rebind fails.
>
> Keep a list of the video devices registered by this call and unregister
> only those devices on failure. Record each device before creating its
> media interface link so a failure in that step rolls back the new node
> as well. Calls with no missing nodes need no bookkeeping allocation.
>
> Codex drafted the change and tested allocation, registration and
> media-link failure using the registration helper with mocked operations.
And you didn't understand the change, because this is clearly not right.
NAK.
> Fixes: db0f4691d974 ("[media] v4l: Allow calling v4l2_device_register_subdev_nodes() multiple times")
> Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
> ---
> drivers/media/v4l2-core/v4l2-device.c | 26 ++++++++++++++++++++------
> include/media/v4l2-device.h | 3 +++
> 2 files changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
> index b4036105c..8cfca95ce 100644
> --- a/drivers/media/v4l2-core/v4l2-device.c
> +++ b/drivers/media/v4l2-core/v4l2-device.c
> @@ -191,10 +191,23 @@ static void v4l2_device_release_subdev_node(struct video_device *vdev)
> int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
> bool read_only)
> {
> + unsigned int count = 0, registered = 0;
> + struct video_device **new_nodes;
> struct video_device *vdev;
> struct v4l2_subdev *sd;
> int err;
>
> + list_for_each_entry(sd, &v4l2_dev->subdevs, list)
> + if ((sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE) && !sd->devnode)
> + count++;
> +
> + if (!count)
> + return 0;
> +
> + new_nodes = kcalloc(count, sizeof(*new_nodes), GFP_KERNEL);
> + if (!new_nodes)
> + return -ENOMEM;
> +
> /* Register a device node for every subdev marked with the
> * V4L2_SUBDEV_FL_HAS_DEVNODE flag.
> */
> @@ -228,6 +241,7 @@ int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
> kfree(vdev);
> goto clean_up;
> }
> + new_nodes[registered++] = vdev;
> #if defined(CONFIG_MEDIA_CONTROLLER)
> sd->entity.info.dev.major = VIDEO_MAJOR;
> sd->entity.info.dev.minor = vdev->minor;
> @@ -247,15 +261,15 @@ int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
> }
> #endif
> }
> - return 0;
> + err = 0;
> + goto out;
>
> clean_up:
> - list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> - if (!sd->devnode)
> - break;
> - video_unregister_device(sd->devnode);
> - }
> + while (registered)
> + video_unregister_device(new_nodes[--registered]);
>
> +out:
> + kfree(new_nodes);
> return err;
> }
> EXPORT_SYMBOL_GPL(__v4l2_device_register_subdev_nodes);
> diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
> index 25f69b1b8..6d8834d40 100644
> --- a/include/media/v4l2-device.h
> +++ b/include/media/v4l2-device.h
> @@ -183,6 +183,9 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
> * @read_only: subdevices read-only flag. True to register the subdevices
> * device nodes in read-only mode, false to allow full access to the
> * subdevice userspace API.
> + *
> + * Existing nodes are kept even if registration of a new node fails.
> + * The caller must serialize this operation with changes to the subdevice list.
> */
> int __must_check
> __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
> --
> 2.53.0
>
>
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2026-11-21 13:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 01/14] media: v4l2-core: Preserve existing subdevice nodes on rollback Maurizio Casciano
2026-11-21 13:53 ` Laurent Pinchart [this message]
2026-11-21 13:31 ` [PATCH v11 02/14] media: ov8858: Extract digital gain programming Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 03/14] media: ov8858: Support a 19.2 MHz input clock on four-lane R2A Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 04/14] media: ov2740: Add OVTI2740 ACPI ID Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 05/14] media: intel: ipu-bridge: Add the Yoga Book OVTI2740 entry Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 06/14] media: atomisp: Add Yoga Book camera configuration Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 07/14] media: ov2740: support 288 MHz link frequency Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 08/14] media: intel: ipu-bridge: select OV2740 frequency by IPU ID Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 09/14] media: atomisp: Derive CSI-2 timing from the sensor link frequency Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 10/14] media: ov2740: release group hold after gain write errors Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 11/14] media: atomisp: Use struct v4l2_area for padding Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 12/14] media: atomisp: Allow raw Bayer capture Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 13/14] media: i2c: Add WV517S lens actuator driver Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 14/14] media: atomisp: Preserve the capture graph when a lens rebinds Maurizio Casciano
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=20261121135349.GE2472094@killaraus.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=bingbu.cao@amd.com \
--cc=dan.scally@ideasonboard.com \
--cc=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--cc=jacopo.mondi@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mauriziocasciano7@gmail.com \
--cc=mchehab@kernel.org \
--cc=nicholas@rothemail.net \
--cc=sakari.ailus@linux.intel.com \
/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