Re: [PATCH -next] watch_queue: Fix error return code in watch_queue_set_size()

From: David Howells
Date: Mon Jan 20 2020 - 06:32:37 EST


Wei Yongjun <weiyongjun1@xxxxxxxxxx> wrote:

> pages = kcalloc(sizeof(struct page *), nr_pages, GFP_KERNEL);
> - if (!pages)
> + if (!pages) {
> + ret = -ENOMEM;

I think the preferred method would be to set ret before calling kcalloc as the
attached.

David
---

diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
index 8c625cf451e6..a11724d66834 100644
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -249,6 +249,7 @@ long watch_queue_set_size(struct pipe_inode_info *pipe, unsigned int nr_notes)
if (ret < 0)
goto error;

+ ret = -ENOMEM;
pages = kcalloc(sizeof(struct page *), nr_pages, GFP_KERNEL);
if (!pages)
goto error;