* [PATCH 1/1] xen: set error code on failures
@ 2016-12-04 6:24 Pan Bian
2016-12-05 6:56 ` Juergen Gross
0 siblings, 1 reply; 2+ messages in thread
From: Pan Bian @ 2016-12-04 6:24 UTC (permalink / raw)
To: Boris Ostrovsky, David Vrabel, Juergen Gross, xen-devel
Cc: linux-kernel, Pan Bian
From: Pan Bian <bianpan2016@163.com>
The return variable rc is initialized with "-ENOMEM" outside the loop.
However, it is reset in the loop, and its value is not negative during
the second or after repeat of the loop. If kzalloc() fails then, it will
return 0. This patch fixes the bug, assigning "-ENOMEM" to rc when
kzalloc() or alloc_page() returns NULL.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189111
Signed-off-by: Pan Bian <bianpan2016@163.com>
---
drivers/xen/gntalloc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
index 7a47c4c..55ef246 100644
--- a/drivers/xen/gntalloc.c
+++ b/drivers/xen/gntalloc.c
@@ -130,15 +130,19 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
rc = -ENOMEM;
for (i = 0; i < op->count; i++) {
gref = kzalloc(sizeof(*gref), GFP_KERNEL);
- if (!gref)
+ if (!gref) {
+ rc = -ENOMEM;
goto undo;
+ }
list_add_tail(&gref->next_gref, &queue_gref);
list_add_tail(&gref->next_file, &queue_file);
gref->users = 1;
gref->file_index = op->index + i * PAGE_SIZE;
gref->page = alloc_page(GFP_KERNEL|__GFP_ZERO);
- if (!gref->page)
+ if (!gref->page) {
+ rc = -ENOMEM;
goto undo;
+ }
/* Grant foreign access to the page. */
rc = gnttab_grant_foreign_access(op->domid,
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] xen: set error code on failures
2016-12-04 6:24 [PATCH 1/1] xen: set error code on failures Pan Bian
@ 2016-12-05 6:56 ` Juergen Gross
0 siblings, 0 replies; 2+ messages in thread
From: Juergen Gross @ 2016-12-05 6:56 UTC (permalink / raw)
To: Pan Bian, Boris Ostrovsky, David Vrabel, xen-devel; +Cc: linux-kernel, Pan Bian
On 04/12/16 07:24, Pan Bian wrote:
> From: Pan Bian <bianpan2016@163.com>
>
> The return variable rc is initialized with "-ENOMEM" outside the loop.
> However, it is reset in the loop, and its value is not negative during
> the second or after repeat of the loop. If kzalloc() fails then, it will
> return 0. This patch fixes the bug, assigning "-ENOMEM" to rc when
> kzalloc() or alloc_page() returns NULL.
>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189111
>
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> ---
> drivers/xen/gntalloc.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
> index 7a47c4c..55ef246 100644
> --- a/drivers/xen/gntalloc.c
> +++ b/drivers/xen/gntalloc.c
> @@ -130,15 +130,19 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
> rc = -ENOMEM;
You can drop this now.
> for (i = 0; i < op->count; i++) {
> gref = kzalloc(sizeof(*gref), GFP_KERNEL);
> - if (!gref)
> + if (!gref) {
> + rc = -ENOMEM;
> goto undo;
> + }
> list_add_tail(&gref->next_gref, &queue_gref);
> list_add_tail(&gref->next_file, &queue_file);
> gref->users = 1;
> gref->file_index = op->index + i * PAGE_SIZE;
> gref->page = alloc_page(GFP_KERNEL|__GFP_ZERO);
> - if (!gref->page)
> + if (!gref->page) {
> + rc = -ENOMEM;
> goto undo;
> + }
>
> /* Grant foreign access to the page. */
> rc = gnttab_grant_foreign_access(op->domid,
>
Juergen
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-12-05 6:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-04 6:24 [PATCH 1/1] xen: set error code on failures Pan Bian
2016-12-05 6:56 ` Juergen Gross
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).