From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org,
Mauro Carvalho Chehab <mchehab@infradead.org>,
Hans de Goede <hdegoede@redhat.com>,
Andy Walls <awalls@md.metrocast.net>,
Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
Pawel Osciak <pawel@osciak.com>,
Tomasz Stanislawski <t.stanislaws@samsung.com>,
Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [RFCv1 PATCH 04/32] v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality.
Date: Mon, 18 Jun 2012 11:47:07 +0200 [thread overview]
Message-ID: <6945599.iYfJgtEiGu@avalon> (raw)
In-Reply-To: <04d048ef96f333b1dfd644ee8861d81080123e01.1339321562.git.hans.verkuil@cisco.com>
Hi Hans,
Thanks for the patch.
On Sunday 10 June 2012 12:25:26 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
>
> Add the necessary plumbing to make it possible to replace the switch by a
> table driven implementation.
>
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
> drivers/media/video/v4l2-ioctl.c | 91
> ++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 13
> deletions(-)
>
> diff --git a/drivers/media/video/v4l2-ioctl.c
> b/drivers/media/video/v4l2-ioctl.c index a9602db..a4115ce 100644
> --- a/drivers/media/video/v4l2-ioctl.c
> +++ b/drivers/media/video/v4l2-ioctl.c
> @@ -396,12 +396,22 @@ struct v4l2_ioctl_info {
> unsigned int ioctl;
> u32 flags;
> const char * const name;
> + union {
> + u32 offset;
> + int (*func)(const struct v4l2_ioctl_ops *ops,
> + struct file *file, void *fh, void *p);
> + };
> + void (*debug)(const void *arg);
> };
>
> /* This control needs a priority check */
> #define INFO_FL_PRIO (1 << 0)
> /* This control can be valid if the filehandle passes a control handler. */
> #define INFO_FL_CTRL (1 << 1)
> +/* This is a standard ioctl, no need for special code */
> +#define INFO_FL_STD (1 << 2)
> +/* This is ioctl has its own function */
> +#define INFO_FL_FUNC (1 << 3)
> /* Zero struct from after the field to the end */
> #define INFO_FL_CLEAR(v4l2_struct, field) \
> ((offsetof(struct v4l2_struct, field) + \
> @@ -414,6 +424,24 @@ struct v4l2_ioctl_info {
> .name = #_ioctl, \
> }
>
> +#define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags) \
> + [_IOC_NR(_ioctl)] = { \
> + .ioctl = _ioctl, \
> + .flags = _flags | INFO_FL_STD, \
> + .name = #_ioctl, \
> + .offset = offsetof(struct v4l2_ioctl_ops, _vidioc), \
> + .debug = _debug, \
> + }
> +
> +#define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags) \
> + [_IOC_NR(_ioctl)] = { \
> + .ioctl = _ioctl, \
> + .flags = _flags | INFO_FL_FUNC, \
> + .name = #_ioctl, \
> + .func = _func, \
> + .debug = _debug, \
> + }
> +
> static struct v4l2_ioctl_info v4l2_ioctls[] = {
> IOCTL_INFO(VIDIOC_QUERYCAP, 0),
> IOCTL_INFO(VIDIOC_ENUM_FMT, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
> @@ -512,7 +540,7 @@ bool v4l2_is_known_ioctl(unsigned int cmd)
> external ioctl messages as well as internal V4L ioctl */
> void v4l_printk_ioctl(unsigned int cmd)
> {
> - char *dir, *type;
> + const char *dir, *type;
>
> switch (_IOC_TYPE(cmd)) {
> case 'd':
> @@ -523,10 +551,11 @@ void v4l_printk_ioctl(unsigned int cmd)
> type = "v4l2";
> break;
> }
> - printk("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
> + pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
> return;
> default:
> type = "unknown";
> + break;
> }
>
> switch (_IOC_DIR(cmd)) {
> @@ -536,7 +565,7 @@ void v4l_printk_ioctl(unsigned int cmd)
> case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
> default: dir = "*ERR*"; break;
> }
> - printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
> + pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
> type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
> }
> EXPORT_SYMBOL(v4l_printk_ioctl);
> @@ -546,6 +575,9 @@ static long __video_do_ioctl(struct file *file,
> {
> struct video_device *vfd = video_devdata(file);
> const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
> + bool write_only = false;
> + struct v4l2_ioctl_info default_info;
> + const struct v4l2_ioctl_info *info;
> void *fh = file->private_data;
> struct v4l2_fh *vfh = NULL;
> int use_fh_prio = 0;
> @@ -563,23 +595,40 @@ static long __video_do_ioctl(struct file *file,
> }
>
> if (v4l2_is_known_ioctl(cmd)) {
> - struct v4l2_ioctl_info *info = &v4l2_ioctls[_IOC_NR(cmd)];
> + info = &v4l2_ioctls[_IOC_NR(cmd)];
>
> if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
> !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
> - return -ENOTTY;
> + goto error;
>
> if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
> ret = v4l2_prio_check(vfd->prio, vfh->prio);
> if (ret)
> - return ret;
> + goto error;
> }
> + } else {
> + default_info.ioctl = cmd;
> + default_info.flags = 0;
> + default_info.debug = NULL;
> + info = &default_info;
> }
>
> - if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
> - !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
> + write_only = _IOC_DIR(cmd) == _IOC_WRITE;
> + if (info->debug && write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
> v4l_print_ioctl(vfd->name, cmd);
> - printk(KERN_CONT "\n");
> + pr_cont(": ");
> + info->debug(arg);
> + }
Shouldn't you print the ioctl name and information even if info->debug is NULL
?
> + if (info->flags & INFO_FL_STD) {
> + typedef int (*vidioc_op)(struct file *file, void *fh, void *p);
> + const void *p = vfd->ioctl_ops;
> + const vidioc_op *vidioc = p + info->offset;
> +
> + ret = (*vidioc)(file, fh, arg);
> + goto error;
> + } else if (info->flags & INFO_FL_FUNC) {
> + ret = info->func(ops, file, fh, arg);
> + goto error;
> }
>
> switch (cmd) {
> @@ -2100,10 +2149,26 @@ static long __video_do_ioctl(struct file *file,
> break;
> } /* switch */
>
> - if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
> - if (ret < 0) {
> - v4l_print_ioctl(vfd->name, cmd);
> - printk(KERN_CONT " error %ld\n", ret);
> +error:
This isn't an error, is it ? I'd call it done instead.
> + if (vfd->debug) {
> + if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
vfd->debug is a bitmask (or at least is documented as being a bitmask in
include/media/v4l2-ioctl.h).
> + if (ret)
Shouldn't you test for < 0 instead ? Driver-specific ioctls might return a > 0
value in case of success.
> + pr_info("%s: error %ld\n",
> + video_device_node_name(vfd), ret);
> + return ret;
> + }
> + v4l_print_ioctl(vfd->name, cmd);
> + if (ret)
> + pr_cont(": error %ld\n", ret);
> + else if (vfd->debug == V4L2_DEBUG_IOCTL)
> + pr_cont("\n");
> + else if (!info->debug)
> + return ret;
> + else if (_IOC_DIR(cmd) == _IOC_NONE)
> + info->debug(arg);
> + else {
> + pr_cont(": ");
> + info->debug(arg);
> }
Ouch. What are you trying to do here ? Can't we simplify debug messages ?
> }
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2012-06-18 9:46 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-10 10:25 [RFCv1 PATCH 00/32] Core and vb2 enhancements Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 02/32] v4l2-ioctl.c: move a block of code down, no other changes Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 03/32] v4l2-ioctl.c: introduce INFO_FL_CLEAR to replace switch Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 04/32] v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality Hans Verkuil
2012-06-18 9:47 ` Laurent Pinchart [this message]
2012-06-18 11:25 ` Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 05/32] v4l2-ioctl.c: remove an unnecessary #ifdef Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 06/32] v4l2-ioctl.c: use the new table for querycap and i/o ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 07/32] v4l2-ioctl.c: use the new table for priority ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 08/32] v4l2-ioctl.c: use the new table for format/framebuffer ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 09/32] v4l2-ioctl.c: use the new table for overlay/streamon/off ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 10/32] v4l2-ioctl.c: use the new table for std/tuner/modulator ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 11/32] v4l2-ioctl.c: use the new table for queuing/parm ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 12/32] v4l2-ioctl.c: use the new table for control ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 13/32] v4l2-ioctl.c: use the new table for selection ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 14/32] v4l2-ioctl.c: use the new table for compression ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 15/32] v4l2-ioctl.c: use the new table for debug ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 16/32] v4l2-ioctl.c: use the new table for preset/timings ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 17/32] v4l2-ioctl.c: use the new table for the remaining ioctls Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion Hans Verkuil
2012-06-18 9:46 ` Laurent Pinchart
2012-06-18 10:50 ` Mauro Carvalho Chehab
2012-06-18 11:03 ` Laurent Pinchart
2012-06-18 11:49 ` Hans Verkuil
2012-06-18 12:03 ` Mauro Carvalho Chehab
2012-06-18 12:22 ` Hans Verkuil
2012-06-18 11:17 ` Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 19/32] v4l2-dev.c: add debug sysfs entry Hans Verkuil
2012-06-18 9:48 ` Laurent Pinchart
2012-06-18 11:30 ` Hans Verkuil
2012-06-18 11:36 ` Laurent Pinchart
2012-06-10 10:25 ` [RFCv1 PATCH 20/32] v4l2-ioctl: remove v4l_(i2c_)print_ioctl Hans Verkuil
2012-06-18 9:50 ` Laurent Pinchart
2012-06-18 11:33 ` Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 21/32] ivtv: don't mess with vfd->debug Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 22/32] cx18: " Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 23/32] v4l2-dev/ioctl.c: add vb2_queue support to video_device Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 24/32] videobuf2-core: add helper functions Hans Verkuil
2012-06-18 10:23 ` Laurent Pinchart
2012-06-18 11:49 ` Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 25/32] create_bufs: handle count == 0 Hans Verkuil
2012-06-18 10:11 ` Laurent Pinchart
2012-06-18 11:43 ` Hans Verkuil
2012-06-18 12:20 ` Laurent Pinchart
2012-06-10 10:25 ` [RFCv1 PATCH 26/32] vivi: remove pointless g/s_std support Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 27/32] vivi: embed struct video_device instead of allocating it Hans Verkuil
2012-06-18 10:13 ` Laurent Pinchart
2012-06-18 11:44 ` Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 28/32] vivi: use vb2 helper functions Hans Verkuil
2012-06-18 10:08 ` Laurent Pinchart
2012-06-18 11:40 ` Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 29/32] v4l2-dev.c: also add debug support for the fops Hans Verkuil
2012-06-18 10:01 ` Laurent Pinchart
2012-06-18 11:40 ` Hans Verkuil
2012-06-18 12:19 ` Laurent Pinchart
2012-06-18 12:48 ` Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 30/32] v4l2-ioctl.c: shorten the lines of the table Hans Verkuil
2012-06-18 9:57 ` Laurent Pinchart
2012-06-18 11:34 ` Hans Verkuil
2012-06-18 12:15 ` Laurent Pinchart
2012-06-10 10:25 ` [RFCv1 PATCH 31/32] pwc: use the new vb2 helpers Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 32/32] pwc: v4l2-compliance fixes Hans Verkuil
2012-06-10 16:46 ` [RFCv1 PATCH 00/32] Core and vb2 enhancements Mauro Carvalho Chehab
2012-06-10 17:32 ` Hans Verkuil
2012-06-10 19:27 ` Hans Verkuil
2012-06-12 11:35 ` Mauro Carvalho Chehab
2012-06-12 13:21 ` Hans Verkuil
2012-06-12 13:24 ` Hans de Goede
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=6945599.iYfJgtEiGu@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=awalls@md.metrocast.net \
--cc=g.liakhovetski@gmx.de \
--cc=hans.verkuil@cisco.com \
--cc=hdegoede@redhat.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@infradead.org \
--cc=pawel@osciak.com \
--cc=t.stanislaws@samsung.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.