[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/11] Change xen_host_pci_sysfs_path() to return voi
From: |
Stefano Stabellini |
Subject: |
[Qemu-devel] [PULL 06/11] Change xen_host_pci_sysfs_path() to return void |
Date: |
Thu, 21 Jan 2016 17:01:25 +0000 |
From: Cao jin <address@hidden>
And assert the snprintf() error, because user can do nothing in case of
snprintf() fail.
Signed-off-by: Cao jin <address@hidden>
Reviewed-by: Stefano Stabellini <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
hw/xen/xen-host-pci-device.c | 35 +++++++++++------------------------
1 file changed, 11 insertions(+), 24 deletions(-)
diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c
index 7d8a023..9c342e7 100644
--- a/hw/xen/xen-host-pci-device.c
+++ b/hw/xen/xen-host-pci-device.c
@@ -31,19 +31,14 @@
#define IORESOURCE_PREFETCH 0x00001000 /* No side effects */
#define IORESOURCE_MEM_64 0x00100000
-static int xen_host_pci_sysfs_path(const XenHostPCIDevice *d,
- const char *name, char *buf, ssize_t size)
+static void xen_host_pci_sysfs_path(const XenHostPCIDevice *d,
+ const char *name, char *buf, ssize_t size)
{
int rc;
rc = snprintf(buf, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s",
d->domain, d->bus, d->dev, d->func, name);
-
- if (rc >= size || rc < 0) {
- /* The output is truncated, or some other error was encountered */
- return -ENODEV;
- }
- return 0;
+ assert(rc >= 0 && rc < size);
}
@@ -58,10 +53,8 @@ static int xen_host_pci_get_resource(XenHostPCIDevice *d)
char *endptr, *s;
uint8_t type;
- rc = xen_host_pci_sysfs_path(d, "resource", path, sizeof (path));
- if (rc) {
- return rc;
- }
+ xen_host_pci_sysfs_path(d, "resource", path, sizeof(path));
+
fd = open(path, O_RDONLY);
if (fd == -1) {
XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));
@@ -150,10 +143,8 @@ static int xen_host_pci_get_value(XenHostPCIDevice *d,
const char *name,
unsigned long value;
char *endptr;
- rc = xen_host_pci_sysfs_path(d, name, path, sizeof (path));
- if (rc) {
- return rc;
- }
+ xen_host_pci_sysfs_path(d, name, path, sizeof(path));
+
fd = open(path, O_RDONLY);
if (fd == -1) {
XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));
@@ -200,21 +191,17 @@ static bool xen_host_pci_dev_is_virtfn(XenHostPCIDevice
*d)
char path[PATH_MAX];
struct stat buf;
- if (xen_host_pci_sysfs_path(d, "physfn", path, sizeof (path))) {
- return false;
- }
+ xen_host_pci_sysfs_path(d, "physfn", path, sizeof(path));
+
return !stat(path, &buf);
}
static int xen_host_pci_config_open(XenHostPCIDevice *d)
{
char path[PATH_MAX];
- int rc;
- rc = xen_host_pci_sysfs_path(d, "config", path, sizeof (path));
- if (rc) {
- return rc;
- }
+ xen_host_pci_sysfs_path(d, "config", path, sizeof(path));
+
d->config_fd = open(path, O_RDWR);
if (d->config_fd < 0) {
return -errno;
--
1.7.10.4
- [Qemu-devel] [PULL 0/11] xen-20160121, Stefano Stabellini, 2016/01/21
- [Qemu-devel] [PULL 07/11] Xen: use qemu_strtoul instead of strtol, Stefano Stabellini, 2016/01/21
- [Qemu-devel] [PULL 04/11] xen-hvm: Clean up xen_ram_alloc() error handling, Stefano Stabellini, 2016/01/21
- [Qemu-devel] [PULL 10/11] Add Error **errp for xen_pt_config_init(), Stefano Stabellini, 2016/01/21
- [Qemu-devel] [PULL 03/11] xen-hvm: Clean up xen_hvm_init() error handling, Stefano Stabellini, 2016/01/21
- [Qemu-devel] [PULL 05/11] xen-pvdevice: convert to realize(), Stefano Stabellini, 2016/01/21
- [Qemu-devel] [PULL 01/11] MAINTAINERS: update Xen files, Stefano Stabellini, 2016/01/21
- [Qemu-devel] [PULL 06/11] Change xen_host_pci_sysfs_path() to return void,
Stefano Stabellini <=
- [Qemu-devel] [PULL 08/11] Add Error **errp for xen_host_pci_device_get(), Stefano Stabellini, 2016/01/21
- [Qemu-devel] [PULL 09/11] Add Error **errp for xen_pt_setup_vga(), Stefano Stabellini, 2016/01/21
- [Qemu-devel] [PULL 02/11] xenfb.c: avoid expensive loops when prod <= out_cons, Stefano Stabellini, 2016/01/21
- [Qemu-devel] [PULL 11/11] Xen PCI passthru: convert to realize(), Stefano Stabellini, 2016/01/21
- Re: [Qemu-devel] [PULL 0/11] xen-20160121, Peter Maydell, 2016/01/21