public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
	linux-media@vger.kernel.org, Tianshu Qiu <tian.shu.qiu@intel.com>,
	Bingbu Cao <bingbu.cao@intel.com>,
	Jacopo Mondi <jacopo+renesas@jmondi.org>,
	Rui Miguel Silva <rmfrfs@gmail.com>,
	Martin Kepplinger <martink@posteo.de>
Subject: Re: [PATCH v3 11/12] media: v4l: subdev: Print debug information on frame descriptor
Date: Fri, 22 Sep 2023 17:51:51 +0300	[thread overview]
Message-ID: <20230922145151.GI19112@pendragon.ideasonboard.com> (raw)
In-Reply-To: <60f44e28-1166-026f-1bea-633de7d53298@ideasonboard.com>

On Fri, Sep 22, 2023 at 01:27:46PM +0300, Tomi Valkeinen wrote:
> On 22/09/2023 13:22, Laurent Pinchart wrote:
> > On Fri, Sep 22, 2023 at 01:16:21PM +0300, Tomi Valkeinen wrote:
> >> On 22/09/2023 13:09, Sakari Ailus wrote:
> >>> On Fri, Sep 22, 2023 at 12:53:20PM +0300, Laurent Pinchart wrote:
> >>>> On Fri, Sep 22, 2023 at 09:41:01AM +0000, Sakari Ailus wrote:
> >>>>> On Tue, Sep 19, 2023 at 06:21:23PM +0300, Laurent Pinchart wrote:
> >>>>>> On Tue, Sep 19, 2023 at 02:49:29PM +0000, Sakari Ailus wrote:
> >>>>>>> On Tue, Sep 19, 2023 at 04:32:48PM +0300, Laurent Pinchart wrote:
> >>>>>>>> On Tue, Sep 19, 2023 at 03:17:27PM +0300, Sakari Ailus wrote:
> >>>>>>>>> Print debug level information on returned frame descriptors.
> >>>>>>>>>
> >>>>>>>>> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> >>>>>>>>> ---
> >>>>>>>>>    drivers/media/v4l2-core/v4l2-subdev.c | 32 ++++++++++++++++++++++++++-
> >>>>>>>>>    1 file changed, 31 insertions(+), 1 deletion(-)
> >>>>>>>>>
> >>>>>>>>> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> >>>>>>>>> index 7b087be3ff4f..504ca625b2bd 100644
> >>>>>>>>> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> >>>>>>>>> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> >>>>>>>>> @@ -15,6 +15,7 @@
> >>>>>>>>>    #include <linux/module.h>
> >>>>>>>>>    #include <linux/overflow.h>
> >>>>>>>>>    #include <linux/slab.h>
> >>>>>>>>> +#include <linux/string.h>
> >>>>>>>>>    #include <linux/types.h>
> >>>>>>>>>    #include <linux/version.h>
> >>>>>>>>>    #include <linux/videodev2.h>
> >>>>>>>>> @@ -309,9 +310,38 @@ static int call_set_selection(struct v4l2_subdev *sd,
> >>>>>>>>>    static int call_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
> >>>>>>>>>    			       struct v4l2_mbus_frame_desc *fd)
> >>>>>>>>>    {
> >>>>>>>>> +	unsigned int i;
> >>>>>>>>> +	int ret;
> >>>>>>>>> +
> >>>>>>>>>    	memset(fd, 0, sizeof(*fd));
> >>>>>>>>>    
> >>>>>>>>> -	return sd->ops->pad->get_frame_desc(sd, pad, fd);
> >>>>>>>>> +	ret = sd->ops->pad->get_frame_desc(sd, pad, fd);
> >>>>>>>>> +	if (ret)
> >>>>>>>>> +		return ret;
> >>>>>>>>> +
> >>>>>>>>> +	dev_dbg(sd->dev, "Frame descriptor on pad %u, type %s\n", pad,
> >>>>>>>>> +		fd->type == V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ? "parallel" :
> >>>>>>>>> +		fd->type == V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ? "CSI-2" :
> >>>>>>>>> +		"unknown");
> >>>>>>>>> +
> >>>>>>>>> +	for (i = 0; i < fd->num_entries; i++) {
> >>>>>>>>> +		struct v4l2_mbus_frame_desc_entry *entry = &fd->entry[i];
> >>>>>>>>> +		char buf[20] = "";
> >>>>>>>>
> >>>>>>>> Should this be sized for the worst case ? The vc and dt should not be
> >>>>>>>> large, but a buffer overflow on the stack in debug code if a subdev
> >>>>>>>> returns an incorrect value would be bad.
> >>>>>>>
> >>>>>>> 17 should be enough but it's not useful to use a size not divisible by 4 in
> >>>>>>> practice here.
> >>>>>>
> >>>>>> 18 with the terminating 0. But indeed, it's large enough as vc and dt
> >>>>>
> >>>>> I can count only 17 --- there's no newline.
> >>>>>
> >>>>> I guess it's most probably either of these then. X-)
> >>>>>
> >>>>>> are u8. I'm just a bit worried we're opening the door to hard to debug
> >>>>>> problems if we later change the vc and dt types.
> >>>>>
> >>>>> I can add a WARN_ON() to cover this.
> >>>>>
> >>>>>>>>> +
> >>>>>>>>> +		if (fd->type == V4L2_MBUS_FRAME_DESC_TYPE_CSI2)
> >>>>>>>>> +			snprintf(buf, sizeof(buf), ", vc %u, dt 0x%2.2x",
> >>>>>>>>
> >>>>>>>> 0x%02x would be one character shorter ;-) Same below.
> >>>>>>>
> >>>>>>> It would be, but I prefer the above notation as it's more generic.
> >>>>>>
> >>>>>> Out of curiosity, how so ?
> >>>>>
> >>>>> It works with data that would span more than 9 characters when printed.
> >>>>
> >>>> And 0x%02x doesn't ?
> >>>
> >>> Ah, it should indeed work, 0 is actually a flag here and part of the field
> >>> width or precision. I can use that in v4.
> >>
> >> Or %#04x, even shorter!
> > 
> > That's different though.
> > 
> > printf("0x%2.2x\n", 0);		-> 0x00
> > printf("0x%2.2x\n", 1);		-> 0x01
> > printf("0x%2.2x\n", 42);	-> 0x2a
> > 
> > printf("0x%02x\n", 0);		-> 0x00
> > printf("0x%02x\n", 1);		-> 0x01
> > printf("0x%02x\n", 42);		-> 0x2a
> > 
> > printf("%#2.2x\n", 0);		-> 00
> > printf("%#2.2x\n", 1);		-> 0x01
> > printf("%#2.2x\n", 42);		-> 0x2a
> > 
> > printf("%#02x\n", 0);		-> 00
> > printf("%#02x\n", 1);		-> 0x1
> > printf("%#02x\n", 42);		-> 0x2a
> 
> The length should be 4 there, not 2. But even after fixing that, the 0 
> case is printed wrong. Interesting, I haven't noticed that before. I 
> wonder why it behaves that way...

It's documented as such:

  #  The value should be converted to an "alternate form". [...] For x
     and X conversions, a nonzero result has the string "0x" (or "0X"
     for X conversions) prepended to it. [...]

> 0000
> 0x01
> 0x2a

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2023-09-22 14:51 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19 12:17 [PATCH v3 00/12] Small fixes and cleanups (ov2740 and ccs) Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 01/12] media: Documentation: Align numbered list, make it a proper ReST Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 02/12] media: ccs: Fix driver quirk struct documentation Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 03/12] media: ccs: Correctly initialise try compose rectangle Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 04/12] media: ccs: Correct error handling in ccs_register_subdev Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 05/12] media: ccs: Switch to init_cfg Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 06/12] media: ccs: Use sub-device active state Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 07/12] media: ov2740: Enable runtime PM before registering the async subdev Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 08/12] media: ov2740: Use sub-device active state Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 09/12] media: ov2740: Return -EPROBE_DEFER if no endpoint is found Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 10/12] media: v4l: subdev: Clear frame descriptor before get_frame_desc Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 11/12] media: v4l: subdev: Print debug information on frame descriptor Sakari Ailus
2023-09-19 13:32   ` Laurent Pinchart
2023-09-19 14:49     ` Sakari Ailus
2023-09-19 15:21       ` Laurent Pinchart
2023-09-22  9:41         ` Sakari Ailus
2023-09-22  9:53           ` Laurent Pinchart
2023-09-22 10:09             ` Sakari Ailus
2023-09-22 10:16               ` Tomi Valkeinen
2023-09-22 10:22                 ` Laurent Pinchart
2023-09-22 10:27                   ` Tomi Valkeinen
2023-09-22 14:51                     ` Laurent Pinchart [this message]
2023-09-22 10:23                 ` Sakari Ailus
2023-09-19 12:17 ` [PATCH v3 12/12] media: mc: Check pad flag validity Sakari Ailus
2023-09-19 13:26   ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230922145151.GI19112@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=bingbu.cao@intel.com \
    --cc=jacopo+renesas@jmondi.org \
    --cc=linux-media@vger.kernel.org \
    --cc=martink@posteo.de \
    --cc=rmfrfs@gmail.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tian.shu.qiu@intel.com \
    --cc=tomi.valkeinen@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox