All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] include/uapi/linux/netlink.h -Wall -Wextra -Werror support fix
@ 2013-12-15 14:40 Doron Tsur
  2013-12-15 14:52 ` Levente Kurusa
  0 siblings, 1 reply; 4+ messages in thread
From: Doron Tsur @ 2013-12-15 14:40 UTC (permalink / raw)
  To: linux-kernel; +Cc: itaib, Doron Tsur

For code using:
    #include <linux/netlink.h>
    NLMSG_OK
    -I<INSTALL_HDR_PATH>/include

Tested-by: Doron Tsur <doront@mellanox.com>
Test log:
Compilation environments:
Ubuntu 13.10, x86_64, gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
Ubuntu 13.04, x86_64, gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
[ -ftrack-macro-expansion=2 issue submitted:
  gcc.gnu.org/bugzilla/show_bug.cgi?id=59495 ]
Kernel headers installed at:
make -C .../linux-stable headers_install \
    INSTALL_HDR_PATH=/builds/kernel_tests_user_headers/
Pre-patch compilation:
gcc -Wall -Wextra -Werror
-I/builds/kernel_tests_pre_patch_user_headers/include
include-uapi-linux-netlink.h.test.c
In file included from include-uapi-linux-netlink.h.test.c:2:0:
include-uapi-linux-netlink.h.test.c: In function ‘main’:
/builds/kernel_tests_pre_patch_user_headers/include/linux/netlink.h:89:24:
error: comparison between signed and unsigned integer expressions
[-Werror=sign-compare]
       (nlh)->nlmsg_len <= (len))
                        ^
include-uapi-linux-netlink.h.test.c:26:5: note: in expansion of macro ‘NLMSG_OK’
     NLMSG_OK(&auxiliary_netlink_header, active_len));
     ^
cc1: all warnings being treated as errors
Post-patch:
$ gcc  -Wall -Wextra -Werror
-I/builds/kernel_tests_user_headers/include/
include-uapi-linux-netlink.h.test.c
$ ./a.out
nlmsg_len= 1, len = 1 NLMSG_OK(nlh,len) test result: 0
nlmsg_len= 1, len = 3000 NLMSG_OK(nlh,len) test result: 0
nlmsg_len= 3000, len = 1 NLMSG_OK(nlh,len) test result: 0
nlmsg_len= 3000, len = 3000 NLMSG_OK(nlh,len) test result: 1

Signed-off-by: Doron Tsur <doront@mellanox.com>
---
 include/uapi/linux/netlink.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h
index 1a85940..1884d4e 100644
--- a/include/uapi/linux/netlink.h
+++ b/include/uapi/linux/netlink.h
@@ -86,7 +86,7 @@ struct nlmsghdr {
 				  (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
 #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
 			   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
-			   (nlh)->nlmsg_len <= (len))
+			   (int)(nlh)->nlmsg_len <= (len))
 #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
 
 #define NLMSG_NOOP		0x1	/* Nothing.		*/
-- 
1.7.1


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

* Re: [PATCH] include/uapi/linux/netlink.h -Wall -Wextra -Werror support fix
  2013-12-15 14:40 [PATCH] include/uapi/linux/netlink.h -Wall -Wextra -Werror support fix Doron Tsur
@ 2013-12-15 14:52 ` Levente Kurusa
  0 siblings, 0 replies; 4+ messages in thread
From: Levente Kurusa @ 2013-12-15 14:52 UTC (permalink / raw)
  To: Doron Tsur, linux-kernel; +Cc: itaib

On 12/15/2013 03:40 PM, Doron Tsur wrote:
> For code using:
>     #include <linux/netlink.h>
>     NLMSG_OK
>     -I<INSTALL_HDR_PATH>/include
> 
> Tested-by: Doron Tsur <doront@mellanox.com>
This should go where your Signed-off-by line is.

[insert newlines here]
> Test log:
> Compilation environments:
> Ubuntu 13.10, x86_64, gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
> Ubuntu 13.04, x86_64, gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
> [ -ftrack-macro-expansion=2 issue submitted:
>   gcc.gnu.org/bugzilla/show_bug.cgi?id=59495 ]


[insert newlines here]
> Kernel headers installed at:
> make -C .../linux-stable headers_install \
>     INSTALL_HDR_PATH=/builds/kernel_tests_user_headers/


