Skip to content

Commit 0fdb474

Browse files
SinkFinderjgross1
authored andcommitted
xen: set error code on failures
Variable rc is reset in the loop, and its value will be non-negative during the second and after repeat of the loop. If it fails to allocate memory then, it may return a non-negative integer, which indicates no error. This patch fixes the bug, assigning "-ENOMEM" to rc when kzalloc() or alloc_page() returns NULL, and removing the initialization of rc outside of the loop. Signed-off-by: Pan Bian <bianpan2016@163.com> Reviewed-by: Juergen Gross <jgross@suse.com> Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent 24d5373 commit 0fdb474

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/xen/gntalloc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,21 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
127127
struct gntalloc_gref *gref, *next;
128128

129129
readonly = !(op->flags & GNTALLOC_FLAG_WRITABLE);
130-
rc = -ENOMEM;
131130
for (i = 0; i < op->count; i++) {
132131
gref = kzalloc(sizeof(*gref), GFP_KERNEL);
133-
if (!gref)
132+
if (!gref) {
133+
rc = -ENOMEM;
134134
goto undo;
135+
}
135136
list_add_tail(&gref->next_gref, &queue_gref);
136137
list_add_tail(&gref->next_file, &queue_file);
137138
gref->users = 1;
138139
gref->file_index = op->index + i * PAGE_SIZE;
139140
gref->page = alloc_page(GFP_KERNEL|__GFP_ZERO);
140-
if (!gref->page)
141+
if (!gref->page) {
142+
rc = -ENOMEM;
141143
goto undo;
144+
}
142145

143146
/* Grant foreign access to the page. */
144147
rc = gnttab_grant_foreign_access(op->domid,

0 commit comments

Comments
 (0)