Skip to contentSkip to conversation

media: v4l: Safely to call v4l2_subdev_cleanup on an uninitialised subdev

PATCH New Sakari Ailus 1 participant 1 message Dec 7, 2023 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: v4l: Safely to call v4l2_subdev_cleanup on an uninitialised subdev

Graciously handle an uninitialised (but still zeroed) sub-device in v4l2_subdev_cleanup(). The list_empty() check there is unnecessary, too, so replace that by cheking whether the lists's next field is NULL.

---
 drivers/media/v4l2-core/v4l2-subdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-subdev.c +2 -1
index 4fbefe4cd714..1fa1acfa5b7b 100644
@@ -1521,7 +1521,8 @@ void v4l2_subdev_cleanup(struct v4l2_subdev *sd)
 	__v4l2_subdev_state_free(sd->active_state);
 	sd->active_state = NULL;
 
-	if (list_empty(&sd->async_subdev_endpoint_list))
+	/* Uninitialised sub-device, bail out here. */
+	if (!sd->async_subdev_endpoint_list.next)
 		return;
 
 	list_for_each_entry_safe(ase, ase_tmp, &sd->async_subdev_endpoint_list,
Signature · 1 line
2.39.2