nfsd: add appropriate __force directives to filehandle generation code
authorJeff Layton <jlayton@primarydata.com>
Tue, 17 Jun 2014 11:44:14 +0000 (07:44 -0400)
committerJ. Bruce Fields <bfields@redhat.com>
Mon, 23 Jun 2014 15:31:37 +0000 (11:31 -0400)
The filehandle structs all use host-endian values, but will sometimes
stuff big-endian values into those fields. This is OK since these
values are opaque to the client, but it confuses sparse. Add __force to
make it clear that we are doing this intentionally.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/nfsfh.c
fs/nfsd/nfsfh.h

index 6f5cc76a6c6e898e52fdd11db02327e8f0b0b4d4..e883a5868be6212be3e4e9bf3b6073730566ef57 100644 (file)
@@ -162,7 +162,14 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
                        /* deprecated, convert to type 3 */
                        len = key_len(FSID_ENCODE_DEV)/4;
                        fh->fh_fsid_type = FSID_ENCODE_DEV;
-                       fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl(fh->fh_fsid[0]), ntohl(fh->fh_fsid[1])));
+                       /*
+                        * struct knfsd_fh uses host-endian fields, which are
+                        * sometimes used to hold net-endian values. This
+                        * confuses sparse, so we must use __force here to
+                        * keep it from complaining.
+                        */
+                       fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl((__force __be32)fh->fh_fsid[0]),
+                                                       ntohl((__force __be32)fh->fh_fsid[1])));
                        fh->fh_fsid[1] = fh->fh_fsid[2];
                }
                data_left -= len;
index 2e89e70ac15c8f2df95fcac9d58b7b96bd93cb42..08236d70c667e76df879b358be5478d1ec6f92cf 100644 (file)
@@ -73,8 +73,15 @@ enum fsid_source {
 extern enum fsid_source fsid_source(struct svc_fh *fhp);
 
 
-/* This might look a little large to "inline" but in all calls except
+/*
+ * This might look a little large to "inline" but in all calls except
  * one, 'vers' is constant so moste of the function disappears.
+ *
+ * In some cases the values are considered to be host endian and in
+ * others, net endian. fsidv is always considered to be u32 as the
+ * callers don't know which it will be. So we must use __force to keep
+ * sparse from complaining. Since these values are opaque to the
+ * client, that shouldn't be a problem.
  */
 static inline void mk_fsid(int vers, u32 *fsidv, dev_t dev, ino_t ino,
                           u32 fsid, unsigned char *uuid)
@@ -82,7 +89,7 @@ static inline void mk_fsid(int vers, u32 *fsidv, dev_t dev, ino_t ino,
        u32 *up;
        switch(vers) {
        case FSID_DEV:
-               fsidv[0] = htonl((MAJOR(dev)<<16) |
+               fsidv[0] = (__force __u32)htonl((MAJOR(dev)<<16) |
                                 MINOR(dev));
                fsidv[1] = ino_t_to_u32(ino);
                break;
@@ -90,8 +97,8 @@ static inline void mk_fsid(int vers, u32 *fsidv, dev_t dev, ino_t ino,
                fsidv[0] = fsid;
                break;
        case FSID_MAJOR_MINOR:
-               fsidv[0] = htonl(MAJOR(dev));
-               fsidv[1] = htonl(MINOR(dev));
+               fsidv[0] = (__force __u32)htonl(MAJOR(dev));
+               fsidv[1] = (__force __u32)htonl(MINOR(dev));
                fsidv[2] = ino_t_to_u32(ino);
                break;
 
This page took 0.026291 seconds and 5 git commands to generate.