All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@s-opensource.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Sakari Ailus <sakari.ailus@iki.fi>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Tomasz Figa <tfiga@chromium.org>,
	Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>,
	Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH 2/8] media: v4l2-ioctl.h: convert debug into an enum of bits
Date: Wed, 20 Dec 2017 11:34:36 -0200	[thread overview]
Message-ID: <20171220113436.6f1f40eb@vento.lan> (raw)
In-Reply-To: <2495011.azrSBV26NO@avalon>

Em Wed, 20 Dec 2017 12:47:23 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Tuesday, 19 December 2017 17:34:46 EET Mauro Carvalho Chehab wrote:
> > Em Tue, 19 Dec 2017 16:05:46 +0200 Laurent Pinchart escreveu:  
> > > On Tuesday, 19 December 2017 16:02:02 EET Laurent Pinchart wrote:  
> > >> On Tuesday, 19 December 2017 13:39:27 EET Sakari Ailus wrote:  
> > >>> On Mon, Dec 18, 2017 at 05:53:56PM -0200, Mauro Carvalho Chehab wrote:  
> > >>>> The V4L2_DEV_DEBUG_IOCTL macros actually define a bitmask,
> > >>>> but without using Kernel's modern standards. Also,
> > >>>> documentation looks akward.
> > >>>> 
> > >>>> So, convert them into an enum with valid bits, adding
> > >>>> the correspoinding kernel-doc documentation for it.  
> > >>> 
> > >>> The pattern of using bits for flags is a well established one and I
> > >>> wouldn't deviate from that by requiring the use of the BIT() macro.
> > >>> There are no benefits that I can see from here but the approach brings
> > >>> additional risks: misuse of the flags and mimicing the same risky
> > >>> pattern.
> > >>> 
> > >>> I'd also like to echo Laurent's concern that code is being changed in
> > >>> odd ways and not for itself, but due to deficiencies in documentation
> > >>> tools.
> > >>> 
> > >>> I believe the tooling has to be improved to address this properly.
> > >>> That only needs to done once, compared to changing all flag
> > >>> definitions to enums.  
> > >> 
> > >> That's my main concern too. We really must not sacrifice code
> > >> readability or writing ease in order to work around limitations of the
> > >> documentation system. For this reason I'm strongly opposed to patches 2
> > >> and 5 in this series.  
> > > 
> > > And I forgot to mention patch 8/8. Let's drop those three and improve the
> > > documentation system instead.  
> > 
> > Are you volunteering yourself to write the kernel-doc patches? :-)  
> 
> I thought you were the expert in this field, given the number of documentation 
> patches that you have merged in the kernel ? :-)

c/c linux-doc, as this kind of discussion should be happening there.

Let me recap your proposal here, for the others from linux-doc to
understand this reply:

