linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tomoyo: fix clang pointer arithmetic warning
@ 2020-10-26 21:52 Arnd Bergmann
  2020-11-11 20:00 ` Nick Desaulniers
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2020-10-26 21:52 UTC (permalink / raw)
  To: Kentaro Takeda, Tetsuo Handa, James Morris, Serge E. Hallyn,
	Nathan Chancellor, Nick Desaulniers, Toshiharu Harada
  Cc: Arnd Bergmann, linux-security-module, linux-kernel, clang-built-linux

From: Arnd Bergmann <arnd@arndb.de>

clang warns about additions on NULL pointers being undefined in C:

security/tomoyo/securityfs_if.c:226:59: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
        securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,

Change the code to instead use a cast through uintptr_t to avoid
the warning.

Fixes: 9590837b89aa ("Common functions for TOMOYO Linux.")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 security/tomoyo/securityfs_if.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/tomoyo/securityfs_if.c b/security/tomoyo/securityfs_if.c
index 546281c5b233..0a5f00073ef1 100644
--- a/security/tomoyo/securityfs_if.c
+++ b/security/tomoyo/securityfs_if.c
@@ -223,7 +223,7 @@ static const struct file_operations tomoyo_operations = {
 static void __init tomoyo_create_entry(const char *name, const umode_t mode,
 				       struct dentry *parent, const u8 key)
 {
-	securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
+	securityfs_create_file(name, mode, parent, (u8 *)(uintptr_t)key,
 			       &tomoyo_operations);
 }
 
-- 
2.27.0


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

* Re: [PATCH] tomoyo: fix clang pointer arithmetic warning
  2020-10-26 21:52 [PATCH] tomoyo: fix clang pointer arithmetic warning Arnd Bergmann
@ 2020-11-11 20:00 ` Nick Desaulniers
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Desaulniers @ 2020-11-11 20:00 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Kentaro Takeda, Tetsuo Handa, James Morris, Serge E. Hallyn,
	Nathan Chancellor, Toshiharu Harada, Arnd Bergmann,
	linux-security-module, LKML, clang-built-linux

On Mon, Oct 26, 2020 at 2:52 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> clang warns about additions on NULL pointers being undefined in C:
>
> security/tomoyo/securityfs_if.c:226:59: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
>         securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
>
> Change the code to instead use a cast through uintptr_t to avoid
> the warning.
>
> Fixes: 9590837b89aa ("Common functions for TOMOYO Linux.")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks for the patch.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  security/tomoyo/securityfs_if.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/security/tomoyo/securityfs_if.c b/security/tomoyo/securityfs_if.c
> index 546281c5b233..0a5f00073ef1 100644
> --- a/security/tomoyo/securityfs_if.c
> +++ b/security/tomoyo/securityfs_if.c
> @@ -223,7 +223,7 @@ static const struct file_operations tomoyo_operations = {
>  static void __init tomoyo_create_entry(const char *name, const umode_t mode,
>                                        struct dentry *parent, const u8 key)
>  {
> -       securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
> +       securityfs_create_file(name, mode, parent, (u8 *)(uintptr_t)key,
>                                &tomoyo_operations);
>  }
>
> --
> 2.27.0
>


-- 
Thanks,
~Nick Desaulniers

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

end of thread, other threads:[~2020-11-11 20:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 21:52 [PATCH] tomoyo: fix clang pointer arithmetic warning Arnd Bergmann
2020-11-11 20:00 ` Nick Desaulniers

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