coda: add error handling for fget [Linux 4.9.188]

This Linux kernel change "coda: add error handling for fget" is included in the Linux 4.9.188 release. This change is authored by Zhouyang Jia <jiazhouyang09 [at]> on Tue Jul 16 16:28:13 2019 -0700. The commit for this change in Linux stable tree is ca62806 (patch) which is from upstream commit 02551c2. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 02551c2.

coda: add error handling for fget

[ Upstream commit 02551c23bcd85f0c68a8259c7b953d49d44f86af ]

When fget fails, the lack of error-handling code may cause unexpected

This patch adds error-handling code after calling fget.

Link:[email protected]
Signed-off-by: Zhouyang Jia <[email protected]>
Signed-off-by: Jan Harkes <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Colin Ian King <[email protected]>
Cc: Dan Carpenter <[email protected]>
Cc: David Howells <[email protected]>
Cc: Fabian Frederick <[email protected]>
Cc: Mikko Rapeli <[email protected]>
Cc: Sam Protsenko <[email protected]>
Cc: Yann Droneaud <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>

There are 5 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/coda/psdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c
index 8226291..ff9b5cf 100644
--- a/fs/coda/psdev.c
+++ b/fs/coda/psdev.c
@@ -187,8 +187,11 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
    if (req->uc_opcode == CODA_OPEN_BY_FD) {
        struct coda_open_by_fd_out *outp =
            (struct coda_open_by_fd_out *)req->uc_data;
-       if (!outp->oh.result)
+       if (!outp->oh.result) {
            outp->fh = fget(outp->fd);
+           if (!outp->fh)
+               return -EBADF;
+       }


Leave a Reply

Your email address will not be published. Required fields are marked *