From 351bbad39a5c5a1c3623c0b183ef121565e31dd2 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 2 Jan 2021 23:31:07 +0800 Subject: [PATCH] fs: Remove inode null check from file_dup and fs_dupfd2 since the same check already done in file_dup2 Signed-off-by: Xiang Xiao Change-Id: I7ba1309c55be1ac564f798df02fc6725c4a0d469 --- fs/inode/fs_files.c | 5 +++++ fs/vfs/fs_dupfd.c | 15 +-------------- fs/vfs/fs_dupfd2.c | 24 ------------------------ 3 files changed, 6 insertions(+), 38 deletions(-) diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index af466e8f998..6d549d2313b 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -188,6 +188,11 @@ int file_dup2(FAR struct file *filep1, FAR struct file *filep2) return -EBADF; } + if (filep1 == filep2) + { + return OK; + } + list = nxsched_get_files(); /* The file list can be NULL under two cases: (1) One is an obscure diff --git a/fs/vfs/fs_dupfd.c b/fs/vfs/fs_dupfd.c index 5364bdef939..c3525ae79d6 100644 --- a/fs/vfs/fs_dupfd.c +++ b/fs/vfs/fs_dupfd.c @@ -32,12 +32,6 @@ #include "inode/inode.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DUP_ISOPEN(filep) (filep->f_inode != NULL) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -61,14 +55,7 @@ int file_dup(FAR struct file *filep, int minfd) int fd2; int ret; - /* Verify that fd is a valid, open file descriptor */ - - if (!DUP_ISOPEN(filep)) - { - return -EBADF; - } - - /* Then allocate a new file descriptor for the inode */ + /* Allocate a new file descriptor for the inode */ fd2 = files_allocate(NULL, 0, 0, minfd); if (fd2 < 0) diff --git a/fs/vfs/fs_dupfd2.c b/fs/vfs/fs_dupfd2.c index d314a224acc..3ad7aa0c287 100644 --- a/fs/vfs/fs_dupfd2.c +++ b/fs/vfs/fs_dupfd2.c @@ -46,16 +46,6 @@ #include "inode/inode.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DUP_ISOPEN(filep) (filep->f_inode != NULL) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -93,20 +83,6 @@ int fs_dupfd2(int fd1, int fd2) DEBUGASSERT(filep1 != NULL && filep2 != NULL); - /* Verify that fd1 is a valid, open file descriptor */ - - if (!DUP_ISOPEN(filep1)) - { - return -EBADF; - } - - /* Handle a special case */ - - if (fd1 == fd2) - { - return fd1; - } - /* Perform the dup2 operation */ return file_dup2(filep1, filep2);