Skip to contentSkip to conversation

Add dprintk calls for control validation in v4l2-ctrls.c?

DISCUSSION Daniel Almeida 2 participants 2 messages Apr 27, 2021 – Apr 28, 2021 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

Hi Hans, Ezequiel & all.

I find it a bit hard to debug my own code when it invariably sneaks in a bad control value with the VIDIOC_S_EXT_CTRLS ioctl.

I feel that it would be tremendously beneficial to encourage the use of dprintk calls in v4l2-ctrls.c to inform the user about what pieces of data were actually rejected in the validation functions.

#define dprintk(vdev, fmt, arg...) do {					\
	if (!WARN_ON(!(vdev)) && ((vdev)->dev_debug & V4L2_DEV_DEBUG_CTRL)) \
		printk(KERN_DEBUG pr_fmt("%s: %s: " fmt),		\
		       __func__, video_device_node_name(vdev), ##arg);	

Unfortunately the dprintk macro above takes a pointer to struct video_device as argument. This is not available in the places I want to actually place the calls, as far as I could tell.

E.g. here:

static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
union v4l2_ctrl_ptr ptr)

I'd like to make the changes to make this possible, if any, or be pointed at another solution if there is one - such as calling pr_err directly or something along these lines - please.

Kindly advise?

-- thanks
-- Daniel

#1 lore raw

Hi Daniel,

Quoted 9 lines · Daniel Almeida

Hi Hans, Ezequiel & all.

I find it a bit hard to debug my own code when it invariably sneaks in a bad control value with the VIDIOC_S_EXT_CTRLS ioctl.

I feel that it would be tremendously beneficial to encourage the use of dprintk calls in v4l2-ctrls.c to inform the user about what pieces of data were actually rejected in the validation functions.

Makes sense!

Quoted 11 lines
#define dprintk(vdev, fmt, arg...) do {					\
	if (!WARN_ON(!(vdev)) && ((vdev)->dev_debug & V4L2_DEV_DEBUG_CTRL)) \
		printk(KERN_DEBUG pr_fmt("%s: %s: " fmt),		\
		       __func__, video_device_node_name(vdev), ##arg);	

Unfortunately the dprintk macro above takes a pointer to struct video_device as argument. This is not available in the places I want to actually place the calls, as far as I could tell.

Quoted 8 lines

E.g. here:

static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
union v4l2_ctrl_ptr ptr)

I'd like to make the changes to make this possible, if any, or be pointed at another solution if there is one - such as calling pr_err directly or something along these lines - please.

I have no problem with changing the prototypes to pass a vdev pointer along. The validate_new function is the starting point for that.

However, keep in mind that it can also be called from a driver via e.g. __v4l2_ctrl_s_ctrl(), in which case there is no video_device, so the debug code has to be able to handle the case where vdev == NULL, and not do a WARN_ON in that case.

I would postpone working on this though. Early in the next cycle I want to merge a large refactor patch found here:

https://git.linuxtv.org/hverkuil/media_tree.git/log/?h=ctrl-refactor

where v4l2-ctrls.c is split up in several pieces. I suggest you wait until that's merged before making patches for the control framework.

Regards,

Hans

Quoted 6 lines

Kindly advise?

-- thanks
-- Daniel