Skip to contentSkip to conversation

ib_srpt: fixup error handling in srpt_alloc_ioctx_ring()

PATCH In review Dan Carpenter 2 participants 2 messages Nov 4, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 ib_srpt: fixup error handling in srpt_alloc_ioctx_ring()

We returned a freed value instead of NULL on certain error paths. Complicated error handling generally more error prone, so I've tried to simplify it a little by removing some gotos.

drivers/infiniband/ulp/srpt/ib_srpt.c +3 -4
index 1c29679..937b4bc 100644
@@ -680,21 +680,20 @@ static struct srpt_ioctx **srpt_alloc_ioctx_ring(struct srpt_device *sdev,
 
 	ring = kmalloc(ring_size * sizeof(ring[0]), GFP_KERNEL);
 	if (!ring)
-		goto out;
+		return NULL;
 	for (i = 0; i < ring_size; ++i) {
 		ring[i] = srpt_alloc_ioctx(sdev, ioctx_size, dma_size, dir);
 		if (!ring[i])
 			goto err;
 		ring[i]->index = i;
 	}
-	goto out;
+	return ring;
 
 err:
 	while (--i >= 0)
 		srpt_free_ioctx(sdev, ring[i], dma_size, dir);
 	kfree(ring);
-out:
-	return ring;
+	return NULL;
 }
 
 /**
#1 lore raw

Re: [patch 1/3] ib_srpt: fixup error handling in

Quoted 6 lines · Dan Carpenter

We returned a freed value instead of NULL on certain error paths. Complicated error handling generally more error prone, so I've tried to simplify it a little by removing some gotos.

Looks like a reasonable cleanup. Thanks Dan!

--nab

Quoted 29 lines
drivers/infiniband/ulp/srpt/ib_srpt.c +3 -4
index 1c29679..937b4bc 100644
@@ -680,21 +680,20 @@ static struct srpt_ioctx **srpt_alloc_ioctx_ring(struct srpt_device *sdev,
 
 	ring = kmalloc(ring_size * sizeof(ring[0]), GFP_KERNEL);
 	if (!ring)
-		goto out;
+		return NULL;
 	for (i = 0; i < ring_size; ++i) {
 		ring[i] = srpt_alloc_ioctx(sdev, ioctx_size, dma_size, dir);
 		if (!ring[i])
 			goto err;
 		ring[i]->index = i;
 	}
-	goto out;
+	return ring;
 
 err:
 	while (--i >= 0)
 		srpt_free_ioctx(sdev, ring[i], dma_size, dir);
 	kfree(ring);
-out:
-	return ring;
+	return NULL;
 }
 
 /**