diff mbox series

[v12,20/30] media: subdev: add streams to v4l2_subdev_get_fmt() helper function

Message ID 20220727103639.581567-21-tomi.valkeinen@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series v4l: routing and streams support | expand

Commit Message

Tomi Valkeinen July 27, 2022, 10:36 a.m. UTC
Add streams support to v4l2_subdev_get_fmt() helper function. Subdev
drivers that do not need to do anything special in their get_fmt op can
use this helper directly for v4l2_subdev_pad_ops.get_fmt.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/v4l2-core/v4l2-subdev.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Satish Nagireddy July 29, 2022, 9:16 a.m. UTC | #1
Hi Tomi,

Thanks for the patch.

On Wed, Jul 27, 2022 at 3:37 AM Tomi Valkeinen
<tomi.valkeinen@ideasonboard.com> wrote:
>
> Add streams support to v4l2_subdev_get_fmt() helper function. Subdev
> drivers that do not need to do anything special in their get_fmt op can
> use this helper directly for v4l2_subdev_pad_ops.get_fmt.
>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/v4l2-core/v4l2-subdev.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index 0dd612f09f35..95fd2e07d69f 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -1455,10 +1455,14 @@ int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
>  {
>         struct v4l2_mbus_framefmt *fmt;
>
> -       if (format->pad >= sd->entity.num_pads)
> -               return -EINVAL;
> +       if (sd->flags & V4L2_SUBDEV_FL_STREAMS)
> +               fmt = v4l2_subdev_state_get_stream_format(state, format->pad,
> +                                                         format->stream);
> +       else if (format->pad < sd->entity.num_pads && format->stream == 0)
> +               fmt = v4l2_subdev_get_pad_format(sd, state, format->pad);
> +       else
> +               fmt = NULL;

fmt can be initialized to NULL at the declaration, so that the above 2
lines can be removed.

Regards,
Satish

>
> -       fmt = v4l2_subdev_get_pad_format(sd, state, format->pad);
>         if (!fmt)
>                 return -EINVAL;
>
> --
> 2.34.1
>
Tomi Valkeinen July 29, 2022, 10:30 a.m. UTC | #2
On 29/07/2022 12:16, Satish Nagireddy wrote:
> Hi Tomi,
> 
> Thanks for the patch.
> 
> On Wed, Jul 27, 2022 at 3:37 AM Tomi Valkeinen
> <tomi.valkeinen@ideasonboard.com> wrote:
>>
>> Add streams support to v4l2_subdev_get_fmt() helper function. Subdev
>> drivers that do not need to do anything special in their get_fmt op can
>> use this helper directly for v4l2_subdev_pad_ops.get_fmt.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/v4l2-core/v4l2-subdev.c | 10 +++++++---
>>   1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
>> index 0dd612f09f35..95fd2e07d69f 100644
>> --- a/drivers/media/v4l2-core/v4l2-subdev.c
>> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
>> @@ -1455,10 +1455,14 @@ int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
>>   {
>>          struct v4l2_mbus_framefmt *fmt;
>>
>> -       if (format->pad >= sd->entity.num_pads)
>> -               return -EINVAL;
>> +       if (sd->flags & V4L2_SUBDEV_FL_STREAMS)
>> +               fmt = v4l2_subdev_state_get_stream_format(state, format->pad,
>> +                                                         format->stream);
>> +       else if (format->pad < sd->entity.num_pads && format->stream == 0)
>> +               fmt = v4l2_subdev_get_pad_format(sd, state, format->pad);
>> +       else
>> +               fmt = NULL;
> 
> fmt can be initialized to NULL at the declaration, so that the above 2
> lines can be removed.

That is true, but I personally like the above better, as it handles all 
the cases in the same if-else-sequence.

  Tomi
Satish Nagireddy July 29, 2022, 5:01 p.m. UTC | #3
On Fri, Jul 29, 2022 at 3:30 AM Tomi Valkeinen
<tomi.valkeinen@ideasonboard.com> wrote:
>
> On 29/07/2022 12:16, Satish Nagireddy wrote:
> > Hi Tomi,
> >
> > Thanks for the patch.
> >
> > On Wed, Jul 27, 2022 at 3:37 AM Tomi Valkeinen
> > <tomi.valkeinen@ideasonboard.com> wrote:
> >>
> >> Add streams support to v4l2_subdev_get_fmt() helper function. Subdev
> >> drivers that do not need to do anything special in their get_fmt op can
> >> use this helper directly for v4l2_subdev_pad_ops.get_fmt.
> >>
> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> >> ---
> >>   drivers/media/v4l2-core/v4l2-subdev.c | 10 +++++++---
> >>   1 file changed, 7 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> >> index 0dd612f09f35..95fd2e07d69f 100644
> >> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> >> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> >> @@ -1455,10 +1455,14 @@ int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
> >>   {
> >>          struct v4l2_mbus_framefmt *fmt;
> >>
> >> -       if (format->pad >= sd->entity.num_pads)
> >> -               return -EINVAL;
> >> +       if (sd->flags & V4L2_SUBDEV_FL_STREAMS)
> >> +               fmt = v4l2_subdev_state_get_stream_format(state, format->pad,
> >> +                                                         format->stream);
> >> +       else if (format->pad < sd->entity.num_pads && format->stream == 0)
> >> +               fmt = v4l2_subdev_get_pad_format(sd, state, format->pad);
> >> +       else
> >> +               fmt = NULL;
> >
> > fmt can be initialized to NULL at the declaration, so that the above 2
> > lines can be removed.
>
> That is true, but I personally like the above better, as it handles all
> the cases in the same if-else-sequence.
>
>   Tomi

Sure.

- Satish
diff mbox series

Patch

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index 0dd612f09f35..95fd2e07d69f 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -1455,10 +1455,14 @@  int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
 {
 	struct v4l2_mbus_framefmt *fmt;
 
-	if (format->pad >= sd->entity.num_pads)
-		return -EINVAL;
+	if (sd->flags & V4L2_SUBDEV_FL_STREAMS)
+		fmt = v4l2_subdev_state_get_stream_format(state, format->pad,
+							  format->stream);
+	else if (format->pad < sd->entity.num_pads && format->stream == 0)
+		fmt = v4l2_subdev_get_pad_format(sd, state, format->pad);
+	else
+		fmt = NULL;
 
-	fmt = v4l2_subdev_get_pad_format(sd, state, format->pad);
 	if (!fmt)
 		return -EINVAL;