netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netlink: use 48 byte ctx instead of 6 signed longs for callback
@ 2019-06-28 14:40 Jason A. Donenfeld
  2019-06-28 14:42 ` Johannes Berg
  0 siblings, 1 reply; 3+ messages in thread
From: Jason A. Donenfeld @ 2019-06-28 14:40 UTC (permalink / raw)
  To: netdev, linux-kernel; +Cc: Jason A. Donenfeld, Johannes Berg

People are inclined to stuff random things into cb->args[n] because it
looks like an array of integers. Sometimes people even put u64s in there
with comments noting that a certain member takes up two slots. The
horror! Really this should mirror the usage of skb->cb, which are just
48 opaque bytes suitable for casting a struct. Then people can create
their usual casting macros for accessing strongly typed members of a
struct.

As a plus, this also gives us the same amount of space on 32bit and 64bit.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
---
 include/linux/netlink.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 593d1b9c33a8..205fa7b1f07a 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -192,7 +192,14 @@ struct netlink_callback {
 	bool			strict_check;
 	u16			answer_flags;
 	unsigned int		prev_seq, seq;
-	long			args[6];
+	union {
+		u8		ctx[48];
+
+		/* args is deprecated. Cast a struct over ctx instead
+		 * for proper type safety.
+		 */
+		long		args[6];
+	};
 };
 
 struct netlink_notify {
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] netlink: use 48 byte ctx instead of 6 signed longs for callback
  2019-06-28 14:40 [PATCH] netlink: use 48 byte ctx instead of 6 signed longs for callback Jason A. Donenfeld
@ 2019-06-28 14:42 ` Johannes Berg
  2019-07-02  2:12   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Berg @ 2019-06-28 14:42 UTC (permalink / raw)
  To: Jason A. Donenfeld, netdev, linux-kernel

On Fri, 2019-06-28 at 16:40 +0200, Jason A. Donenfeld wrote:
> People are inclined to stuff random things into cb->args[n] because it
> looks like an array of integers. Sometimes people even put u64s in there
> with comments noting that a certain member takes up two slots. The
> horror! Really this should mirror the usage of skb->cb, which are just
> 48 opaque bytes suitable for casting a struct. Then people can create
> their usual casting macros for accessing strongly typed members of a
> struct.
> 
> As a plus, this also gives us the same amount of space on 32bit and 64bit.
> 
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> Cc: Johannes Berg <johannes@sipsolutions.net>

Reviewed-by: Johannes Berg <johannes@sipsolutions.net>

I think this makes a lot of sense - we've got a mess here in many
places, e.g. look at struct nl80211_dump_wiphy_state in nl82011.c, I
think that could fit into the ctx[] since those don't all need to be
'long' (int or even shorter would be OK), we just want many more fields
and somehow it didn't occur to me to cast that "long args[]" array to
another struct ...

Thanks for doing this!

johannes


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] netlink: use 48 byte ctx instead of 6 signed longs for callback
  2019-06-28 14:42 ` Johannes Berg
@ 2019-07-02  2:12   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2019-07-02  2:12 UTC (permalink / raw)
  To: johannes; +Cc: Jason, netdev, linux-kernel

From: Johannes Berg <johannes@sipsolutions.net>
Date: Fri, 28 Jun 2019 16:42:26 +0200

> On Fri, 2019-06-28 at 16:40 +0200, Jason A. Donenfeld wrote:
>> People are inclined to stuff random things into cb->args[n] because it
>> looks like an array of integers. Sometimes people even put u64s in there
>> with comments noting that a certain member takes up two slots. The
>> horror! Really this should mirror the usage of skb->cb, which are just
>> 48 opaque bytes suitable for casting a struct. Then people can create
>> their usual casting macros for accessing strongly typed members of a
>> struct.
>> 
>> As a plus, this also gives us the same amount of space on 32bit and 64bit.
>> 
>> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
>> Cc: Johannes Berg <johannes@sipsolutions.net>
> 
> Reviewed-by: Johannes Berg <johannes@sipsolutions.net>

Applied to net-next.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-02  2:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-28 14:40 [PATCH] netlink: use 48 byte ctx instead of 6 signed longs for callback Jason A. Donenfeld
2019-06-28 14:42 ` Johannes Berg
2019-07-02  2:12   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).