scsi: sg: fix minor memory leak in error path
authorTony Battersby <tonyb@cybernetics.com>
Thu, 12 Jul 2018 20:30:45 +0000 (16:30 -0400)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 13 Jul 2018 03:08:10 +0000 (23:08 -0400)
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>
Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/sg.c

index cd2fdac000c9e23fbf1df8cca453f30379b22d66..2962a38c5068e724851e8309da6eeee6f43561d6 100644 (file)
@@ -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);