Skip to contentSkip to conversation

libsrp: fix memory leak in srp_ring_free()

PATCH In review Bart Van Assche 2 participants 5 messages Aug 30, 2009 – Sep 5, 2009 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsrp: fix memory leak in srp_ring_free()

This patch fixes a memory leak in the libsrp function srp_ring_free(). It is not documented whether or not this function should free the ring pointer itself. But the source code of the callers of this function (srp_target_alloc() and srp_target_free()) makes it clear that srp_ring_free() should deallocate the ring pointer itself. Furthermore, the patch below makes srp_ring_free() deallocate all memory allocated by srp_ring_alloc().

This patch affects the ibmvstgt driver, which is the only in-tree driver that calls the srp_ring_free() function (indirectly).

Cc James Bottomley <[email protected]>
Cc FUJITA Tomonori <[email protected]>

diff -uprN orig/linux-2.6.30/drivers/scsi/libsrp.c linux-2.6.30/drivers/scsi/libsrp.c

drivers/scsi/libsrp.c renamed from linux-2.6.30/drivers/scsi/libsrp.c +1 -0
@@ -124,6 +124,7 @@ static void srp_ring_free(struct device
 		dma_free_coherent(dev, size, ring[i]->buf, ring[i]->dma);
 		kfree(ring[i]);
 	}
+	kfree(ring);
 }
 
 int srp_target_alloc(struct srp_target *target, struct device *dev,
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Sun, 30 Aug 2009 12:36:48 +0200 Bart Van Assche <[email protected]>…

This patch fixes a memory leak in the libsrp function srp_ring_free(). It is not documented whether or not this function should free the ring pointer itself. But the source code of the callers of this function (srp_target_alloc() and srp_target_free()) makes it clear that srp_ring_free() should deallocate the ring pointer itself. Furthermore, the patch below makes srp_ring_free() deallocate all memory allocated by srp_ring_alloc().

Quoted 6 lines

This patch affects the ibmvstgt driver, which is the only in-tree driver that calls the srp_ring_free() function (indirectly).

Cc James Bottomley <[email protected]>
Cc FUJITA Tomonori <[email protected]>

Better to add:

Thanks,

#2 lore raw
Quoted 19 lines · FUJITA Tomonori
Quoted 8 lines · On Sun, 30 Aug 2009 12:36:48 +0200 Bart Van Assche <[email protected]>…

This patch fixes a memory leak in the libsrp function srp_ring_free(). It is not documented whether or not this function should free the ring pointer itself. But the source code of the callers of this function (srp_target_alloc() and srp_target_free()) makes it clear that srp_ring_free() should deallocate the ring pointer itself. Furthermore, the patch below makes srp_ring_free() deallocate all memory allocated by srp_ring_alloc().

Quoted 6 lines

This patch affects the ibmvstgt driver, which is the only in-tree driver that calls the srp_ring_free() function (indirectly).

Cc James Bottomley <[email protected]>
Cc FUJITA Tomonori <[email protected]>
Quoted 5 lines

Better to add:

Thanks for the review. I will submit this patch to [email protected] as soon as it has been committed. Patches are only accepted for backporting after they have been committed in the mainline kernel.

Bart.

#3 lore raw
Quoted 23 lines · On Sat, 5 Sep 2009 11:34:40 +0200 Bart Van Assche <[email protected]>…
Quoted 21 lines · FUJITA Tomonori
Quoted 8 lines · On Sun, 30 Aug 2009 12:36:48 +0200 Bart Van Assche <[email protected]>…

This patch fixes a memory leak in the libsrp function srp_ring_free(). It is not documented whether or not this function should free the ring pointer itself. But the source code of the callers of this function (srp_target_alloc() and srp_target_free()) makes it clear that srp_ring_free() should deallocate the ring pointer itself. Furthermore, the patch below makes srp_ring_free() deallocate all memory allocated by srp_ring_alloc().

Quoted 6 lines

This patch affects the ibmvstgt driver, which is the only in-tree driver that calls the srp_ring_free() function (indirectly).

Cc James Bottomley <[email protected]>
Cc FUJITA Tomonori <[email protected]>
Quoted 7 lines
Quoted 3 lines

Better to add:

Thanks for the review. I will submit this patch to [email protected] as soon as it has been committed. Patches are only accepted for backporting after they have been committed in the mainline kernel.

You don't need to submit a patch to [email protected] if you put 'Cc:
[email protected]' tag in a commit log; the patch will be sent to [email protected] automatically after the the patch is merged into mainline.