Em Mon, 18 Dec 2017 17:32:11 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Monday, 18 December 2017 17:13:26 EET Mauro Carvalho Chehab wrote:
> > Em Fri, 13 Oct 2017 15:38:11 +0300 Laurent Pinchart escreveu:  
> > > On Thursday, 28 September 2017 00:46:51 EEST Mauro Carvalho Chehab wrote:  
> > >> Currently, there's no way to document #define foo <value>
> > >> with kernel-doc. So, convert it to an enum, and document.  
> > > 
> > > The documentation seems fine to me (except for one comment below).
> > > However, converting macros to an enum just to work around a defect of the
> > > documentation system doesn't seem like a good idea to me. I'd rather find
> > > a way to document macros.  
> > 
> > I agree that this limitation should be fixed.
> > 
> > Yet, in this specific case where we have an "array" of defines, all
> > associated to the same field (even being a bitmask), and assuming that
> > we would add a way for kernel-doc to parse this kind of defines
> > (not sure how easy/doable would be), then, in order to respect the
> > way kernel-doc markup is, the documentation for those macros would be:
> > 
> > 
> > /**
> >  * define: Just log the ioctl name + error code
> >  */
> > #define V4L2_DEV_DEBUG_IOCTL		0x01
> > /**
> >  * define: Log the ioctl name arguments + error code
> >  */
> > #define V4L2_DEV_DEBUG_IOCTL_ARG	0x02
> > /**
> >  * define: Log the file operations open, release, mmap and get_unmapped_area
> > */
> > #define V4L2_DEV_DEBUG_FOP		0x04
> > /**
> >  * define: Log the read and write file operations and the VIDIOC_(D)QBUF
> > ioctls */
> > #define V4L2_DEV_DEBUG_STREAMING	0x08
> > 
> > IMHO, this is a way easier to read/understand by humans, and a way more
> > coincise:
> > 
> > /**
> >  * enum v4l2_debug_flags - Device debug flags to be used with the video
> >  *	device debug attribute
> >  *
> >  * @V4L2_DEV_DEBUG_IOCTL:	Just log the ioctl name + error code.
> >  * @V4L2_DEV_DEBUG_IOCTL_ARG:	Log the ioctl name arguments + error code.
> >  * @V4L2_DEV_DEBUG_FOP:		Log the file operations and open, release,
> >  *				mmap and get_unmapped_area syscalls.
> >  * @V4L2_DEV_DEBUG_STREAMING:	Log the read and write syscalls and
> >  *				:c:ref:`VIDIOC_[Q|DQ]BUFF <VIDIOC_QBUF>` ioctls.
> >  */
> > 
> > It also underlines the aspect that those names are grouped altogether.
> > 
> > So, IMHO, the main reason to place them inside an enum and document
> > as such is that it looks a way better for humans to read.  
> 
> As we're talking about extending kerneldoc to document macros, we're free to 
> decide on a format that would make it easy and clear. Based on your above 
> example, we could write it
> 
> /**
>  * define v4l2_debug_flags - Device debug flags to be used with the video
>  *	device debug attribute
>  *
>  * @V4L2_DEV_DEBUG_IOCTL:	Just log the ioctl name + error code.
>  * @V4L2_DEV_DEBUG_IOCTL_ARG:	Log the ioctl name arguments + error code.
>  * @V4L2_DEV_DEBUG_FOP:		Log the file operations and open, release,
>  *				mmap and get_unmapped_area syscalls.
>  * @V4L2_DEV_DEBUG_STREAMING:	Log the read and write syscalls and
>  *				:c:ref:`VIDIOC_[Q|DQ]BUFF <VIDIOC_QBUF>` ioctls.
>  */
> 
> That would be simple, clear, and wouldn't require a code change to workaround 
> a limitation of the documentation system.
> 

I could volunteer myself to write a patch that would just parse a single
define when I have some time for that, and after finishing to document
other things that don't depend on it.

However, I won't volunteer to add a patch that would artificially
group #defines on a single kernel-doc markup, because:

1) I don't believe that this is the right solution. When several
   name macros should be grouped altogether, C provides an specific
   syntax for it: enum;
2) the patch will likely be very complex;
3) the define "grouping" logic would be based on hints.

Let me explain (3) a little better. Right now, kernel-doc common
logic removes any comments and blank lines when processing a single
markup, like struct, enum, function, etc. It should very likely need
to do the same for #defines.

Using your proposed, syntax, please assume the following fictional
(but based on real code) example:

	/**
	 * define v4l2_debug_flags - Device debug flags to be used with the video
	 *	device debug attribute
	 *
	 * @V4L2_DEV_DEBUG_IOCTL:	Just log the ioctl name + error code.
	 * @V4L2_DEV_DEBUG_IOCTL_ARG:	Log the ioctl name arguments + error code.
	 * @V4L2_DEV_DEBUG_FOP:		Log the file operations and open, release,
	 *				mmap and get_unmapped_area syscalls.
	 * @V4L2_DEV_DEBUG_STREAMING:	Log the read and write syscalls and
	 *				:c:ref:`VIDIOC_[Q|DQ]BUFF <VIDIOC_QBUF>` ioctls.
	 */

	/* ioctl debug macros */
	#define V4L2_DEV_DEBUG_IOCTL         0x01
	#define V4L2_DEV_DEBUG_IOCTL_ARG     0x02

	/* streaming debug macros */
	#define V4L2_DEV_DEBUG_FOP           0x04
	#define V4L2_DEV_DEBUG_STREAMING     0x08

	#define CEC_NUM_CORE_EVENTS 2
	#define CEC_NUM_EVENTS CEC_EVENT_PIN_CEC_HIGH

The V4L_DEV_DEBUG_* macros will be properly documented using your
notation.

However, how the kernel-doc logic will know when to stop grouping defines?

