From: FUJITA Tomonori Date: Thu, 22 Jul 2010 00:36:51 +0000 (+0900) Subject: [SCSI] sg: fix bio leak with a detached device X-Git-Tag: firefly_0821_release~9833^2~1305^2~45 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=caf19d38607108304cd8cc67ed21378017f69e8a;p=firefly-linux-kernel-4.4.55.git [SCSI] sg: fix bio leak with a detached device After blk_rq_map_user is successful, if we find that a device is unavailable (was detached), we must call blk_end_request_all to free bio(s) before blk_rq_unmap_user and blk_put_request. Reported-by: "Dailey, Nate" Signed-off-by: FUJITA Tomonori Tested-by: "Dailey, Nate" Signed-off-by: James Bottomley --- diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index ef752b248c4d..d4549092400c 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -729,6 +729,8 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp, return k; /* probably out of space --> ENOMEM */ } if (sdp->detached) { + if (srp->bio) + blk_end_request_all(srp->rq, -EIO); sg_finish_rem_req(srp); return -ENODEV; }