Skip to content

Commit 85c9fe8

Browse files
kjwinchestertorvalds
authored andcommitted
vfs: fix warning: 'dirent' is used uninitialized in this function
Using: gcc (GCC) 4.5.0 20100610 (prerelease) The following warnings appear: fs/readdir.c: In function `filldir64': fs/readdir.c:240:15: warning: `dirent' is used uninitialized in this function fs/readdir.c: In function `filldir': fs/readdir.c:155:15: warning: `dirent' is used uninitialized in this function fs/compat.c: In function `compat_filldir64': fs/compat.c:1071:11: warning: `dirent' is used uninitialized in this function fs/compat.c: In function `compat_filldir': fs/compat.c:984:15: warning: `dirent' is used uninitialized in this function The warnings are related to the use of the NAME_OFFSET() macro. Luckily, it appears as though the standard offsetof() macro is what is being implemented by NAME_OFFSET(), thus we can fix the warning and use a more standard code construct at the same time. Signed-off-by: Kevin Winchester <[email protected]> Cc: Al Viro <[email protected]> Cc: Christoph Hellwig <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d89b194 commit 85c9fe8

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

fs/compat.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* published by the Free Software Foundation.
1616
*/
1717

18+
#include <linux/stddef.h>
1819
#include <linux/kernel.h>
1920
#include <linux/linkage.h>
2021
#include <linux/compat.h>
@@ -891,8 +892,6 @@ asmlinkage long compat_sys_mount(char __user * dev_name, char __user * dir_name,
891892
return retval;
892893
}
893894

894-
#define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
895-
896895
struct compat_old_linux_dirent {
897896
compat_ulong_t d_ino;
898897
compat_ulong_t d_offset;
@@ -981,7 +980,8 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
981980
struct compat_linux_dirent __user * dirent;
982981
struct compat_getdents_callback *buf = __buf;
983982
compat_ulong_t d_ino;
984-
int reclen = ALIGN(NAME_OFFSET(dirent) + namlen + 2, sizeof(compat_long_t));
983+
int reclen = ALIGN(offsetof(struct compat_linux_dirent, d_name) +
984+
namlen + 2, sizeof(compat_long_t));
985985

986986
buf->error = -EINVAL; /* only used if we fail.. */
987987
if (reclen > buf->count)
@@ -1068,8 +1068,8 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
10681068
{
10691069
struct linux_dirent64 __user *dirent;
10701070
struct compat_getdents_callback64 *buf = __buf;
1071-
int jj = NAME_OFFSET(dirent);
1072-
int reclen = ALIGN(jj + namlen + 1, sizeof(u64));
1071+
int reclen = ALIGN(offsetof(struct linux_dirent64, d_name) + namlen + 1,
1072+
sizeof(u64));
10731073
u64 off;
10741074

10751075
buf->error = -EINVAL; /* only used if we fail.. */

fs/readdir.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (C) 1995 Linus Torvalds
55
*/
66

7+
#include <linux/stddef.h>
78
#include <linux/kernel.h>
89
#include <linux/module.h>
910
#include <linux/time.h>
@@ -54,7 +55,6 @@ EXPORT_SYMBOL(vfs_readdir);
5455
* anyway. Thus the special "fillonedir()" function for that
5556
* case (the low-level handlers don't need to care about this).
5657
*/
57-
#define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
5858

5959
#ifdef __ARCH_WANT_OLD_READDIR
6060

@@ -152,7 +152,8 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
152152
struct linux_dirent __user * dirent;
153153
struct getdents_callback * buf = (struct getdents_callback *) __buf;
154154
unsigned long d_ino;
155-
int reclen = ALIGN(NAME_OFFSET(dirent) + namlen + 2, sizeof(long));
155+
int reclen = ALIGN(offsetof(struct linux_dirent, d_name) + namlen + 2,
156+
sizeof(long));
156157

157158
buf->error = -EINVAL; /* only used if we fail.. */
158159
if (reclen > buf->count)
@@ -237,7 +238,8 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
237238
{
238239
struct linux_dirent64 __user *dirent;
239240
struct getdents_callback64 * buf = (struct getdents_callback64 *) __buf;
240-
int reclen = ALIGN(NAME_OFFSET(dirent) + namlen + 1, sizeof(u64));
241+
int reclen = ALIGN(offsetof(struct linux_dirent64, d_name) + namlen + 1,
242+
sizeof(u64));
241243

242244
buf->error = -EINVAL; /* only used if we fail.. */
243245
if (reclen > buf->count)

0 commit comments

Comments
 (0)