diff mbox

Fixing segfault in libibverbs

Message ID BANLkTik4e-kygpRTnxfpTdRMSTbyYNO1_Q@mail.gmail.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Roland Dreier May 27, 2011, 4:22 p.m. UTC
>> This patch fixes SEGFAULT in libibverbs in case when there are no user
>> space drivers found. I've cloned the libibverbs from
>> git://git.openfabrics.org/ofed_1_1_5/libibverbs.git (I hope this is
>> correct)

Thanks for the patches.  I think I would prefer to fix this more like the
following (sorry for the attachment, using the gmail web interface ATM).
This actually simplifies things I think, and sticks to the original idea
that we should only be calling ibverbs_init once.

I only compile tested this, can one of you guys confirm this also fixes
the problem?

Thanks!
  Roland

Comments

Yann Droneaud May 27, 2011, 5:06 p.m. UTC | #1
Hi, 

Le vendredi 27 mai 2011 à 09:22 -0700, Roland Dreier a écrit :
> >> This patch fixes SEGFAULT in libibverbs in case when there are no user
> >> space drivers found. I've cloned the libibverbs from
> >> git://git.openfabrics.org/ofed_1_1_5/libibverbs.git (I hope this is
> >> correct)
> 
> Thanks for the patches.  I think I would prefer to fix this more like the
> following (sorry for the attachment, using the gmail web interface ATM).
> This actually simplifies things I think, and sticks to the original idea
> that we should only be calling ibverbs_init once.
> 
> I only compile tested this, can one of you guys confirm this also fixes
> the problem?
> 

It fixes the problem of segfault on empty driver list.

But __ibv_get_device_list() returns a non NULL pointer when there's no
device.

> -       if (!num_devices)
> -               num_devices = ibverbs_init(&device_list);
> +       pthread_once(&device_list_once, count_devices);
 
It miss

        if (!num_devices)
               return NULL;

>        if (num_devices < 0) {
>                errno = -num_devices;
>-               goto out;
>+               return NULL;
>        }

Tested-by: Yann Droneaud <ydroneaud@opteya.com>

BTW, my others patches are still interesting.

Regards.
Yann Droneaud May 27, 2011, 5:31 p.m. UTC | #2
Hi,

Le vendredi 27 mai 2011 à 19:06 +0200, Yann Droneaud a écrit :

> But __ibv_get_device_list() returns a non NULL pointer when there's no
> device.
> 

Forget about my comment, I haven't checked the manpage for the function:

ibv_get_device_list(3) :

RETURN VALUE

ibv_get_device_list()  returns  the array of available RDMA devices, or
sets errno and returns NULL if the request fails.  If  no  devices  are
found then num_devices is set to 0, and non-NULL is returned.

I'm sending a patch against rdmacm to address the problem.

Regards.
Roland Dreier May 27, 2011, 6:21 p.m. UTC | #3
On Fri, May 27, 2011 at 10:06 AM, Yann Droneaud <ydroneaud@opteya.com> wrote:
> Tested-by: Yann Droneaud <ydroneaud@opteya.com>

Thanks, committed and pushed out.

> BTW, my others patches are still interesting.

Yes, I need to look at them.  Sorry for being so slow.

 - R.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

 src/device.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/device.c b/src/device.c
index 185f4a6..5798895 100644
--- a/src/device.c
+++ b/src/device.c
@@ -49,32 +49,34 @@ 
 
 #include "ibverbs.h"
 
-static pthread_mutex_t device_list_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_once_t device_list_once = PTHREAD_ONCE_INIT;
 static int num_devices;
 static struct ibv_device **device_list;
 
+static void count_devices(void)
+{
+	num_devices = ibverbs_init(&device_list);
+}
+
 struct ibv_device **__ibv_get_device_list(int *num)
 {
-	struct ibv_device **l = 0;
+	struct ibv_device **l;
 	int i;
 
 	if (num)
 		*num = 0;
 
-	pthread_mutex_lock(&device_list_lock);
-
-	if (!num_devices)
-		num_devices = ibverbs_init(&device_list);
+	pthread_once(&device_list_once, count_devices);
 
 	if (num_devices < 0) {
 		errno = -num_devices;
-		goto out;
+		return NULL;
 	}
 
 	l = calloc(num_devices + 1, sizeof (struct ibv_device *));
 	if (!l) {
 		errno = ENOMEM;
-		goto out;
+		return NULL;
 	}
 
 	for (i = 0; i < num_devices; ++i)
@@ -82,8 +84,6 @@  struct ibv_device **__ibv_get_device_list(int *num)
 	if (num)
 		*num = num_devices;
 
-out:
-	pthread_mutex_unlock(&device_list_lock);
 	return l;
 }
 default_symver(__ibv_get_device_list, ibv_get_device_list);