Skip to content

Commit 578c1bb

Browse files
jgross1bostrovs
authored andcommitted
xen/xenbus: let xenbus_map_ring_valloc() return errno values only
Today xenbus_map_ring_valloc() can return either a negative errno value (-ENOMEM or -EINVAL) or a grant status value. This is a mess as e.g -ENOMEM and GNTST_eagain have the same numeric value. Fix that by turning all grant mapping errors into -ENOENT. This is no problem as all callers of xenbus_map_ring_valloc() only use the return value to print an error message, and in case of mapping errors the grant status value has already been printed by __xenbus_map_ring() before. Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Boris Ostrovsky <[email protected]>
1 parent 3848e4e commit 578c1bb

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

drivers/xen/xenbus/xenbus_client.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,7 @@ EXPORT_SYMBOL_GPL(xenbus_free_evtchn);
456456
* Map @nr_grefs pages of memory into this domain from another
457457
* domain's grant table. xenbus_map_ring_valloc allocates @nr_grefs
458458
* pages of virtual address space, maps the pages to that address, and
459-
* sets *vaddr to that address. Returns 0 on success, and GNTST_*
460-
* (see xen/include/interface/grant_table.h) or -ENOMEM / -EINVAL on
459+
* sets *vaddr to that address. Returns 0 on success, and -errno on
461460
* error. If an error is returned, device will switch to
462461
* XenbusStateClosing and the error message will be saved in XenStore.
463462
*/
@@ -477,18 +476,11 @@ int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs,
477476
return -ENOMEM;
478477

479478
info->node = kzalloc(sizeof(*info->node), GFP_KERNEL);
480-
if (!info->node) {
479+
if (!info->node)
481480
err = -ENOMEM;
482-
goto out;
483-
}
484-
485-
err = ring_ops->map(dev, info, gnt_refs, nr_grefs, vaddr);
486-
487-
/* Some hypervisors are buggy and can return 1. */
488-
if (err > 0)
489-
err = GNTST_general_error;
481+
else
482+
err = ring_ops->map(dev, info, gnt_refs, nr_grefs, vaddr);
490483

491-
out:
492484
kfree(info->node);
493485
kfree(info);
494486
return err;
@@ -507,7 +499,6 @@ static int __xenbus_map_ring(struct xenbus_device *dev,
507499
bool *leaked)
508500
{
509501
int i, j;
510-
int err = GNTST_okay;
511502

512503
if (nr_grefs > XENBUS_MAX_RING_GRANTS)
513504
return -EINVAL;
@@ -522,7 +513,6 @@ static int __xenbus_map_ring(struct xenbus_device *dev,
522513

523514
for (i = 0; i < nr_grefs; i++) {
524515
if (info->map[i].status != GNTST_okay) {
525-
err = info->map[i].status;
526516
xenbus_dev_fatal(dev, info->map[i].status,
527517
"mapping in shared page %d from domain %d",
528518
gnt_refs[i], dev->otherend_id);
@@ -531,7 +521,7 @@ static int __xenbus_map_ring(struct xenbus_device *dev,
531521
handles[i] = info->map[i].handle;
532522
}
533523

534-
return GNTST_okay;
524+
return 0;
535525

536526
fail:
537527
for (i = j = 0; i < nr_grefs; i++) {
@@ -554,7 +544,7 @@ static int __xenbus_map_ring(struct xenbus_device *dev,
554544
}
555545
}
556546

557-
return err;
547+
return -ENOENT;
558548
}
559549

560550
/**

0 commit comments

Comments
 (0)