Re: [PATCH v1 1/9] media: vimc: Don't iterate over single pad

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Shuah,

On Thu, May 30, 2024 at 01:27:53PM -0600, Shuah Khan wrote:
> On 4/24/24 17:57, Laurent Pinchart wrote:
> > The .init_state() operations of the debayer and sensor entities iterate
> > over the entity's pads. In practice, the iteration covers a single pad
> > only. Access the pad directly and remove the loops.
> 
> I am not seeing much of a reason to do this. This code is good
> even when num_pads change.
> 
> Don't change the loops.

Why so ? Beside the fact that the loop wastes some CPU cycles, the
current code implies that there would be multiple source pads, which is
confusing for the reader. I think the result of this patch is both
improved efficiency and improved readability.

> > Signed-off-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
> > ---
> >   drivers/media/test-drivers/vimc/vimc-debayer.c |  9 +++------
> >   drivers/media/test-drivers/vimc/vimc-sensor.c  | 10 +++-------
> >   2 files changed, 6 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/media/test-drivers/vimc/vimc-debayer.c b/drivers/media/test-drivers/vimc/vimc-debayer.c
> > index d72ed086e00b..e1bf6db73050 100644
> > --- a/drivers/media/test-drivers/vimc/vimc-debayer.c
> > +++ b/drivers/media/test-drivers/vimc/vimc-debayer.c
> > @@ -155,16 +155,13 @@ static int vimc_debayer_init_state(struct v4l2_subdev *sd,
> >   {
> >   	struct vimc_debayer_device *vdebayer = v4l2_get_subdevdata(sd);
> >   	struct v4l2_mbus_framefmt *mf;
> > -	unsigned int i;
> >   
> >   	mf = v4l2_subdev_state_get_format(sd_state, 0);
> >   	*mf = sink_fmt_default;
> >   
> > -	for (i = 1; i < sd->entity.num_pads; i++) {
> > -		mf = v4l2_subdev_state_get_format(sd_state, i);
> > -		*mf = sink_fmt_default;
> > -		mf->code = vdebayer->src_code;
> > -	}
> > +	mf = v4l2_subdev_state_get_format(sd_state, 1);
> > +	*mf = sink_fmt_default;
> > +	mf->code = vdebayer->src_code;
> >   
> >   	return 0;
> >   }
> > diff --git a/drivers/media/test-drivers/vimc/vimc-sensor.c b/drivers/media/test-drivers/vimc/vimc-sensor.c
> > index 5e34b1aed95e..b535b3ffecff 100644
> > --- a/drivers/media/test-drivers/vimc/vimc-sensor.c
> > +++ b/drivers/media/test-drivers/vimc/vimc-sensor.c
> > @@ -44,14 +44,10 @@ static const struct v4l2_mbus_framefmt fmt_default = {
> >   static int vimc_sensor_init_state(struct v4l2_subdev *sd,
> >   				  struct v4l2_subdev_state *sd_state)
> >   {
> > -	unsigned int i;
> > +	struct v4l2_mbus_framefmt *mf;
> >   
> > -	for (i = 0; i < sd->entity.num_pads; i++) {
> > -		struct v4l2_mbus_framefmt *mf;
> > -
> > -		mf = v4l2_subdev_state_get_format(sd_state, i);
> > -		*mf = fmt_default;
> > -	}
> > +	mf = v4l2_subdev_state_get_format(sd_state, 0);
> > +	*mf = fmt_default;
> >   
> >   	return 0;
> >   }

-- 
Regards,

Laurent Pinchart




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux