From: Douglas Gilbert Date: Tue, 28 Mar 2006 19:48:22 +0000 (-0500) Subject: [SCSI] sg: fix leak when dio setup fails X-Git-Tag: v2.6.17-rc2~30^2~16 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c06bb7f514567efa39062a781679120e51caa818;p=linux-2.6 [SCSI] sg: fix leak when dio setup fails when the sg driver is unable to setup direct IO, free that scatter gather list prior to falling back to indirect IO 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. Signed-off-by: Douglas Gilbert Signed-off-by: James Bottomley --- diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index bfa86b378f..b098942445 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1799,8 +1799,10 @@ sg_build_direct(Sg_request * srp, Sg_fd * sfp, int dxfer_len) 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;