Skip to contentSkip to conversation

iw: fix formats under MIPS64/PPC

PATCH In review Rosen Penev 2 participants 9 messages Jun 28, 2024 – Jul 1, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iw: fix formats under MIPS64/PPC

__SANE_USERSPACE_TYPES__ needs to be defined to get consistent 64-bit type defines and to fix -Wformat warnings.

---
 iw.h | 2 ++
 1 file changed, 2 insertions(+)
iw.h +2 -0
index f416d6d..436723f 100644
@@ -1,6 +1,8 @@
 #ifndef __IW_H
 #define __IW_H
 
+#define __SANE_USERSPACE_TYPES__
+
 #include <stdbool.h>
 #include <netlink/netlink.h>
 #include <netlink/genl/genl.h>
Signature · 1 line
2.45.2
#1 lore raw
Quoted 3 lines · Rosen Penev

__SANE_USERSPACE_TYPES__ needs to be defined to get consistent 64-bit type defines and to fix -Wformat warnings.

How does this even work? Pretty much every file I checked in iw includes iw.h _last_ (or close to it), after netlink, nl80211.h etc., so ...? Doesn't really seem like it would have any effect?

johannes

#2 lore raw
Quoted 9 lines · Johannes Berg
Quoted 3 lines · Rosen Penev

__SANE_USERSPACE_TYPES__ needs to be defined to get consistent 64-bit type defines and to fix -Wformat warnings.

How does this even work? Pretty much every file I checked in iw includes iw.h _last_ (or close to it), after netlink, nl80211.h etc., so ...? Doesn't really seem like it would have any effect?

I only tested compilation of iw itself, not of any project that uses it.

Quoted 2 lines

johannes

#3 lore raw
Quoted 11 lines · Rosen Penev
Quoted 9 lines · Johannes Berg
Quoted 3 lines · Rosen Penev

__SANE_USERSPACE_TYPES__ needs to be defined to get consistent 64-bit type defines and to fix -Wformat warnings.

How does this even work? Pretty much every file I checked in iw includes iw.h _last_ (or close to it), after netlink, nl80211.h etc., so ...? Doesn't really seem like it would have any effect?

I only tested compilation of iw itself, not of any project that uses it.

Hm? It's iw itself only anyway? But where did you see warnings/errors, and why did they go away when this shouldn't have really done anything?

johannes

Quoted 1 line
#4 lore raw
Quoted 9 lines · Johannes Berg
Quoted 7 lines · Rosen Penev
Quoted 6 lines · Johannes Berg
Quoted 3 lines · Rosen Penev

__SANE_USERSPACE_TYPES__ needs to be defined to get consistent 64-bit type defines and to fix -Wformat warnings.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

How does this even work? Pretty much every file I checked in iw includes iw.h _last_ (or close to it), after netlink, nl80211.h etc., so ...? Doesn't really seem like it would have any effect?

I only tested compilation of iw itself, not of any project that uses it.

Hm? It's iw itself only anyway? But where did you see warnings/errors, and why did they go away when this shouldn't have really done anything?

The whole codebase.

They go away because if the define is found before any header inclusion, __u64 gets defined to unsigned long long.

Note that the header after the define include linux headers.

The impacted architectures can be found in the kernel with

git grep SANE_USERSPACE arch

Quoted 3 lines

johannes

Quoted 1 line
#5 lore raw
Quoted 3 lines · Rosen Penev

They go away because if the define is found before any header inclusion, __u64 gets defined to unsigned long long.

It *isn't* found before any header inclusion though.

For pretty much all of the C files, "iw.h" comes _last_ in the list of included headers.

johannes

#6 lore raw
Quoted 10 lines · Johannes Berg
Quoted 3 lines · Rosen Penev

They go away because if the define is found before any header inclusion, __u64 gets defined to unsigned long long.

It *isn't* found before any header inclusion though.

For pretty much all of the C files, "iw.h" comes _last_ in the list of included headers.

