* [PATCH v2] fat: Use pointer to simple type in put_user()
@ 2022-02-14 11:33 Helge Deller
2022-02-14 16:08 ` OGAWA Hirofumi
0 siblings, 1 reply; 2+ messages in thread
From: Helge Deller @ 2022-02-14 11:33 UTC (permalink / raw)
To: OGAWA Hirofumi, linux-kernel, David Laight, Andrew Morton,
Andreas Schwab
Cc: linux-parisc
The put_user(val,ptr) macro wants a pointer to a simple type, but in
fat_ioctl_filldir() the d_name field references an "array of chars".
Be more accurate and explicitly give the pointer to the first character
of the d_name[] array.
I noticed that issue while trying to optimize the parisc put_user() macro
and used an intermediate variable to store the pointer. In that case I
got this error:
In file included from include/linux/uaccess.h:11,
from include/linux/compat.h:17,
from fs/fat/dir.c:18:
fs/fat/dir.c: In function ‘fat_ioctl_filldir’:
fs/fat/dir.c:725:33: error: invalid initializer
725 | if (put_user(0, d2->d_name) || \
| ^~
include/asm/uaccess.h:152:33: note: in definition of macro ‘__put_user’
152 | __typeof__(ptr) __ptr = ptr; \
| ^~~
fs/fat/dir.c:759:1: note: in expansion of macro ‘FAT_IOCTL_FILLDIR_FUNC’
759 | FAT_IOCTL_FILLDIR_FUNC(fat_ioctl_filldir, __fat_dirent)
Andreas Schwab <schwab@linux-m68k.org> suggested to use
__typeof__(&*(ptr)) __ptr = ptr;
instead. This works, but nevertheless it's probably reasonable to
fix the original caller too.
Signed-off-by: Helge Deller <deller@gmx.de>
__
v2: Adjusted the description with input from David Laight
<David.Laight@ACULAB.COM> and Andreas Schwab <schwab@linux-m68k.org>.
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index c4a274285858..249825017da7 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -722,7 +722,7 @@ static int func(struct dir_context *ctx, const char *name, int name_len, \
if (name_len >= sizeof(d1->d_name)) \
name_len = sizeof(d1->d_name) - 1; \
\
- if (put_user(0, d2->d_name) || \
+ if (put_user(0, &d2->d_name[0]) || \
put_user(0, &d2->d_reclen) || \
copy_to_user(d1->d_name, name, name_len) || \
put_user(0, d1->d_name + name_len) || \
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] fat: Use pointer to simple type in put_user()
2022-02-14 11:33 [PATCH v2] fat: Use pointer to simple type in put_user() Helge Deller
@ 2022-02-14 16:08 ` OGAWA Hirofumi
0 siblings, 0 replies; 2+ messages in thread
From: OGAWA Hirofumi @ 2022-02-14 16:08 UTC (permalink / raw)
To: Helge Deller
Cc: linux-kernel, David Laight, Andrew Morton, Andreas Schwab,
linux-parisc
Helge Deller <deller@gmx.de> writes:
> The put_user(val,ptr) macro wants a pointer to a simple type, but in
> fat_ioctl_filldir() the d_name field references an "array of chars".
> Be more accurate and explicitly give the pointer to the first character
> of the d_name[] array.
>
> I noticed that issue while trying to optimize the parisc put_user() macro
> and used an intermediate variable to store the pointer. In that case I
> got this error:
>
> In file included from include/linux/uaccess.h:11,
> from include/linux/compat.h:17,
> from fs/fat/dir.c:18:
> fs/fat/dir.c: In function ‘fat_ioctl_filldir’:
> fs/fat/dir.c:725:33: error: invalid initializer
> 725 | if (put_user(0, d2->d_name) || \
> | ^~
> include/asm/uaccess.h:152:33: note: in definition of macro ‘__put_user’
> 152 | __typeof__(ptr) __ptr = ptr; \
> | ^~~
> fs/fat/dir.c:759:1: note: in expansion of macro ‘FAT_IOCTL_FILLDIR_FUNC’
> 759 | FAT_IOCTL_FILLDIR_FUNC(fat_ioctl_filldir, __fat_dirent)
>
>
> Andreas Schwab <schwab@linux-m68k.org> suggested to use
> __typeof__(&*(ptr)) __ptr = ptr;
> instead. This works, but nevertheless it's probably reasonable to
> fix the original caller too.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
> __
> v2: Adjusted the description with input from David Laight
> <David.Laight@ACULAB.COM> and Andreas Schwab <schwab@linux-m68k.org>.
>
> diff --git a/fs/fat/dir.c b/fs/fat/dir.c
> index c4a274285858..249825017da7 100644
> --- a/fs/fat/dir.c
> +++ b/fs/fat/dir.c
> @@ -722,7 +722,7 @@ static int func(struct dir_context *ctx, const char *name, int name_len, \
> if (name_len >= sizeof(d1->d_name)) \
> name_len = sizeof(d1->d_name) - 1; \
> \
> - if (put_user(0, d2->d_name) || \
> + if (put_user(0, &d2->d_name[0]) || \
> put_user(0, &d2->d_reclen) || \
> copy_to_user(d1->d_name, name, name_len) || \
> put_user(0, d1->d_name + name_len) || \
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-14 16:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-14 11:33 [PATCH v2] fat: Use pointer to simple type in put_user() Helge Deller
2022-02-14 16:08 ` OGAWA Hirofumi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox