netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets
@ 2019-06-25 11:49 Baruch Siach
  2019-06-25 11:49 ` [PATCH iproute2 2/2] devlink: fix libc and kernel headers collision Baruch Siach
  2019-06-25 18:58 ` [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets Stephen Hemminger
  0 siblings, 2 replies; 6+ messages in thread
From: Baruch Siach @ 2019-06-25 11:49 UTC (permalink / raw)
  To: Stephen Hemminger, Jiri Pirko
  Cc: netdev, Baruch Siach, Aya Levin, Moshe Shemesh

32bit targets define uint64_t as long long unsigned. This leads to the
following build warning:

devlink.c: In function ‘pr_out_u64’:
devlink.c:1729:11: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘uint64_t {aka long long unsigned int}’ [-Wformat=]
    pr_out("%s %lu", name, val);
           ^
devlink.c:59:21: note: in definition of macro ‘pr_out’
   fprintf(stdout, ##args);   \
                     ^~~~

Use 'll' length modifier in the format string to fix that.

Cc: Aya Levin <ayal@mellanox.com>
Cc: Moshe Shemesh <moshe@mellanox.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 devlink/devlink.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 436935f88bda..b400fab17578 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -1726,9 +1726,9 @@ static void pr_out_u64(struct dl *dl, const char *name, uint64_t val)
 		jsonw_u64_field(dl->jw, name, val);
 	} else {
 		if (g_indent_newline)
-			pr_out("%s %lu", name, val);
+			pr_out("%s %llu", name, val);
 		else
-			pr_out(" %s %lu", name, val);
+			pr_out(" %s %llu", name, val);
 	}
 }
 
@@ -1753,7 +1753,7 @@ static void pr_out_uint64_value(struct dl *dl, uint64_t value)
 	if (dl->json_output)
 		jsonw_u64(dl->jw, value);
 	else
-		pr_out(" %lu", value);
+		pr_out(" %llu", value);
 }
 
 static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len)
-- 
2.20.1


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

