* [PATCH -next] watch_queue: Fix error return code in watch_queue_set_size()
@ 2021-05-19 14:16 Wei Yongjun
0 siblings, 0 replies; 4+ messages in thread
From: Wei Yongjun @ 2021-05-19 14:16 UTC (permalink / raw)
To: weiyongjun1, David Howells, Jarkko Sakkinen, Lukas Bulwahn
Cc: linux-kernel, Hulk Robot
Fix to return negative error code -ENOMEM from the alloc failed error
handling cases instead of 0, as done elsewhere in this function.
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
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 9c9eb20dd2c5..35e03b1bfadd 100644
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -248,21 +248,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;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next] watch_queue: Fix error return code in watch_queue_set_size()
2020-01-20 8:54 ` Wei Yongjun
(?)
@ 2020-01-20 11:32 ` David Howells
-1 siblings, 0 replies; 4+ messages in thread
From: David Howells @ 2020-01-20 11:32 UTC (permalink / raw)
To: Wei Yongjun; +Cc: dhowells, linux-kernel, kernel-janitors
Wei Yongjun <weiyongjun1@huawei.com> 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;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH -next] watch_queue: Fix error return code in watch_queue_set_size()
@ 2020-01-20 8:54 ` Wei Yongjun
0 siblings, 0 replies; 4+ messages in thread
From: Wei Yongjun @ 2020-01-20 8:54 UTC (permalink / raw)
To: David Howells; +Cc: Wei Yongjun, linux-kernel, kernel-janitors
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 <weiyongjun1@huawei.com>
---
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;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH -next] watch_queue: Fix error return code in watch_queue_set_size()
@ 2020-01-20 8:54 ` Wei Yongjun
0 siblings, 0 replies; 4+ messages in thread
From: Wei Yongjun @ 2020-01-20 8:54 UTC (permalink / raw)
To: David Howells; +Cc: Wei Yongjun, linux-kernel, kernel-janitors
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 <weiyongjun1@huawei.com>
---
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;
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-19 14:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 14:16 [PATCH -next] watch_queue: Fix error return code in watch_queue_set_size() Wei Yongjun
-- strict thread matches above, loose matches on Subject: below --
2020-01-20 8:54 Wei Yongjun
2020-01-20 8:54 ` Wei Yongjun
2020-01-20 11:32 ` David Howells
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.