* [PATCH] netlink: fix gcc -Wconversion compilation warning
@ 2010-12-13 17:05 Kirill A. Shutsemov
2010-12-13 21:35 ` Eric W. Biederman
0 siblings, 1 reply; 5+ messages in thread
From: Kirill A. Shutsemov @ 2010-12-13 17:05 UTC (permalink / raw)
To: David S. Miller
Cc: netdev, Pablo Neira Ayuso, Eric W. Biederman, Dmitry V. Levin,
linux-kernel, Kirill A. Shutemov
From: Dmitry V. Levin <ldv@altlinux.org>
$ cat << EOF | gcc -Wconversion -xc -S -o/dev/null -
unsigned f(void) {return NLMSG_HDRLEN;}
EOF
<stdin>: In function 'f':
<stdin>:3:26: warning: negative integer implicitly converted to unsigned type
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
include/linux/netlink.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 1235669..e2b9e63 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -70,7 +70,7 @@ struct nlmsghdr {
Check NLM_F_EXCL
*/
-#define NLMSG_ALIGNTO 4
+#define NLMSG_ALIGNTO 4U
#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
#define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
#define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN))
--
1.7.3.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] netlink: fix gcc -Wconversion compilation warning
2010-12-13 17:05 [PATCH] netlink: fix gcc -Wconversion compilation warning Kirill A. Shutsemov
@ 2010-12-13 21:35 ` Eric W. Biederman
2010-12-14 11:27 ` Kirill A. Shutemov
2010-12-17 20:02 ` David Miller
0 siblings, 2 replies; 5+ messages in thread
From: Eric W. Biederman @ 2010-12-13 21:35 UTC (permalink / raw)
To: Kirill A. Shutsemov
Cc: David S. Miller, netdev, Pablo Neira Ayuso, Dmitry V. Levin,
linux-kernel
"Kirill A. Shutsemov" <kirill@shutemov.name> writes:
> From: Dmitry V. Levin <ldv@altlinux.org>
>
> $ cat << EOF | gcc -Wconversion -xc -S -o/dev/null -
> unsigned f(void) {return NLMSG_HDRLEN;}
> EOF
> <stdin>: In function 'f':
> <stdin>:3:26: warning: negative integer implicitly converted to unsigned type
>
This doesn't look like a bad fix, but I believe things will fail if
we give NLMSG_ALIGN an unsigned long like size_t. Say like sizeof.
Admittedly it has to be a huge size but still if we are going
to go fixing things...
And then there is the silliness that NLMSG_HDRLEN forces itself
to be an int, when it start out as a size_t.
So I think NLMSG_ALIGN either needs to operation exclusively
on unsigned longs aka size_t, or it needs to be type preserving.
Do you have time to look at this a bit more?
> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> ---
> include/linux/netlink.h | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/include/linux/netlink.h b/include/linux/netlink.h
> index 1235669..e2b9e63 100644
> --- a/include/linux/netlink.h
> +++ b/include/linux/netlink.h
> @@ -70,7 +70,7 @@ struct nlmsghdr {
> Check NLM_F_EXCL
> */
>
> -#define NLMSG_ALIGNTO 4
> +#define NLMSG_ALIGNTO 4U
> #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
> #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
> #define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] netlink: fix gcc -Wconversion compilation warning
2010-12-13 21:35 ` Eric W. Biederman
@ 2010-12-14 11:27 ` Kirill A. Shutemov
2010-12-17 20:02 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: Kirill A. Shutemov @ 2010-12-14 11:27 UTC (permalink / raw)
To: Eric W. Biederman
Cc: David S. Miller, netdev, Pablo Neira Ayuso, Dmitry V. Levin,
linux-kernel
On Mon, Dec 13, 2010 at 01:35:25PM -0800, Eric W. Biederman wrote:
> "Kirill A. Shutsemov" <kirill@shutemov.name> writes:
>
> > From: Dmitry V. Levin <ldv@altlinux.org>
> >
> > $ cat << EOF | gcc -Wconversion -xc -S -o/dev/null -
> > unsigned f(void) {return NLMSG_HDRLEN;}
> > EOF
> > <stdin>: In function 'f':
> > <stdin>:3:26: warning: negative integer implicitly converted to unsigned type
> >
> This doesn't look like a bad fix, but I believe things will fail if
> we give NLMSG_ALIGN an unsigned long like size_t. Say like sizeof.
>
> Admittedly it has to be a huge size but still if we are going
> to go fixing things...
>
> And then there is the silliness that NLMSG_HDRLEN forces itself
> to be an int, when it start out as a size_t.
>
> So I think NLMSG_ALIGN either needs to operation exclusively
> on unsigned longs aka size_t, or it needs to be type preserving.
>
> Do you have time to look at this a bit more?
Something like this? Untested.
---
>From 8b86073dc9697c0eff93c003d6331c1e4aeda60e Mon Sep 17 00:00:00 2001
From: Kirill A. Shutemov <kirill@shutemov.name>
Date: Tue, 14 Dec 2010 12:50:39 +0200
Subject: [PATCH] netlink: fix gcc -Wconversion compilation warning
$ cat << EOF | gcc -Wconversion -xc -S -o/dev/null -
unsigned f(void) {return NLMSG_HDRLEN;}
EOF
<stdin>: In function 'f':
<stdin>:3:26: warning: negative integer implicitly converted to unsigned type
Define NLMSG_ALIGNTO as size_t, NLMSG_ALIGN always returns size_t and
drop non-sense casting in NLMSG_HDRLEN. Now NLMSG_HDRLEN returns size_t.
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
include/linux/netlink.h | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 1235669..db7d373 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -70,9 +70,9 @@ struct nlmsghdr {
Check NLM_F_EXCL
*/
-#define NLMSG_ALIGNTO 4
-#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
-#define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
+#define NLMSG_ALIGNTO ((size_t) 4)
+#define NLMSG_ALIGN(len) ( ((size_t)(len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
+#define NLMSG_HDRLEN NLMSG_ALIGN(sizeof(struct nlmsghdr))
#define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN))
#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
#define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
--
Kirill A. Shutemov
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] netlink: fix gcc -Wconversion compilation warning
2010-12-13 21:35 ` Eric W. Biederman
2010-12-14 11:27 ` Kirill A. Shutemov
@ 2010-12-17 20:02 ` David Miller
2010-12-18 6:58 ` Eric W. Biederman
1 sibling, 1 reply; 5+ messages in thread
From: David Miller @ 2010-12-17 20:02 UTC (permalink / raw)
To: ebiederm; +Cc: kirill, netdev, pablo, ldv, linux-kernel
From: ebiederm@xmission.com (Eric W. Biederman)
Date: Mon, 13 Dec 2010 13:35:25 -0800
> "Kirill A. Shutsemov" <kirill@shutemov.name> writes:
>
>> From: Dmitry V. Levin <ldv@altlinux.org>
>>
>> $ cat << EOF | gcc -Wconversion -xc -S -o/dev/null -
>> unsigned f(void) {return NLMSG_HDRLEN;}
>> EOF
>> <stdin>: In function 'f':
>> <stdin>:3:26: warning: negative integer implicitly converted to unsigned type
>>
> This doesn't look like a bad fix, but I believe things will fail if
> we give NLMSG_ALIGN an unsigned long like size_t. Say like sizeof.
What are you talking about? That's exactly his test case,
look at what NLMSG_HDRLEN is defined to, it's exactly the
case you're worried "will fail", it passes sizeof() to
NLMSG_ALIGN.
I think I'll apply Kirill's original patch, it's good enough
and simpler.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] netlink: fix gcc -Wconversion compilation warning
2010-12-17 20:02 ` David Miller
@ 2010-12-18 6:58 ` Eric W. Biederman
0 siblings, 0 replies; 5+ messages in thread
From: Eric W. Biederman @ 2010-12-18 6:58 UTC (permalink / raw)
To: David Miller; +Cc: kirill, netdev, pablo, ldv, linux-kernel
David Miller <davem@davemloft.net> writes:
> From: ebiederm@xmission.com (Eric W. Biederman)
> Date: Mon, 13 Dec 2010 13:35:25 -0800
>
>> "Kirill A. Shutsemov" <kirill@shutemov.name> writes:
>>
>>> From: Dmitry V. Levin <ldv@altlinux.org>
>>>
>>> $ cat << EOF | gcc -Wconversion -xc -S -o/dev/null -
>>> unsigned f(void) {return NLMSG_HDRLEN;}
>>> EOF
>>> <stdin>: In function 'f':
>>> <stdin>:3:26: warning: negative integer implicitly converted to unsigned type
>>>
>> This doesn't look like a bad fix, but I believe things will fail if
>> we give NLMSG_ALIGN an unsigned long like size_t. Say like sizeof.
>
> What are you talking about? That's exactly his test case,
> look at what NLMSG_HDRLEN is defined to, it's exactly the
> case you're worried "will fail", it passes sizeof() to
> NLMSG_ALIGN.
>
> I think I'll apply Kirill's original patch, it's good enough
> and simpler.
Probably. The case I was worried about was masks that become
0xffffffxx on 64bit instead of 0xffffffffffffxx. Especially
when mixing those with ints.
It is possible to get some really weird things.
Eric
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-12-18 6:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-13 17:05 [PATCH] netlink: fix gcc -Wconversion compilation warning Kirill A. Shutsemov
2010-12-13 21:35 ` Eric W. Biederman
2010-12-14 11:27 ` Kirill A. Shutemov
2010-12-17 20:02 ` David Miller
2010-12-18 6:58 ` Eric W. Biederman
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).