2020-01-20 09:00:11

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH -next] watch_queue: Fix error return code in watch_queue_set_size()

Fix to return a negative error code from the error handling
case instead of 0, as done elsewhere in this function.

Fixes: d9a34f010efd ("pipe: Add general notification queue support")
Signed-off-by: Wei Yongjun <[email protected]>
---
kernel/watch_queue.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
index f195cbbbb3d3..3051cf4e35c6 100644
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -252,21 +252,27 @@ long watch_queue_set_size(struct pipe_inode_info *pipe, unsigned int nr_notes)
goto error;

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

for (i = 0; i < nr_pages; i++) {
pages[i] = alloc_page(GFP_KERNEL);
- if (!pages[i])
+ if (!pages[i]) {
+ ret = -ENOMEM;
goto error_p;
+ }
pages[i]->index = i * WATCH_QUEUE_NOTES_PER_PAGE;
}

bmsize = (nr_notes + BITS_PER_LONG - 1) / BITS_PER_LONG;
bmsize *= sizeof(unsigned long);
bitmap = kmalloc(bmsize, GFP_KERNEL);
- if (!bitmap)
+ if (!bitmap) {
+ ret = -ENOMEM;
goto error_p;
+ }

memset(bitmap, 0xff, bmsize);
wqueue->notes = pages;




2020-01-20 11:33:47

by David Howells

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

Wei Yongjun <[email protected]> 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;

2020-01-22 07:54:27

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH -next v2] watch_queue: fix error return code in watch_queue_set_size()

Fix to return negative error code -ENOMEM from the error handling
case instead of 0, as done elsewhere in this function.

Fixes: 009b0aa00c5a ("pipe: Add general notification queue support")
Signed-off-by: Wei Yongjun <[email protected]>
---
kernel/watch_queue.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
index f195cbbbb3d3..f1028761cb9c 100644
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -251,6 +251,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;