diff mbox

sg: fix minor memory leak in error path

Message ID 4a89b424-b88e-98b6-5261-df23dff342f0@cybernetics.com (mailing list archive)
State Accepted
Headers show

Commit Message

Tony Battersby July 12, 2018, 8:30 p.m. UTC
Fix a minor memory leak when there is an error opening a /dev/sg device.

Fixes: cc833acbee9d ("sg: O_EXCL and other lock handling")
Cc: <stable@vger.kernel.org>
Reviewed-by: Ewan D. Milne <emilne@redhat.com>
Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
---

Resending to include the requested fixes: / cc: stable tags.

Comments

Bart Van Assche July 12, 2018, 8:35 p.m. UTC | #1
On 07/12/18 13:30, Tony Battersby wrote:
> Fix a minor memory leak when there is an error opening a /dev/sg device.

Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com>
diff mbox

Patch

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index cd2fdac..2962a38 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -2185,6 +2185,7 @@  sg_add_sfp(Sg_device * sdp)
 	write_lock_irqsave(&sdp->sfd_lock, iflags);
 	if (atomic_read(&sdp->detaching)) {
 		write_unlock_irqrestore(&sdp->sfd_lock, iflags);
+		kfree(sfp);
 		return ERR_PTR(-ENODEV);
 	}
 	list_add_tail(&sfp->sfd_siblings, &sdp->sfds);