2024-01-07 01:24:18

by Randy Dunlap

[permalink] [raw]
Subject: [PATCH v2] doc-guide: kernel-doc: tell about object-like macros

Since 2014 kernel-doc has supported describing object-like macros
but it is not documented anywhere. I should have required some
documentation for it when I merged the patch. :(

There are currently only 3 uses of this (all in DRM headers, in
include/drm/*.h).

Add object-like macro kernel-doc documentation now so that more may
know about it and use it.

Fixes: cbb4d3e6510b ("scripts/kernel-doc: handle object-like macros")
Signed-off-by: Randy Dunlap <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Cc: [email protected]
---
v2: Previous attempts to use kernel-doc were for data definitions,
not macros, so remove that comment.
Remove a duplicate word in the patch description.
Add examples.

Documentation/doc-guide/kernel-doc.rst | 45 +++++++++++++++++++++++
1 file changed, 45 insertions(+)

diff -- a/Documentation/doc-guide/kernel-doc.rst b/Documentation/doc-guide/kernel-doc.rst
--- a/Documentation/doc-guide/kernel-doc.rst
+++ b/Documentation/doc-guide/kernel-doc.rst
@@ -341,6 +341,51 @@ Typedefs with function prototypes can al
*/
typedef void (*type_name)(struct v4l2_ctrl *arg1, void *arg2);

+Object-like macro documentation
+-------------------------------
+
+Object-like macros are distinct from function-like macros. They are
+differentiated by whether the macro name is immediately followed by a
+left parenthesis ('(') for function-like macros or not followed by one
+for object-like macros.
+
+Function-like macros are handled like functions by ``scripts/kernel-doc``.
+They may have a parameter list. Object-like macros have do not have a
+parameter list.
+
+The general format of an object-like macro kernel-doc comment is::
+
+ /**
+ * define object_name - Brief description.
+ *
+ * Description of the object.
+ */
+
+Example::
+
+ /**
+ * define MAX_ERRNO - maximum errno value that is supported
+ *
+ * Kernel pointers have redundant information, so we can use a
+ * scheme where we can return either an error code or a normal
+ * pointer with the same return value.
+ */
+ #define MAX_ERRNO 4095
+
+Example::
+
+ /**
+ * define DRM_GEM_VRAM_PLANE_HELPER_FUNCS - \
+ * Initializes struct drm_plane_helper_funcs for VRAM handling
+ *
+ * This macro initializes struct drm_plane_helper_funcs to use the
+ * respective helper functions.
+ */
+ #define DRM_GEM_VRAM_PLANE_HELPER_FUNCS \
+ .prepare_fb = drm_gem_vram_plane_helper_prepare_fb, \
+ .cleanup_fb = drm_gem_vram_plane_helper_cleanup_fb
+
+
Highlights and cross-references
-------------------------------



2024-01-09 15:48:31

by Daniel Vetter

[permalink] [raw]
Subject: Re: [PATCH v2] doc-guide: kernel-doc: tell about object-like macros

On Sun, 7 Jan 2024 at 02:24, Randy Dunlap <[email protected]> wrote:
>
> Since 2014 kernel-doc has supported describing object-like macros
> but it is not documented anywhere. I should have required some
> documentation for it when I merged the patch. :(
>
> There are currently only 3 uses of this (all in DRM headers, in
> include/drm/*.h).
>
> Add object-like macro kernel-doc documentation now so that more may
> know about it and use it.
>
> Fixes: cbb4d3e6510b ("scripts/kernel-doc: handle object-like macros")
> Signed-off-by: Randy Dunlap <[email protected]>
> Cc: Jonathan Corbet <[email protected]>
> Cc: [email protected]
> ---
> v2: Previous attempts to use kernel-doc were for data definitions,
> not macros, so remove that comment.
> Remove a duplicate word in the patch description.
> Add examples.

Randy pointed to this in another thread and also mentioned that
function-like macros are already documented, so this also has my

Acked-by: Daniel Vetter <[email protected]>


>
> Documentation/doc-guide/kernel-doc.rst | 45 +++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff -- a/Documentation/doc-guide/kernel-doc.rst b/Documentation/doc-guide/kernel-doc.rst
> --- a/Documentation/doc-guide/kernel-doc.rst
> +++ b/Documentation/doc-guide/kernel-doc.rst
> @@ -341,6 +341,51 @@ Typedefs with function prototypes can al
> */
> typedef void (*type_name)(struct v4l2_ctrl *arg1, void *arg2);
>
> +Object-like macro documentation
> +-------------------------------
> +
> +Object-like macros are distinct from function-like macros. They are
> +differentiated by whether the macro name is immediately followed by a
> +left parenthesis ('(') for function-like macros or not followed by one
> +for object-like macros.
> +
> +Function-like macros are handled like functions by ``scripts/kernel-doc``.
> +They may have a parameter list. Object-like macros have do not have a
> +parameter list.
> +
> +The general format of an object-like macro kernel-doc comment is::
> +
> + /**
> + * define object_name - Brief description.
> + *
> + * Description of the object.
> + */
> +
> +Example::
> +
> + /**
> + * define MAX_ERRNO - maximum errno value that is supported
> + *
> + * Kernel pointers have redundant information, so we can use a
> + * scheme where we can return either an error code or a normal
> + * pointer with the same return value.
> + */
> + #define MAX_ERRNO 4095
> +
> +Example::
> +
> + /**
> + * define DRM_GEM_VRAM_PLANE_HELPER_FUNCS - \
> + * Initializes struct drm_plane_helper_funcs for VRAM handling
> + *
> + * This macro initializes struct drm_plane_helper_funcs to use the
> + * respective helper functions.
> + */
> + #define DRM_GEM_VRAM_PLANE_HELPER_FUNCS \
> + .prepare_fb = drm_gem_vram_plane_helper_prepare_fb, \
> + .cleanup_fb = drm_gem_vram_plane_helper_cleanup_fb
> +
> +
> Highlights and cross-references
> -------------------------------
>
>


--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

2024-01-30 20:31:58

by Jonathan Corbet

[permalink] [raw]
Subject: Re: [PATCH v2] doc-guide: kernel-doc: tell about object-like macros

Daniel Vetter <[email protected]> writes:

> On Sun, 7 Jan 2024 at 02:24, Randy Dunlap <[email protected]> wrote:
>>
>> Since 2014 kernel-doc has supported describing object-like macros
>> but it is not documented anywhere. I should have required some
>> documentation for it when I merged the patch. :(
>>
>> There are currently only 3 uses of this (all in DRM headers, in
>> include/drm/*.h).
>>
>> Add object-like macro kernel-doc documentation now so that more may
>> know about it and use it.
>>
>> Fixes: cbb4d3e6510b ("scripts/kernel-doc: handle object-like macros")
>> Signed-off-by: Randy Dunlap <[email protected]>
>> Cc: Jonathan Corbet <[email protected]>
>> Cc: [email protected]
>> ---
>> v2: Previous attempts to use kernel-doc were for data definitions,
>> not macros, so remove that comment.
>> Remove a duplicate word in the patch description.
>> Add examples.
>
> Randy pointed to this in another thread and also mentioned that
> function-like macros are already documented, so this also has my
>
> Acked-by: Daniel Vetter <[email protected]>

OK, I'm slowly catching up with the world...I've applied this in favor
of Daniel's version.

Thanks,

jon