[openib-general] [PATCH] fix thinko in libibverbs (was Re: [libibverbs] [PATCH] Added checks to memory allocation failure when using asprintf)
Michael S. Tsirkin
mst at mellanox.co.il
Thu Jan 18 02:06:12 PST 2007
> Quoting Roland Dreier <rdreier at cisco.com>:
> Subject: Re: [libibverbs] [PATCH] Added checks to memory allocation failure when using asprintf
>
> Thanks, applied to master and stable branches of libibverbs.
The patch you applied seems different from what Dotan has posted,
so at least the libibverbs 1.1 branch currently does not work at all:
# ibv_devinfo
libibverbs: Fatal: couldn't read uverbs ABI version.
Here's a fix which makes it work for me:
asprintf returns the number of bytes printed,
so the way to check for failure is < 0.
Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>
---
diff --git a/src/device.c b/src/device.c
index f7ef224..96f906c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -111,7 +111,7 @@ struct ibv_context *ibv_open_device(struct ibv_device *device)
int cmd_fd;
struct ibv_context *context;
- if (asprintf(&devpath, "/dev/infiniband/%s", device->dev_name))
+ if (asprintf(&devpath, "/dev/infiniband/%s", device->dev_name) < 0)
return NULL;
/*
diff --git a/src/sysfs.c b/src/sysfs.c
index 392a675..85aee39 100644
--- a/src/sysfs.c
+++ b/src/sysfs.c
@@ -82,7 +82,7 @@ int ibv_read_sysfs_file(const char *dir, const char *file,
int fd;
int len;
- if (asprintf(&path, "%s/%s", dir, file))
+ if (asprintf(&path, "%s/%s", dir, file) < 0)
return -1;
fd = open(path, O_RDONLY);
--
MST
More information about the general
mailing list