diff mbox

sg: fix minor memory leak in error path

Message ID 3c90c434-0ce4-c8df-1359-1453be766043@cybernetics.com (mailing list archive)
State Superseded
Headers show

Commit Message

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

Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
---

Comments

Ewan Milne July 12, 2018, 7:29 p.m. UTC | #1
On Thu, 2018-07-12 at 14:46 -0400, Tony Battersby wrote:
> Fix a minor memory leak when there is an error opening a /dev/sg device.
> 
> Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
> ---
> 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);
> 

Reviewed-by: Ewan D. Milne <emilne@redhat.com>
Bart Van Assche July 12, 2018, 7:49 p.m. UTC | #2
On Thu, 2018-07-12 at 14:46 -0400, Tony Battersby wrote:
> Fix a minor memory leak when there is an error opening a /dev/sg device.


Please Cc: stable for patches like this and please also add a Fixes: tag.

Thanks,

Bart.
Douglas Gilbert July 12, 2018, 8:49 p.m. UTC | #3
On 2018-07-12 02:46 PM, Tony Battersby wrote:
> Fix a minor memory leak when there is an error opening a /dev/sg device.
> 
> Signed-off-by: Tony Battersby <tonyb@cybernetics.com>

Acked-by: Douglas Gilbert <dgilbert@interlog.com>

Thanks.

> ---
> 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);
> 
>
Martin K. Petersen July 13, 2018, 3:08 a.m. UTC | #4
Tony,

> Fix a minor memory leak when there is an error opening a /dev/sg
> device.

Applied to 4.18/scsi-fixes, thanks!
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);