* [PATCH iproute2 2/2] devlink: fix libc and kernel headers collision
  2019-06-25 11:49 [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets Baruch Siach
@ 2019-06-25 11:49 ` Baruch Siach
  2019-06-25 18:59   ` Stephen Hemminger
  2019-06-25 18:58 ` [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets Stephen Hemminger
  1 sibling, 1 reply; 6+ messages in thread
From: Baruch Siach @ 2019-06-25 11:49 UTC (permalink / raw)
  To: Stephen Hemminger, Jiri Pirko
  Cc: netdev, Baruch Siach, Aya Levin, Moshe Shemesh

Since commit 2f1242efe9d ("devlink: Add devlink health show command") we
use the sys/sysinfo.h header for the sysinfo(2) system call. But since
iproute2 carries a local version of the kernel struct sysinfo, this
causes a collision with libc that do not rely on kernel defined sysinfo
like musl libc:

In file included from devlink.c:25:0:
.../sysroot/usr/include/sys/sysinfo.h:10:8: error: redefinition of 'struct sysinfo'
 struct sysinfo {
        ^~~~~~~
In file included from ../include/uapi/linux/kernel.h:5:0,
                 from ../include/uapi/linux/netlink.h:5,
                 from ../include/uapi/linux/genetlink.h:6,
                 from devlink.c:21:
../include/uapi/linux/sysinfo.h:8:8: note: originally defined here
 struct sysinfo {
        ^~~~~~~

Move the sys/sysinfo.h userspace header before kernel headers, and
suppress the indirect include of linux/sysinfo.h.

Cc: Aya Levin <ayal@mellanox.com>
Cc: Moshe Shemesh <moshe@mellanox.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 devlink/devlink.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index b400fab17578..2ea60d3556da 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -18,11 +18,16 @@
 #include <limits.h>
 #include <errno.h>
 #include <inttypes.h>
+#include <sys/sysinfo.h>
+/* Suppress linux/sysinfo.h to avoid
+ * collision of struct sysinfo definition
+ * with musl libc headers
+ */
+#define _LINUX_SYSINFO_H
 #include <linux/genetlink.h>
 #include <linux/devlink.h>
 #include <libmnl/libmnl.h>
 #include <netinet/ether.h>
-#include <sys/sysinfo.h>
 #include <sys/queue.h>
 
 #include "SNAPSHOT.h"
-- 
2.20.1


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

* Re: [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets
  2019-06-25 11:49 [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets Baruch Siach
  2019-06-25 11:49 ` [PATCH iproute2 2/2] devlink: fix libc and kernel headers collision Baruch Siach
@ 2019-06-25 18:58 ` Stephen Hemminger
  2019-06-26  3:30   ` Baruch Siach
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2019-06-25 18:58 UTC (permalink / raw)
  To: Baruch Siach; +Cc: Jiri Pirko, netdev, Aya Levin, Moshe Shemesh

On Tue, 25 Jun 2019 14:49:04 +0300
Baruch Siach <baruch@tkos.co.il> wrote:

> diff --git a/devlink/devlink.c b/devlink/devlink.c
> index 436935f88bda..b400fab17578 100644
> --- a/devlink/devlink.c
> +++ b/devlink/devlink.c
> @@ -1726,9 +1726,9 @@ static void pr_out_u64(struct dl *dl, const char *name, uint64_t val)
>  		jsonw_u64_field(dl->jw, name, val);
>  	} else {
>  		if (g_indent_newline)
> -			pr_out("%s %lu", name, val);
> +			pr_out("%s %llu", name, val);
>  		else
> -			pr_out(" %s %lu", name, val);
> +			pr_out(" %s %llu", name, val);

But on 64 bit target %llu expects unsigned long long which is 128bit.

The better way to fix this is to use:
#include <inttypes.h>

And the use the macro PRIu64
			pr_out(" %s %"PRIu64, name, val);


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

* Re: [PATCH iproute2 2/2] devlink: fix libc and kernel headers collision
  2019-06-25 11:49 ` [PATCH iproute2 2/2] devlink: fix libc and kernel headers collision Baruch Siach
@ 2019-06-25 18:59   ` Stephen Hemminger
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2019-06-25 18:59 UTC (permalink / raw)
  To: Baruch Siach; +Cc: Jiri Pirko, netdev, Aya Levin, Moshe Shemesh

On Tue, 25 Jun 2019 14:49:05 +0300
Baruch Siach <baruch@tkos.co.il> wrote:

> +/* Suppress linux/sysinfo.h to avoid
> + * collision of struct sysinfo definition
> + * with musl libc headers
> + */

You only need a small comment for this.

#define _LINUX_SYSINFO_H /* avoid collision with musl header */


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

* Re: [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets
  2019-06-25 18:58 ` [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets Stephen Hemminger
@ 2019-06-26  3:30   ` Baruch Siach
  2019-06-26 14:55     ` Stephen Hemminger
  0 siblings, 1 reply; 6+ messages in thread
From: Baruch Siach @ 2019-06-26  3:30 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Jiri Pirko, netdev, Aya Levin, Moshe Shemesh

Hi Stephen,

On Tue, Jun 25, 2019 at 11:58:06AM -0700, Stephen Hemminger wrote:
> On Tue, 25 Jun 2019 14:49:04 +0300
> Baruch Siach <baruch@tkos.co.il> wrote:
> 
> > diff --git a/devlink/devlink.c b/devlink/devlink.c
> > index 436935f88bda..b400fab17578 100644
> > --- a/devlink/devlink.c
> > +++ b/devlink/devlink.c
> > @@ -1726,9 +1726,9 @@ static void pr_out_u64(struct dl *dl, const char *name, uint64_t val)
> >  		jsonw_u64_field(dl->jw, name, val);
> >  	} else {
> >  		if (g_indent_newline)
> > -			pr_out("%s %lu", name, val);
> > +			pr_out("%s %llu", name, val);
> >  		else
> > -			pr_out(" %s %lu", name, val);
> > +			pr_out(" %s %llu", name, val);
> 
> But on 64 bit target %llu expects unsigned long long which is 128bit.

Is that a problem?

> The better way to fix this is to use:
> #include <inttypes.h>
> 
> And the use the macro PRIu64
> 			pr_out(" %s %"PRIu64, name, val);

I think it makes the code harder to read. But OK, I'll post an update to this 
patch and the next.

Thanks,
baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

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

* Re: [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets
  2019-06-26  3:30   ` Baruch Siach
@ 2019-06-26 14:55     ` Stephen Hemminger
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2019-06-26 14:55 UTC (permalink / raw)
  To: Baruch Siach; +Cc: Jiri Pirko, netdev, Aya Levin, Moshe Shemesh

On Wed, 26 Jun 2019 06:30:44 +0300
Baruch Siach <baruch@tkos.co.il> wrote:

> Hi Stephen,
> 
> On Tue, Jun 25, 2019 at 11:58:06AM -0700, Stephen Hemminger wrote:
> > On Tue, 25 Jun 2019 14:49:04 +0300
> > Baruch Siach <baruch@tkos.co.il> wrote:
> >   
> > > diff --git a/devlink/devlink.c b/devlink/devlink.c
> > > index 436935f88bda..b400fab17578 100644
> > > --- a/devlink/devlink.c
> > > +++ b/devlink/devlink.c
> > > @@ -1726,9 +1726,9 @@ static void pr_out_u64(struct dl *dl, const char *name, uint64_t val)
> > >  		jsonw_u64_field(dl->jw, name, val);
> > >  	} else {
> > >  		if (g_indent_newline)
> > > -			pr_out("%s %lu", name, val);
> > > +			pr_out("%s %llu", name, val);
> > >  		else
> > > -			pr_out(" %s %lu", name, val);
> > > +			pr_out(" %s %llu", name, val);  
> > 
> > But on 64 bit target %llu expects unsigned long long which is 128bit.  
> 
> Is that a problem?
> 
> > The better way to fix this is to use:
> > #include <inttypes.h>
> > 
> > And the use the macro PRIu64
> > 			pr_out(" %s %"PRIu64, name, val);  
> 
> I think it makes the code harder to read. But OK, I'll post an update to this 
> patch and the next.

Or cast val to unsigned long long?

the real problem is devlink's macro's for printing.
If I had been paying attention during initial review, would have forced pr_out to be
a function.

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

end of thread, other threads:[~2019-06-26 14:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-25 11:49 [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets Baruch Siach
2019-06-25 11:49 ` [PATCH iproute2 2/2] devlink: fix libc and kernel headers collision Baruch Siach
2019-06-25 18:59   ` Stephen Hemminger
2019-06-25 18:58 ` [PATCH iproute2 1/2] devlink: fix format string warning for 32bit targets Stephen Hemminger
2019-06-26  3:30   ` Baruch Siach
2019-06-26 14:55     ` Stephen Hemminger

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).