Re: [PATCH] tomoyo: fix clang pointer arithmetic warning
From: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Date: 2020-10-28 23:05:05
From: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Date: 2020-10-28 23:05:05
Thank you for a patch. I have two questions. On 2020/10/27 6:52, Arnd Bergmann 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.- securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key, + securityfs_create_file(name, mode, parent, (u8 *)(uintptr_t)key, &tomoyo_operations);
(1) Does clang warn if "(void *)key" is used instead of "(u8 *)(uintptr_t)key" ?
(2) tomoyo_open() has
const int key = ((u8 *) file_inode(file)->i_private) - ((u8 *) NULL);
which decodes the "u8 key" passed to tomoyo_create_entry(). For symmetry,
I'd like to remove NULL from tomoyo_open() as well. Does clang warn if
const int key = (u8) (file_inode(file)->i_private);
is used?