All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Alejandro Colomar <alx.manpages@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Kees Cook <keescook@chromium.org>, Joe Perches <joe@perches.com>
Subject: [PATCH v2 00/20] Add memberof(), split headers, and simplify code
Date: Sat, 20 Nov 2021 14:00:43 +0100	[thread overview]
Message-ID: <20211120130104.185699-1-alx.manpages@gmail.com> (raw)
In-Reply-To: <20211119113644.1600-1-alx.manpages@gmail.com>


Hi all,

I splitted some macros into separate headers,
to be able to use them
without pulling too many deps.

I also simplified some of themr
to be implemented in terms of the others
and to remove some unnecessary explicit casts.

And I added memberof(),
which gives name to a typical construction
to get the member of a struct
without needing a variable of that type.


The next step after this patch set
is another one removing all redefinitions
(at least all that are possible,
since these headers can't be included everywhere)
of these macros,
by including these new tiny headers.
Since these headers are so tiny and bring no dependencies,
they should break anything.

It was hard for me to get this working
because the order of includes _matters a lot_,
and which headers you include _matters_ even outside of uapi.
So I think this should help fix that,
by allowing headers to pull exactly what they want,
without all of the stuff that came with
<linux/compiler.h>
<linux/compiler_types.h>
<linux/stddef.h>.

I already have much of the next patch set ready,
and it removes hundreds of redefinitions of these macros,
which should be a good thing.


Then,
when there are (almost) no redefinitions of these macros,
I'll prepare a 3rd patch set that
explicitly includes these tiny headers
wherever these macros were already in use,
to allow for removal of other bigger headers
(although I won't remove anything,
to avoid silently breaking anything).


And then,
a 4th patch set will
attempt to find all uses of these macros
that were not even named
(i.e., hard-coded sizeof divisions).


Hope this is clear and
that you like these changes.


Cheers,
Alex


Alejandro Colomar (20):
  linux/stddef.h, linux/offsetof.h: Split offsetof() into a separate
    header
  linux/stddef.h, linux/sizeof_field.h: Split sizeof_field() into a
    separate header
  linux/stddef.h, linux/offsetofend.h: Split offsetofend() into a
    separate header
  linux/stddef.h, linux/NULL.h: Split NULL into a separate header
  linux/container_of.h, linux/typeof_member.h: Split typeof_member()
    into a separate header
  linux/kernel.h, linux/array_size.h: Split ARRAY_SIZE() into a separate
    header
  linux/memberof.h: Add memberof(T, m) macro
  Implement container_of_safe() in terms of container_of()
  Implement offsetof(), sizeof_member(), typeof_member(), and
    container_of() in terms of memberof()
  linux/container_of.h: Remove unnecessary cast
  linux/container_of.h: Cosmetic
  linux/must_be.h: Add must_be() to improve readability of
    BUILD_BUG_ON_ZERO()
  linux/build_bug.h, linux/must_be.h: Move BUILD_BUG_ON_ZERO to
    <linux/must_be.h>
  linux/compiler_types.h, linux/same_type.h: Split __same_type() to a
    separate header
  linux/compiler.h: Implement __must_be_array() in terms of __must_be()
  linux/compiler.h, linux/array_size.h: Move __must_be_array() into
    <linux/array_size.h>
  linux/array_size.h: Add __is_array(a) to help readability
  linux/power_of_2.h: Add __IS_POWER_OF_2(n) and __IS_POWER_OF_2_OR_0(n)
    macros
  linux/build_bug.h, linux/power_of_2.h: Move
    [__]BUILD_BUG_ON_NOT_POWER_OF_2() to <linux/power_of_2.h>
  linux/power_of_2.h: Implement [__]BUILD_BUG_ON_NOT_POWER_OF_2() in
    terms of __IS_POWER_OF_2[_OR_0]()

 drivers/gpu/drm/i915/i915_utils.h           |  3 ++
 drivers/net/can/usb/etas_es58x/es58x_core.h |  3 ++
 include/linux/NULL.h                        | 10 +++++++
 include/linux/array_size.h                  | 21 ++++++++++++++
 include/linux/build_bug.h                   | 20 ++-----------
 include/linux/compiler.h                    |  3 --
 include/linux/compiler_types.h              |  7 +++--
 include/linux/container_of.h                | 25 ++++++++--------
 include/linux/kernel.h                      |  9 ++----
 include/linux/memberof.h                    | 12 ++++++++
 include/linux/must_be.h                     | 21 ++++++++++++++
 include/linux/offsetof.h                    | 19 ++++++++++++
 include/linux/offsetofend.h                 | 19 ++++++++++++
 include/linux/overflow.h                    |  3 ++
 include/linux/power_of_2.h                  | 17 +++++++++++
 include/linux/same_type.h                   | 10 +++++++
 include/linux/sizeof_field.h                | 18 ++++++++++++
 include/linux/stddef.h                      | 32 ++++-----------------
 include/linux/typeof_member.h               | 12 ++++++++
 19 files changed, 197 insertions(+), 67 deletions(-)
 create mode 100644 include/linux/NULL.h
 create mode 100644 include/linux/array_size.h
 create mode 100644 include/linux/memberof.h
 create mode 100644 include/linux/must_be.h
 create mode 100644 include/linux/offsetof.h
 create mode 100644 include/linux/offsetofend.h
 create mode 100644 include/linux/power_of_2.h
 create mode 100644 include/linux/same_type.h
 create mode 100644 include/linux/sizeof_field.h
 create mode 100644 include/linux/typeof_member.h

-- 
2.33.1


  parent reply	other threads:[~2021-11-20 13:01 UTC|newest]

Thread overview: 144+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19 11:36 [PATCH 00/17] Add memberof(), split some headers, and slightly simplify code Alejandro Colomar
2021-11-19 11:36 ` [Intel-gfx] " Alejandro Colomar
2021-11-19 11:36 ` Alejandro Colomar
2021-11-19 11:36 ` [PATCH 01/17] linux/container_of.h: Add memberof(T, m) Alejandro Colomar
2021-11-19 11:36 ` [PATCH 02/17] Use memberof(T, m) instead of explicit NULL dereference Alejandro Colomar
2021-11-19 11:36   ` [Intel-gfx] " Alejandro Colomar
2021-11-19 11:36   ` Alejandro Colomar
2021-11-23 18:07   ` Rafael J. Wysocki
2021-11-23 18:07     ` Rafael J. Wysocki
2021-11-23 18:07     ` [Intel-gfx] " Rafael J. Wysocki
2021-11-23 18:07     ` Rafael J. Wysocki
2021-11-19 11:36 ` [PATCH 03/17] Replace some uses of memberof() by its wrappers Alejandro Colomar
2021-11-19 11:36 ` [PATCH 04/17] linux/memberof.h: Move memberof() to separate header Alejandro Colomar
2021-11-19 11:36 ` [PATCH 05/17] linux/typeof_member.h: Move typeof_member() to a " Alejandro Colomar
2021-11-19 11:36 ` [PATCH 06/17] Simplify sizeof(typeof_member()) to sizeof_field() Alejandro Colomar
2021-11-19 11:36 ` [PATCH 07/17] linux/NULL.h: Move NULL to a separate header Alejandro Colomar
2021-11-19 11:36 ` [PATCH 08/17] linux/offsetof.h: Move offsetof(T, m) " Alejandro Colomar
2021-11-19 11:36 ` [PATCH 09/17] linux/offsetof.h: Implement offsetof() in terms of memberof() Alejandro Colomar
2021-11-19 11:36 ` [PATCH 10/17] linux/container_of.h: Implement container_of_safe() in terms of container_of() Alejandro Colomar
2021-11-19 11:36 ` [PATCH 11/17] linux/container_of.h: Cosmetic Alejandro Colomar
2021-11-19 11:36 ` [PATCH 12/17] linux/container_of.h: Remove unnecessary cast to (void *) Alejandro Colomar
2021-11-19 11:36 ` [PATCH 13/17] linux/sizeof_field.h: Move sizeof_field(T, m) to a separate header Alejandro Colomar
2021-11-19 11:36 ` [PATCH 14/17] include/linux/: Include a smaller header if just for NULL Alejandro Colomar
2021-11-19 11:36 ` [PATCH 15/17] linux/offsetofend.h: Move offsetofend(T, m) to a separate header Alejandro Colomar
2021-11-19 11:36 ` [PATCH 16/17] linux/array_size.h: Move ARRAY_SIZE(arr) " Alejandro Colomar
2021-11-19 11:36 ` [PATCH 17/17] include/: Include <linux/array_size.h> for ARRAY_SIZE() Alejandro Colomar
2021-11-19 12:47 ` [PATCH 00/17] Add memberof(), split some headers, and slightly simplify code Jani Nikula
2021-11-19 12:47   ` Jani Nikula
2021-11-19 12:47   ` [Intel-gfx] " Jani Nikula
2021-11-19 12:47   ` Jani Nikula
2021-11-19 13:16   ` Alejandro Colomar (man-pages)
2021-11-19 13:16     ` [Intel-gfx] " Alejandro Colomar (man-pages)
2021-11-19 13:16     ` Alejandro Colomar (man-pages)
2021-11-19 13:48     ` Jani Nikula
2021-11-19 13:48       ` Jani Nikula
2021-11-19 13:48       ` [Intel-gfx] " Jani Nikula
2021-11-19 13:48       ` Jani Nikula
2021-11-19 14:54     ` Andy Shevchenko
2021-11-19 14:54       ` Andy Shevchenko
2021-11-19 14:54       ` [Intel-gfx] " Andy Shevchenko
2021-11-19 14:54       ` Andy Shevchenko
2021-11-19 14:47 ` Arnd Bergmann
2021-11-19 14:47   ` [Intel-gfx] " Arnd Bergmann
2021-11-19 14:47   ` Arnd Bergmann
2021-11-19 14:47   ` Arnd Bergmann
2021-11-19 15:06   ` Alejandro Colomar (man-pages)
2021-11-19 15:06     ` [Intel-gfx] " Alejandro Colomar (man-pages)
2021-11-19 15:06     ` Alejandro Colomar (man-pages)
2021-11-19 15:34     ` Andy Shevchenko
2021-11-19 15:34       ` Andy Shevchenko
2021-11-19 15:34       ` [Intel-gfx] " Andy Shevchenko
2021-11-19 15:34       ` Andy Shevchenko
2021-11-19 15:38       ` Alejandro Colomar (man-pages)
2021-11-19 15:38         ` Alejandro Colomar (man-pages)
2021-11-19 15:38         ` [Intel-gfx] " Alejandro Colomar (man-pages)
2021-11-19 15:43         ` Alejandro Colomar (man-pages)
2021-11-19 15:49           ` Andy Shevchenko
2021-11-19 15:52             ` Alejandro Colomar (man-pages)
2021-11-19 16:07               ` Andy Shevchenko
2021-11-19 15:57     ` Arnd Bergmann
2021-11-19 15:57       ` [Intel-gfx] " Arnd Bergmann
2021-11-19 15:57       ` Arnd Bergmann
2021-11-19 15:57       ` Arnd Bergmann
2021-11-19 16:10       ` Andy Shevchenko
2021-11-19 16:10         ` Andy Shevchenko
2021-11-19 16:10         ` Andy Shevchenko
2021-11-19 16:10         ` [Intel-gfx] " Andy Shevchenko
2021-11-19 16:18         ` Arnd Bergmann
2021-11-19 16:18           ` Arnd Bergmann
2021-11-19 16:18           ` [Intel-gfx] " Arnd Bergmann
2021-11-19 16:18           ` Arnd Bergmann
2021-11-19 16:22           ` Alejandro Colomar (man-pages)
2021-11-19 16:22             ` Alejandro Colomar (man-pages)
2021-11-19 16:22             ` [Intel-gfx] " Alejandro Colomar (man-pages)
2021-11-19 16:27             ` Arnd Bergmann
2021-11-19 16:27               ` Arnd Bergmann
2021-11-19 16:27               ` [Intel-gfx] " Arnd Bergmann
2021-11-19 16:27               ` Arnd Bergmann
2021-11-19 16:35             ` Andy Shevchenko
2021-11-19 16:35               ` Andy Shevchenko
2021-11-19 16:35               ` [Intel-gfx] " Andy Shevchenko
2021-11-19 16:35               ` Andy Shevchenko
2021-11-22 12:36               ` Jonathan Cameron
2021-11-22 12:36                 ` [Intel-gfx] " Jonathan Cameron
2021-11-22 12:36                 ` Jonathan Cameron
2021-11-19 16:12       ` Alejandro Colomar (man-pages)
2021-11-19 16:12         ` Alejandro Colomar (man-pages)
2021-11-19 16:12         ` [Intel-gfx] " Alejandro Colomar (man-pages)
2021-11-19 16:25         ` Arnd Bergmann
2021-11-19 16:25           ` Arnd Bergmann
2021-11-19 16:25           ` Arnd Bergmann
2021-11-19 16:25           ` [Intel-gfx] " Arnd Bergmann
2021-11-19 16:37         ` Andy Shevchenko
2021-11-19 16:37           ` Andy Shevchenko
2021-11-19 16:37           ` [Intel-gfx] " Andy Shevchenko
2021-11-19 16:37           ` Andy Shevchenko
2021-11-19 16:49           ` Alejandro Colomar (man-pages)
2021-11-20 13:00 ` Alejandro Colomar [this message]
2021-11-20 13:00   ` [PATCH v2 01/20] linux/stddef.h, linux/offsetof.h: Split offsetof() into a separate header Alejandro Colomar
2021-11-20 16:14     ` Andy Shevchenko
2021-11-20 16:22       ` Alejandro Colomar (man-pages)
2021-11-20 13:00   ` [PATCH v2 02/20] linux/stddef.h, linux/sizeof_field.h: Split sizeof_field() " Alejandro Colomar
2021-11-20 16:16     ` Andy Shevchenko
2021-11-20 13:00   ` [PATCH v2 03/20] linux/stddef.h, linux/offsetofend.h: Split offsetofend() " Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 04/20] linux/stddef.h, linux/NULL.h: Split NULL " Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 05/20] linux/container_of.h, linux/typeof_member.h: Split typeof_member() " Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 06/20] linux/kernel.h, linux/array_size.h: Split ARRAY_SIZE() " Alejandro Colomar
2021-11-22  7:36     ` kernel test robot
2021-11-22  7:36       ` kernel test robot
2021-11-20 13:00   ` [PATCH v2 07/20] linux/memberof.h: Add memberof(T, m) macro Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 08/20] Implement container_of_safe() in terms of container_of() Alejandro Colomar
2021-11-21 13:31     ` Arnd Bergmann
2021-11-20 13:00   ` [PATCH v2 09/20] Implement offsetof(), sizeof_member(), typeof_member(), and container_of() in terms of memberof() Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 10/20] linux/container_of.h: Remove unnecessary cast Alejandro Colomar
2021-11-20 19:05     ` kernel test robot
2021-11-20 19:05       ` kernel test robot
2021-11-22 17:39     ` kernel test robot
2021-11-22 17:39       ` kernel test robot
2021-11-20 13:00   ` [PATCH v2 11/20] linux/container_of.h: Cosmetic Alejandro Colomar
2021-11-20 16:12     ` Andy Shevchenko
2021-11-20 16:33       ` Joe Perches
2021-11-20 16:44         ` Alejandro Colomar (man-pages)
2021-11-20 13:00   ` [PATCH v2 12/20] linux/must_be.h: Add must_be() to improve readability of BUILD_BUG_ON_ZERO() Alejandro Colomar
2021-11-20 15:05     ` Alexey Dobriyan
2021-11-20 15:22       ` Alejandro Colomar (man-pages)
2021-11-21 13:18       ` Arnd Bergmann
2021-11-20 13:00   ` [PATCH v2 13/20] Move BUILD_BUG_ON_ZERO to <linux/must_be.h> Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 13/20] linux/build_bug.h, linux/must_be.h: " Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 14/20] linux/compiler_types.h, linux/same_type.h: Split __same_type() to a separate header Alejandro Colomar
2021-11-21 13:26     ` Arnd Bergmann
2021-11-20 13:00   ` [PATCH v2 15/20] linux/compiler.h: Implement __must_be_array() in terms of __must_be() Alejandro Colomar
2021-11-21 13:25     ` Arnd Bergmann
2021-11-20 13:01   ` [PATCH v2 16/20] linux/compiler.h, linux/array_size.h: Move __must_be_array() into <linux/array_size.h> Alejandro Colomar
2021-11-21 13:24     ` Arnd Bergmann
2021-11-22  8:51       ` Jani Nikula
2021-11-20 13:01   ` [PATCH v2 17/20] linux/array_size.h: Add __is_array(a) to help readability Alejandro Colomar
2021-11-21 13:22     ` Arnd Bergmann
2021-11-20 13:01   ` [PATCH v2 18/20] linux/power_of_2.h: Add __IS_POWER_OF_2(n) and __IS_POWER_OF_2_OR_0(n) macros Alejandro Colomar
2021-11-21 13:20     ` Arnd Bergmann
2021-11-22  8:55       ` Jani Nikula
2021-11-20 13:01   ` [PATCH v2 19/20] linux/build_bug.h, linux/power_of_2.h: Move [__]BUILD_BUG_ON_NOT_POWER_OF_2() to <linux/power_of_2.h> Alejandro Colomar
2021-11-20 13:01   ` [PATCH v2 20/20] linux/power_of_2.h: Implement [__]BUILD_BUG_ON_NOT_POWER_OF_2() in terms of __IS_POWER_OF_2[_OR_0]() Alejandro Colomar
2021-11-22 11:17   ` [PATCH v2 00/20] Add memberof(), split headers, and simplify code Andy Shevchenko
2021-11-22 12:07     ` Alejandro Colomar (man-pages)

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=20211120130104.185699-1-alx.manpages@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=jani.nikula@linux.intel.com \
    --cc=joe@perches.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /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.