Skip to contentSkip to conversation

sg: fix leak when dio setup fails

PATCH In review Douglas Gilbert 2 participants 2 messages Mar 28, 2006 – Mar 30, 2006

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

PATCH 1/1 sg: fix leak when dio setup fails

Further to this thread started by Bryan Holty:
http://marc.theaimsgroup.com/?l=linux-scsi&m=114306885116728&w=2

Here is the reworked patch again. This time it has been tested with a program provided by Bryan. The patch is against lk 2.6.16 .

Changelog:
- when the sg driver is unable to setup direct IO, free that scatter gather list prior to falling back to indirect IO

Doug Gilbert

drivers/scsi/sg.c2616dio_lk renamed from drivers/scsi/sg.c +3 -1
@@ -1834,8 +1834,10 @@
 	res = st_map_user_pages(schp->buffer, mx_sc_elems,
 				(unsigned long)hp->dxferp, dxfer_len, 
 				(SG_DXFER_TO_DEV == hp->dxfer_direction) ? 1 : 0);
-	if (res <= 0)
+	if (res <= 0) {
+		sg_remove_scat(schp);
 		return 1;
+	}
 	schp->k_use_sg = res;
 	schp->dio_in_use = 1;
 	hp->info |= SG_INFO_DIRECT_IO;
#1 lore raw
Quoted 7 lines · Douglas Gilbert

Further to this thread started by Bryan Holty:
http://marc.theaimsgroup.com/?l=linux-scsi&m=114306885116728&w=2

Here is the reworked patch again. This time it has been tested with a program provided by Bryan. The patch is against lk 2.6.16 .

Quoted 8 lines

Changelog:
- when the sg driver is unable to setup direct IO, free that scatter gather list prior to falling back to indirect IO

Doug Gilbert

Thanks Doug, this fixes the fixes the sg memory leak and the eventual kernel out of memory killer.

drivers/scsi/sg.c2616dio_lk renamed from drivers/scsi/sg.c +3 -1
@@ -1834,8 +1834,10 @@
 	res = st_map_user_pages(schp->buffer, mx_sc_elems,
 				(unsigned long)hp->dxferp, dxfer_len, 
 				(SG_DXFER_TO_DEV == hp->dxfer_direction) ? 1 : 0);
-	if (res <= 0)
+	if (res <= 0) {
+		sg_remove_scat(schp);
 		return 1;
+	}
 	schp->k_use_sg = res;
 	schp->dio_in_use = 1;
 	hp->info |= SG_INFO_DIRECT_IO;

--
Bryan Holty