Skip to content

Add memberof(), split headers, and simplify code

Alejandro Colomar intel-gfx linux-acpi linux-arm-kernel linux-btrfs linux-scsi lkml netdev oe-kbuild-all virtualization 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest20 patches 19 repliesIn review
  2. v117 patches 24 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/20linux/stddef.h, linux/offsetof.h: Split offsetof() into a separate headerinclude/linux/offsetof.h include/linux/stddef.h+21 -72 replies
2/20linux/stddef.h, linux/sizeof_field.h: Split sizeof_field() into a separate headerinclude/linux/sizeof_field.h include/linux/stddef.h+16 -81 reply
3/20linux/stddef.h, linux/offsetofend.h: Split offsetofend() into a separate headerinclude/linux/offsetofend.h include/linux/stddef.h+20 -90 replies
4/20linux/stddef.h, linux/NULL.h: Split NULL into a separate headerinclude/linux/NULL.h include/linux/stddef.h+11 -30 replies
5/20linux/container_of.h, linux/typeof_member.h: Split typeof_member() into a separate headerinclude/linux/container_of.h include/linux/typeof_member.h+11 -10 replies
6/20linux/kernel.h, linux/array_size.h: Split ARRAY_SIZE() into a separate headerinclude/linux/array_size.h include/linux/kernel.h+18 -60 replies
7/20linux/memberof.h: Add memberof(T, m) macroinclude/linux/memberof.h+12 -00 replies
8/20Implement container_of_safe() in terms of container_of()include/linux/container_of.h+2 -71 reply
9/20Implement offsetof(), sizeof_member(), typeof_member(), and container_of() in terms of memberof()include/linux/container_of.h include/linux/offsetof.h include/linux/sizeof_field.h +1 more+13 -40 replies
10/20linux/container_of.h: Remove unnecessary castinclude/linux/container_of.h+1 -10 replies
11/20linux/container_of.h: Cosmeticinclude/linux/container_of.h+6 -23 replies
12/20linux/must_be.h: Add must_be() to improve readability of BUILD_BUG_ON_ZERO()include/linux/must_be.h+9 -03 replies
13/20Move BUILD_BUG_ON_ZERO to <linux/must_be.h>include/linux/build_bug.h include/linux/must_be.h+14 -110 replies
13/20linux/build_bug.h, linux/must_be.h: Move BUILD_BUG_ON_ZERO to <linux/must_be.h>include/linux/build_bug.h include/linux/must_be.h+14 -110 replies
14/20linux/compiler_types.h, linux/same_type.h: Split __same_type() to a separate headerinclude/linux/compiler_types.h include/linux/same_type.h+14 -31 reply
15/20linux/compiler.h: Implement __must_be_array() in terms of __must_be()include/linux/compiler.h+1 -11 reply
16/20linux/compiler.h, linux/array_size.h: Move __must_be_array() into <linux/array_size.h>drivers/gpu/drm/i915/i915_utils.h drivers/net/can/usb/etas_es58x/es58x_core.h include/linux/array_size.h +2 more+14 -42 replies
17/20linux/array_size.h: Add __is_array(a) to help readabilityinclude/linux/array_size.h+3 -11 reply
18/20linux/power_of_2.h: Add __IS_POWER_OF_2(n) and __IS_POWER_OF_2_OR_0(n) macrosinclude/linux/power_of_2.h+10 -02 replies
19/20linux/build_bug.h, linux/power_of_2.h: Move [__]BUILD_BUG_ON_NOT_POWER_OF_2() to <linux/power_of_2.h>include/linux/build_bug.h include/linux/power_of_2.h+10 -60 replies
20/20linux/power_of_2.h: Implement [__]BUILD_BUG_ON_NOT_POWER_OF_2() in terms of __IS_POWER_OF_2[_OR_0]()include/linux/power_of_2.h+2 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 00/20] Add memberof(), split headers, and simplify code

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
Signature · 1 line
2.33.1