Skip to content

Commit 2000f5b

Browse files
committed
eCryptfs: file->private_data is always valid
When accessing the lower_file pointer located in private_data of eCryptfs files, there is no need to check to see if the private_data pointer has been initialized to a non-NULL value. The file->private_data and file->private_data->lower_file pointers are always initialized to non-NULL values in ecryptfs_open(). This change quiets a Smatch warning: CHECK /var/scm/kernel/linux/fs/ecryptfs/file.c fs/ecryptfs/file.c:321 ecryptfs_unlocked_ioctl() error: potential NULL dereference 'lower_file'. fs/ecryptfs/file.c:335 ecryptfs_compat_ioctl() error: potential NULL dereference 'lower_file'. Signed-off-by: Tyler Hicks <[email protected]> Reported-by: Dan Carpenter <[email protected]> Reviewed-by: Geyslan G. Bem <[email protected]> Cc: Al Viro <[email protected]>
1 parent 42a2d92 commit 2000f5b

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

fs/ecryptfs/file.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,9 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag)
313313
static long
314314
ecryptfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
315315
{
316-
struct file *lower_file = NULL;
316+
struct file *lower_file = ecryptfs_file_to_lower(file);
317317
long rc = -ENOTTY;
318318

319-
if (ecryptfs_file_to_private(file))
320-
lower_file = ecryptfs_file_to_lower(file);
321319
if (lower_file->f_op->unlocked_ioctl)
322320
rc = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg);
323321
return rc;
@@ -327,11 +325,9 @@ ecryptfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
327325
static long
328326
ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
329327
{
330-
struct file *lower_file = NULL;
328+
struct file *lower_file = ecryptfs_file_to_lower(file);
331329
long rc = -ENOIOCTLCMD;
332330

333-
if (ecryptfs_file_to_private(file))
334-
lower_file = ecryptfs_file_to_lower(file);
335331
if (lower_file->f_op && lower_file->f_op->compat_ioctl)
336332
rc = lower_file->f_op->compat_ioctl(lower_file, cmd, arg);
337333
return rc;

0 commit comments

Comments
 (0)