Oh I see what you mean. No real idea. However without this patch, I get

event.c: In function 'parse_nan_match':
event.c:668:41: error: format '%llx' expects argument of type 'long long unsigned int', but argument 2 has type '__u64' {aka 'long unsigned int'} [-Werror=format=]
668 | "NAN(cookie=0x%llx): DiscoveryResult,
peer_id=%d, local_id=%d, peer_mac=%s",

      |                                      ~~~^
      |                                         |
      |                                         long long unsigned int
      |                                      %lx
  669 |                        cookie,
      |                        ~~~~~~
      |                        |
      |                        __u64 {aka long unsigned int}

event.c:680:41: error: format '%llx' expects argument of type 'long long unsigned int', but argument 2 has type '__u64' {aka 'long unsigned int'} [-Werror=format=]
680 | "NAN(cookie=0x%llx): Replied,
peer_id=%d, local_id=%d, peer_mac=%s",

      |                                      ~~~^
      |                                         |
      |                                         long long unsigned int
      |                                      %lx
  681 |                        cookie,
      |                        ~~~~~~
      |                        |
      |                        __u64 {aka long unsigned int}

event.c:688:41: error: format '%llx' expects argument of type 'long long unsigned int', but argument 2 has type '__u64' {aka 'long unsigned int'} [-Werror=format=]
688 | "NAN(cookie=0x%llx): FollowUpReceive,
peer_id=%d, local_id=%d, peer_mac=%s",

      |                                      ~~~^
      |                                         |
      |                                         long long unsigned int
      |                                      %lx
  689 |                        cookie,
      |                        ~~~~~~
      |                        |
      |                        __u64 {aka long unsigned int}

And many others.

I submitted a similar patch to fio and was advised to move the define into the Makefiles. Not too sure how to do that here.

Quoted 2 lines

johannes

#7 lore raw
Quoted 7 lines · Rosen Penev
Quoted 6 lines · Johannes Berg
Quoted 3 lines · Rosen Penev

They go away because if the define is found before any header inclusion, __u64 gets defined to unsigned long long.

Quoted 7 lines
Quoted 4 lines

It *isn't* found before any header inclusion though.

For pretty much all of the C files, "iw.h" comes _last_ in the list of included headers.

Oh I see what you mean. No real idea. However without this patch, I get

event.c: In function 'parse_nan_match':

OK, well, event.c is one of those cases where indeed most things are included indirectly via iw.h, so it would actually work ... but most files don't do that. Maybe lucky that they don't use 64-bit types (yet)?

Quoted 3 lines

I submitted a similar patch to fio and was advised to move the define into the Makefiles. Not too sure how to do that here.

Probably a good idea, just add

CFLAGS += -D__SANE_USERSPACE_TYPES__

in the an appropriate place with the others.

johannes

#8 lore raw
Quoted 21 lines · Johannes Berg
Quoted 7 lines · Rosen Penev
Quoted 6 lines · Johannes Berg
Quoted 3 lines · Rosen Penev

They go away because if the define is found before any header inclusion, __u64 gets defined to unsigned long long.

Quoted 7 lines
Quoted 4 lines

It *isn't* found before any header inclusion though.

For pretty much all of the C files, "iw.h" comes _last_ in the list of included headers.

Oh I see what you mean. No real idea. However without this patch, I get

event.c: In function 'parse_nan_match':

OK, well, event.c is one of those cases where indeed most things are included indirectly via iw.h, so it would actually work ... but most files don't do that. Maybe lucky that they don't use 64-bit types (yet)?

Quoted 7 lines
Quoted 3 lines

I submitted a similar patch to fio and was advised to move the define into the Makefiles. Not too sure how to do that here.

Probably a good idea, just add

CFLAGS += -D__SANE_USERSPACE_TYPES__

Right. My thinking was to match against the system being built.

I guess it doesn't really hurt to just define everywhere. That's what this patch does anyway.

Quoted 4 lines

in the an appropriate place with the others.

johannes