Bug 46881 - inode.c:157: bad call to memset
Summary: inode.c:157: bad call to memset
Status: CLOSED CODE_FIX
Alias: None
Product: File System
Classification: Unclassified
Component: NFS (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Trond Myklebust
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-02 14:49 UTC by David Binderman
Modified: 2012-10-30 18:26 UTC (History)
1 user (show)

See Also:
Kernel Version: 3.6-rc4
Subsystem:
Regression: No
Bisected commit-id:


Attachments
NFS: Fix the initialisation of the readdir 'cookieverf' array (3.34 KB, patch)
2012-09-03 19:19 UTC, Trond Myklebust
Details | Diff

Description David Binderman 2012-09-02 14:49:00 UTC
I just tried to compile linux-3.6-rc4 with a recent snapshot
of the gcc compiler. It said

fs/nfs/inode.c:157:41: warning: argument to ‘sizeof’ in ‘memset’ call is the same pointer type ‘__be32 *’ as the destination; expected ‘__be32’ or an explicit length [-Wsizeof-pointer-memaccess]

The source code is

    memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));

maybe something like

    memset(NFS_COOKIEVERF(inode), 0, sizeof(__be32));

might be better.
Comment 1 Trond Myklebust 2012-09-02 21:57:27 UTC
That would be a gcc regression, not a kernel bug.

NFS_COOKIEVERF(inode) points to the 'cookieverf' field in struct nfs_inode,
which is an array. If the 'sizeof' operator suddenly thinks that it is a
pointer, then that's a pretty major gcc bug...

Marking this as resolved invalid.
Comment 2 David Binderman 2012-09-03 18:59:17 UTC
>That would be a gcc regression, not a kernel bug.

Can't see that, myself. The code looks to me like

    memset(X, 0, sizeof(X));

First parameter is memset is a pointer, so I wouldn't expect to
see that first parameter duplicated as the third parameter.

I would expect to see something like

    memset(X, 0, sizeof(*X));

or maybe

    memset(X, 0, SOME_NUMBER * sizeof(*X));
Comment 3 Trond Myklebust 2012-09-03 19:17:26 UTC
No...

The problem is that NFS_COOKIEVERF got changed from being a macro to
a static inline back in 2.6.25. That changed the type being passed to
the memset() from being an array to being a pointer.

At this point NFS_COOKIEVERF appears to be pure obfuscation and just needs
to be removed altogether.
Comment 4 Trond Myklebust 2012-09-03 19:19:25 UTC
Created attachment 79151 [details]
NFS: Fix the initialisation of the readdir 'cookieverf' array
Comment 5 Florian Mickler 2012-09-19 22:13:33 UTC
A patch referencing this bug report has been merged in Linux v3.6-rc6:

commit c3f52af3e03013db5237e339c817beaae5ec9e3a
Author: Trond Myklebust <Trond.Myklebust@netapp.com>
Date:   Mon Sep 3 14:56:02 2012 -0400

    NFS: Fix the initialisation of the readdir 'cookieverf' array

Note You need to log in before you can comment on or make changes to this bug.