* [PATCH 1/1] media: v4l2-ctrls: Set error v4l2_ctrl_new_fwnode_properties consistently
@ 2025-11-11 11:20 Sakari Ailus
2025-11-11 11:32 ` Jacopo Mondi
0 siblings, 1 reply; 2+ messages in thread
From: Sakari Ailus @ 2025-11-11 11:20 UTC (permalink / raw)
To: linux-media; +Cc: hans, laurent.pinchart
The vast majority of the callers of v4l2_ctrl_new_fwnode_properties() do
check the returned error code but the function does not set the control
handler's error on failure. This will make error handling more complicated
and prone for bugs.
Always assign the control handler's error field on error in
v4l2_ctrl_new_fwnode_properties().
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
drivers/media/v4l2-core/v4l2-ctrls-core.c | 3 ++-
include/media/v4l2-ctrls.h | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index 209bc05883bb..1d4b5859f0e2 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -2780,7 +2780,8 @@ int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
orientation_ctrl = V4L2_CAMERA_ORIENTATION_EXTERNAL;
break;
default:
- return -EINVAL;
+ hdl->error = -EINVAL;
+ return hdl->error;
}
if (!v4l2_ctrl_new_std_menu(hdl, ctrl_ops,
V4L2_CID_CAMERA_ORIENTATION,
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 31fc1bee3797..327976b14d50 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -1581,6 +1581,9 @@ int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
* not overwritten. Callers should register the controls they want to handle
* themselves before calling this function.
*
+ * This function will set the control handler's error field on failure, just as
+ * other functions adding controls to the handler.
+ *
* Return: 0 on success, a negative error code on failure.
*/
int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] media: v4l2-ctrls: Set error v4l2_ctrl_new_fwnode_properties consistently
2025-11-11 11:20 [PATCH 1/1] media: v4l2-ctrls: Set error v4l2_ctrl_new_fwnode_properties consistently Sakari Ailus
@ 2025-11-11 11:32 ` Jacopo Mondi
0 siblings, 0 replies; 2+ messages in thread
From: Jacopo Mondi @ 2025-11-11 11:32 UTC (permalink / raw)
To: Sakari Ailus; +Cc: linux-media, hans, laurent.pinchart
Hi Sakari
On Tue, Nov 11, 2025 at 01:20:57PM +0200, Sakari Ailus wrote:
> The vast majority of the callers of v4l2_ctrl_new_fwnode_properties() do
> check the returned error code but the function does not set the control
> handler's error on failure. This will make error handling more complicated
> and prone for bugs.
>
> Always assign the control handler's error field on error in
> v4l2_ctrl_new_fwnode_properties().
>
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
I think it makes sense indeed
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Thanks
j
> ---
> drivers/media/v4l2-core/v4l2-ctrls-core.c | 3 ++-
> include/media/v4l2-ctrls.h | 3 +++
> 2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> index 209bc05883bb..1d4b5859f0e2 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> @@ -2780,7 +2780,8 @@ int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
> orientation_ctrl = V4L2_CAMERA_ORIENTATION_EXTERNAL;
> break;
> default:
> - return -EINVAL;
> + hdl->error = -EINVAL;
> + return hdl->error;
> }
> if (!v4l2_ctrl_new_std_menu(hdl, ctrl_ops,
> V4L2_CID_CAMERA_ORIENTATION,
> diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
> index 31fc1bee3797..327976b14d50 100644
> --- a/include/media/v4l2-ctrls.h
> +++ b/include/media/v4l2-ctrls.h
> @@ -1581,6 +1581,9 @@ int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
> * not overwritten. Callers should register the controls they want to handle
> * themselves before calling this function.
> *
> + * This function will set the control handler's error field on failure, just as
> + * other functions adding controls to the handler.
> + *
> * Return: 0 on success, a negative error code on failure.
> */
> int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
> --
> 2.47.3
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-11 11:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-11 11:20 [PATCH 1/1] media: v4l2-ctrls: Set error v4l2_ctrl_new_fwnode_properties consistently Sakari Ailus
2025-11-11 11:32 ` Jacopo Mondi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox