Skip to content

Commit 0a688ad

Browse files
hharrisontorvalds
authored andcommitted
ecryptfs: inode.c mmap.c use unaligned byteorder helpers
Fixe sparse warnings: fs/ecryptfs/inode.c:368:15: warning: cast to restricted __be64 fs/ecryptfs/mmap.c:385:12: warning: incorrect type in assignment (different base types) fs/ecryptfs/mmap.c:385:12: expected unsigned long long [unsigned] [assigned] [usertype] file_size fs/ecryptfs/mmap.c:385:12: got restricted __be64 [usertype] <noident> fs/ecryptfs/mmap.c:428:12: warning: incorrect type in assignment (different base types) fs/ecryptfs/mmap.c:428:12: expected unsigned long long [unsigned] [assigned] [usertype] file_size fs/ecryptfs/mmap.c:428:12: got restricted __be64 [usertype] <noident> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Cc: Michael Halcrow <mhalcrow@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 29335c6 commit 0a688ad

2 files changed

Lines changed: 5 additions & 10 deletions

File tree

‎fs/ecryptfs/inode.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/mount.h>
3232
#include <linux/crypto.h>
3333
#include <linux/fs_stack.h>
34+
#include <asm/unaligned.h>
3435
#include "ecryptfs_kernel.h"
3536

3637
static struct dentry *lock_parent(struct dentry *dentry)
@@ -364,8 +365,7 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
364365
else
365366
file_size = i_size_read(lower_dentry->d_inode);
366367
} else {
367-
memcpy(&file_size, page_virt, sizeof(file_size));
368-
file_size = be64_to_cpu(file_size);
368+
file_size = get_unaligned_be64(page_virt);
369369
}
370370
i_size_write(dentry->d_inode, (loff_t)file_size);
371371
kmem_cache_free(ecryptfs_header_cache_2, page_virt);

‎fs/ecryptfs/mmap.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/file.h>
3333
#include <linux/crypto.h>
3434
#include <linux/scatterlist.h>
35+
#include <asm/unaligned.h>
3536
#include "ecryptfs_kernel.h"
3637

3738
/**
@@ -372,7 +373,6 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
372373
*/
373374
static int ecryptfs_write_inode_size_to_header(struct inode *ecryptfs_inode)
374375
{
375-
u64 file_size;
376376
char *file_size_virt;
377377
int rc;
378378

@@ -381,9 +381,7 @@ static int ecryptfs_write_inode_size_to_header(struct inode *ecryptfs_inode)
381381
rc = -ENOMEM;
382382
goto out;
383383
}
384-
file_size = (u64)i_size_read(ecryptfs_inode);
385-
file_size = cpu_to_be64(file_size);
386-
memcpy(file_size_virt, &file_size, sizeof(u64));
384+
put_unaligned_be64(i_size_read(ecryptfs_inode), file_size_virt);
387385
rc = ecryptfs_write_lower(ecryptfs_inode, file_size_virt, 0,
388386
sizeof(u64));
389387
kfree(file_size_virt);
@@ -403,7 +401,6 @@ static int ecryptfs_write_inode_size_to_xattr(struct inode *ecryptfs_inode)
403401
struct dentry *lower_dentry =
404402
ecryptfs_inode_to_private(ecryptfs_inode)->lower_file->f_dentry;
405403
struct inode *lower_inode = lower_dentry->d_inode;
406-
u64 file_size;
407404
int rc;
408405

409406
if (!lower_inode->i_op->getxattr || !lower_inode->i_op->setxattr) {
@@ -424,9 +421,7 @@ static int ecryptfs_write_inode_size_to_xattr(struct inode *ecryptfs_inode)
424421
xattr_virt, PAGE_CACHE_SIZE);
425422
if (size < 0)
426423
size = 8;
427-
file_size = (u64)i_size_read(ecryptfs_inode);
428-
file_size = cpu_to_be64(file_size);
429-
memcpy(xattr_virt, &file_size, sizeof(u64));
424+
put_unaligned_be64(i_size_read(ecryptfs_inode), xattr_virt);
430425
rc = lower_inode->i_op->setxattr(lower_dentry, ECRYPTFS_XATTR_NAME,
431426
xattr_virt, size, 0);
432427
mutex_unlock(&lower_inode->i_mutex);

0 commit comments

Comments
 (0)