linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] v4l: subdev: Fail graciously when getting try data for NULL state
@ 2022-08-26 11:56 Sakari Ailus
  2022-08-29  6:14 ` Tomi Valkeinen
  0 siblings, 1 reply; 2+ messages in thread
From: Sakari Ailus @ 2022-08-26 11:56 UTC (permalink / raw)
  To: linux-media; +Cc: Bingbu Cao, Tianshu Qiu, Tomi Valkeinen

The state argument for the functions for obtaining various parts of the
state is NULL if it is called by drivers for active state. Fail graciously
in that case instead of dereferencing a NULL pointer.

Suggested-by: Bingbu Cao <bingbu.cao@intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 include/media/v4l2-subdev.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 9689f38a0af1f..ec1896886dbd6 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -1046,6 +1046,8 @@ v4l2_subdev_get_pad_format(struct v4l2_subdev *sd,
 			   struct v4l2_subdev_state *state,
 			   unsigned int pad)
 {
+	if (WARN_ON(!state))
+		return NULL;
 	if (WARN_ON(pad >= sd->entity.num_pads))
 		pad = 0;
 	return &state->pads[pad].try_fmt;
@@ -1064,6 +1066,8 @@ v4l2_subdev_get_pad_crop(struct v4l2_subdev *sd,
 			 struct v4l2_subdev_state *state,
 			 unsigned int pad)
 {
+	if (WARN_ON(!state))
+		return NULL;
 	if (WARN_ON(pad >= sd->entity.num_pads))
 		pad = 0;
 	return &state->pads[pad].try_crop;
@@ -1082,6 +1086,8 @@ v4l2_subdev_get_pad_compose(struct v4l2_subdev *sd,
 			    struct v4l2_subdev_state *state,
 			    unsigned int pad)
 {
+	if (WARN_ON(!state))
+		return NULL;
 	if (WARN_ON(pad >= sd->entity.num_pads))
 		pad = 0;
 	return &state->pads[pad].try_compose;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] v4l: subdev: Fail graciously when getting try data for NULL state
  2022-08-26 11:56 [PATCH 1/1] v4l: subdev: Fail graciously when getting try data for NULL state Sakari Ailus
@ 2022-08-29  6:14 ` Tomi Valkeinen
  0 siblings, 0 replies; 2+ messages in thread
From: Tomi Valkeinen @ 2022-08-29  6:14 UTC (permalink / raw)
  To: Sakari Ailus, linux-media; +Cc: Bingbu Cao, Tianshu Qiu

On 26/08/2022 14:56, Sakari Ailus wrote:
> The state argument for the functions for obtaining various parts of the
> state is NULL if it is called by drivers for active state. Fail graciously

Only for drivers that do not use active state. Which is most of them at 
the moment.

> in that case instead of dereferencing a NULL pointer.
> 
> Suggested-by: Bingbu Cao <bingbu.cao@intel.com>
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>   include/media/v4l2-subdev.h | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index 9689f38a0af1f..ec1896886dbd6 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -1046,6 +1046,8 @@ v4l2_subdev_get_pad_format(struct v4l2_subdev *sd,
>   			   struct v4l2_subdev_state *state,
>   			   unsigned int pad)
>   {
> +	if (WARN_ON(!state))
> +		return NULL;
>   	if (WARN_ON(pad >= sd->entity.num_pads))
>   		pad = 0;
>   	return &state->pads[pad].try_fmt;
> @@ -1064,6 +1066,8 @@ v4l2_subdev_get_pad_crop(struct v4l2_subdev *sd,
>   			 struct v4l2_subdev_state *state,
>   			 unsigned int pad)
>   {
> +	if (WARN_ON(!state))
> +		return NULL;
>   	if (WARN_ON(pad >= sd->entity.num_pads))
>   		pad = 0;
>   	return &state->pads[pad].try_crop;
> @@ -1082,6 +1086,8 @@ v4l2_subdev_get_pad_compose(struct v4l2_subdev *sd,
>   			    struct v4l2_subdev_state *state,
>   			    unsigned int pad)
>   {
> +	if (WARN_ON(!state))
> +		return NULL;
>   	if (WARN_ON(pad >= sd->entity.num_pads))
>   		pad = 0;
>   	return &state->pads[pad].try_compose;

Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

  Tomi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-29  6:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26 11:56 [PATCH 1/1] v4l: subdev: Fail graciously when getting try data for NULL state Sakari Ailus
2022-08-29  6:14 ` Tomi Valkeinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).