[insert newlines here]
> Pre-patch compilation:
> gcc -Wall -Wextra -Werror
> -I/builds/kernel_tests_pre_patch_user_headers/include
> include-uapi-linux-netlink.h.test.c
> In file included from include-uapi-linux-netlink.h.test.c:2:0:
> include-uapi-linux-netlink.h.test.c: In function ‘main’:
> /builds/kernel_tests_pre_patch_user_headers/include/linux/netlink.h:89:24:
> error: comparison between signed and unsigned integer expressions
> [-Werror=sign-compare]
>        (nlh)->nlmsg_len <= (len))
>                         ^
> include-uapi-linux-netlink.h.test.c:26:5: note: in expansion of macro ‘NLMSG_OK’
>      NLMSG_OK(&auxiliary_netlink_header, active_len));
>      ^
> cc1: all warnings being treated as errors


[insert newlines here]
> Post-patch:
> $ gcc  -Wall -Wextra -Werror
> -I/builds/kernel_tests_user_headers/include/
> include-uapi-linux-netlink.h.test.c


[insert newlines here]
> $ ./a.out
> nlmsg_len= 1, len = 1 NLMSG_OK(nlh,len) test result: 0
> nlmsg_len= 1, len = 3000 NLMSG_OK(nlh,len) test result: 0
> nlmsg_len= 3000, len = 1 NLMSG_OK(nlh,len) test result: 0
> nlmsg_len= 3000, len = 3000 NLMSG_OK(nlh,len) test result: 1
> 
> Signed-off-by: Doron Tsur <doront@mellanox.com>

Please make your commit message understandable by adding newlines and such.
Also it doesn't say what did you change and why. All it says, that there
was a warning and post-patch there is no warning.

-- 
Regards,
Levente Kurusa

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

* [PATCH] include/uapi/linux/netlink.h -Wall -Wextra -Werror support fix
@ 2013-12-15 17:29 Doron Tsur
  0 siblings, 0 replies; 4+ messages in thread
From: Doron Tsur @ 2013-12-15 17:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: itaib, Doron Tsur

For code using:
    #include <linux/netlink.h>
    NLMSG_OK
    -I<INSTALL_HDR_PATH>/include

Issue:
(nlh)->nlmsg_len is of type __u32, while len is of type int,
according to (len) >= (int)sizeof(struct nlmsghdr).
Hence (nlh)->nlmsg_len <= (len) sign-compare warning when using NLMSG_OK

Fix:
Add (int) casting:
-			   (nlh)->nlmsg_len <= (len))
+			   (int)(nlh)->nlmsg_len <= (len))

Test log:
Compilation environments:
Ubuntu 13.10, x86_64, gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
Ubuntu 13.04, x86_64, gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
[ -ftrack-macro-expansion=2 issue submitted:
  gcc.gnu.org/bugzilla/show_bug.cgi?id=59495 ]

Kernel headers installed at:
make -C .../linux-stable headers_install \
    INSTALL_HDR_PATH=/builds/kernel_tests_user_headers/

Pre-patch compilation:
gcc -Wall -Wextra -Werror
-I/builds/kernel_tests_pre_patch_user_headers/include
include-uapi-linux-netlink.h.test.c
In file included from include-uapi-linux-netlink.h.test.c:2:0:
include-uapi-linux-netlink.h.test.c: In function ‘main’:
/builds/kernel_tests_pre_patch_user_headers/include/linux/netlink.h:89:24:
error: comparison between signed and unsigned integer expressions
[-Werror=sign-compare]
       (nlh)->nlmsg_len <= (len))
                        ^
include-uapi-linux-netlink.h.test.c:26:5: note: in expansion of macro ‘NLMSG_OK’
     NLMSG_OK(&auxiliary_netlink_header, active_len));
     ^
cc1: all warnings being treated as errors

Post-patch:
$ gcc  -Wall -Wextra -Werror
-I/builds/kernel_tests_user_headers/include/
include-uapi-linux-netlink.h.test.c

$ ./a.out
nlmsg_len= 1, len = 1 NLMSG_OK(nlh,len) test result: 0
nlmsg_len= 1, len = 3000 NLMSG_OK(nlh,len) test result: 0
nlmsg_len= 3000, len = 1 NLMSG_OK(nlh,len) test result: 0
nlmsg_len= 3000, len = 3000 NLMSG_OK(nlh,len) test result: 1

