[ Upstream commit 02551c23bcd85f0c68a8259c7b953d49d44f86af ] When fget fails, the lack of error-handling code may cause unexpected results.
This patch adds error-handling code after calling fget. Link: http://lkml.kernel.org/r/2514ec03df9c33b86e56748513267a80dd8004d9.1558117389.git.jahar...@cs.cmu.edu Signed-off-by: Zhouyang Jia <jiazhouyan...@gmail.com> Signed-off-by: Jan Harkes <jahar...@cs.cmu.edu> Cc: Arnd Bergmann <a...@arndb.de> Cc: Colin Ian King <colin.k...@canonical.com> Cc: Dan Carpenter <dan.carpen...@oracle.com> Cc: David Howells <dhowe...@redhat.com> Cc: Fabian Frederick <f...@skynet.be> Cc: Mikko Rapeli <mikko.rap...@iki.fi> Cc: Sam Protsenko <semen.protse...@linaro.org> Cc: Yann Droneaud <ydrone...@opteya.com> Signed-off-by: Andrew Morton <a...@linux-foundation.org> Signed-off-by: Linus Torvalds <torva...@linux-foundation.org> Signed-off-by: Sasha Levin <sas...@kernel.org> --- 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 f40e3953e7fe3..a6d9e841a375c 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; + } } wake_up(&req->uc_sleep); -- 2.20.1