It should be reminded that, if later someone adds a new V4L_DEV_DEBUG_FOO
(either after V4L2_DEV_DEBUG_STREAMING or before it), we want a warning to
be generated, because something that belongs to this define "group"
was added without documentation.

It might be parsing by name, but that would break if someone ever adds a
macro like: V4L2_NODEV_DEBUG, it won't work (we do have some
"namespaces" like that). It would also fail if someone adds an unrelated
macro that would start with V4L2_DEV_DEBUG_.

Now, assume that, sometime in the future, we decide to also document
CEC_NUM_CORE_EVENTS, because it is now part of a kAPI, but we don't
want to document CEC_NUM_EVENTS, with is just an ancillary macro 
to be used internally.  The "group" define syntax won't fit.

In summary, trying to artificially group #defines for documentation is
a very dirty hack. We should really use enums on all kAPI cases where
we have different symbols that should be grouped altogether.

Regards,
Mauro

  reply	other threads:[~2017-12-20 13:34 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-18 19:53 [PATCH 0/8] Some V4L2 documentation pending patches Mauro Carvalho Chehab
2017-12-18 19:53 ` [PATCH 1/8] media: v4l2-device.h: document helper macros Mauro Carvalho Chehab
2017-12-18 19:53 ` [PATCH 2/8] media: v4l2-ioctl.h: convert debug into an enum of bits Mauro Carvalho Chehab
2017-12-19 11:39   ` Sakari Ailus
2017-12-19 14:02     ` Laurent Pinchart
2017-12-19 14:05       ` Laurent Pinchart
2017-12-19 15:34         ` Mauro Carvalho Chehab
2017-12-20 10:47           ` Laurent Pinchart
2017-12-20 13:34             ` Mauro Carvalho Chehab [this message]
2017-12-19 14:12       ` Sakari Ailus
2017-12-19 15:37         ` Mauro Carvalho Chehab
2017-12-19 17:17           ` Laurent Pinchart
2017-12-19 19:20             ` Mauro Carvalho Chehab
2017-12-18 19:53 ` [PATCH 3/8] media: v4l2-async: simplify v4l2_async_subdev structure Mauro Carvalho Chehab
2017-12-18 19:53   ` Mauro Carvalho Chehab
2017-12-18 19:53   ` Mauro Carvalho Chehab
2017-12-18 20:01   ` Benoit Parrot
2017-12-18 20:01     ` Benoit Parrot
2017-12-18 20:01     ` Benoit Parrot
2017-12-18 22:27   ` Alexandre Belloni
2017-12-18 22:27     ` Alexandre Belloni
2017-12-18 22:27     ` Alexandre Belloni
2017-12-19  8:27   ` Sakari Ailus
2017-12-19  8:27     ` Sakari Ailus
2017-12-19  8:27     ` Sakari Ailus
2017-12-19  9:16   ` Philipp Zabel
2017-12-19  9:16     ` Philipp Zabel
2017-12-19  9:16     ` Philipp Zabel
2017-12-18 19:53 ` [PATCH 4/8] media: v4l2-async: better describe match union at async match struct Mauro Carvalho Chehab
2017-12-18 19:53 ` [PATCH 5/8] media: v4l2-mediabus: convert flags to enums and document them Mauro Carvalho Chehab
2017-12-19  9:30   ` Philipp Zabel
2017-12-19 11:11     ` Mauro Carvalho Chehab
2017-12-18 19:54 ` [PATCH 6/8] media: v4l2-subdev: get rid of __V4L2_SUBDEV_MK_GET_TRY() macro Mauro Carvalho Chehab
2017-12-18 19:54 ` [PATCH 7/8] media: v4l2-subdev: document remaining undocumented functions Mauro Carvalho Chehab
2017-12-18 19:54 ` [PATCH 8/8] media: v4l2-subdev: use kernel-doc markups to document subdev flags Mauro Carvalho Chehab

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=20171220113436.6f1f40eb@vento.lan \
    --to=mchehab@s-opensource.com \
    --cc=hans.verkuil@cisco.com \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mchehab@infradead.org \
    --cc=ramesh.shanmugasundaram@bp.renesas.com \
    --cc=ricardo.ribalda@gmail.com \
    --cc=sakari.ailus@iki.fi \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tfiga@chromium.org \
    /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.