Tested-by: Doron Tsur <doront@mellanox.com>
Signed-off-by: Doron Tsur <doront@mellanox.com>
---
 include/uapi/linux/netlink.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h
index 1a85940..1884d4e 100644
--- a/include/uapi/linux/netlink.h
+++ b/include/uapi/linux/netlink.h
@@ -86,7 +86,7 @@ struct nlmsghdr {
 				  (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
 #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
 			   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
-			   (nlh)->nlmsg_len <= (len))
+			   (int)(nlh)->nlmsg_len <= (len))
 #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
 
 #define NLMSG_NOOP		0x1	/* Nothing.		*/
-- 
1.7.1


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

* [PATCH] include/uapi/linux/netlink.h -Wall -Wextra -Werror support fix
@ 2013-12-15 17:31 Doron Tsur
  0 siblings, 0 replies; 4+ messages in thread
From: Doron Tsur @ 2013-12-15 17:31 UTC (permalink / raw)
  To: linux-kernel, levex; +Cc: itaib, Doron Tsur

For code using:
    #include <linux/netlink.h>
    NLMSG_OK
    -I<INSTALL_HDR_PATH>/include

Issue:
(nlh)->nlmsg_len is of type __u32, while len is of type int,
according to (len) >= (int)sizeof(struct nlmsghdr).
Hence (nlh)->nlmsg_len <= (len) sign-compare warning when using NLMSG_OK

Fix:
Add (int) casting:
-			   (nlh)->nlmsg_len <= (len))
+			   (int)(nlh)->nlmsg_len <= (len))

Test log:
Compilation environments:
Ubuntu 13.10, x86_64, gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
Ubuntu 13.04, x86_64, gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
[ -ftrack-macro-expansion=2 issue submitted:
  gcc.gnu.org/bugzilla/show_bug.cgi?id=59495 ]

Kernel headers installed at:
make -C .../linux-stable headers_install \
    INSTALL_HDR_PATH=/builds/kernel_tests_user_headers/

Pre-patch compilation:
gcc -Wall -Wextra -Werror
-I/builds/kernel_tests_pre_patch_user_headers/include
include-uapi-linux-netlink.h.test.c
In file included from include-uapi-linux-netlink.h.test.c:2:0:
include-uapi-linux-netlink.h.test.c: In function ‘main’:
/builds/kernel_tests_pre_patch_user_headers/include/linux/netlink.h:89:24:
error: comparison between signed and unsigned integer expressions
[-Werror=sign-compare]
       (nlh)->nlmsg_len <= (len))
                        ^
include-uapi-linux-netlink.h.test.c:26:5: note: in expansion of macro ‘NLMSG_OK’
     NLMSG_OK(&auxiliary_netlink_header, active_len));
     ^
cc1: all warnings being treated as errors

Post-patch:
$ gcc  -Wall -Wextra -Werror
-I/builds/kernel_tests_user_headers/include/
include-uapi-linux-netlink.h.test.c

$ ./a.out
nlmsg_len= 1, len = 1 NLMSG_OK(nlh,len) test result: 0
nlmsg_len= 1, len = 3000 NLMSG_OK(nlh,len) test result: 0
nlmsg_len= 3000, len = 1 NLMSG_OK(nlh,len) test result: 0
nlmsg_len= 3000, len = 3000 NLMSG_OK(nlh,len) test result: 1

Tested-by: Doron Tsur <doront@mellanox.com>
Signed-off-by: Doron Tsur <doront@mellanox.com>
---
 include/uapi/linux/netlink.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h
index 1a85940..1884d4e 100644
--- a/include/uapi/linux/netlink.h
+++ b/include/uapi/linux/netlink.h
@@ -86,7 +86,7 @@ struct nlmsghdr {
 				  (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
 #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
 			   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
-			   (nlh)->nlmsg_len <= (len))
+			   (int)(nlh)->nlmsg_len <= (len))
 #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
 
 #define NLMSG_NOOP		0x1	/* Nothing.		*/
-- 
1.7.1


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

end of thread, other threads:[~2013-12-15 17:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-15 14:40 [PATCH] include/uapi/linux/netlink.h -Wall -Wextra -Werror support fix Doron Tsur
2013-12-15 14:52 ` Levente Kurusa
  -- strict thread matches above, loose matches on Subject: below --
2013-12-15 17:29 Doron Tsur
2013-12-15 17:31 Doron Tsur

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.