linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi, block: fix memory leak of sdpk on when gd fails to allocate
@ 2017-02-03 19:38 Colin King
  2017-02-15 18:03 ` Bart Van Assche
  2017-02-23  0:19 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2017-02-03 19:38 UTC (permalink / raw)
  To: James E . J . Bottomley, Martin K . Petersen, linux-scsi
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

On an allocation failure of gd, the current exit path is via out_free_devt
which leaves sdpk still allocated and hence it gets leaked. Fix this by
correcting the order of resource free'ing with a change in the error exit
path labels.

Detected by CoverityScan, CID#1399519 ("Resource Leak")

Fixes: 0dba1314d4f81115dc ("scsi, block: fix duplicate bdi name registration crashes")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/scsi/sd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index cb6e68d..99e1206 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3213,10 +3213,10 @@ static int sd_probe(struct device *dev)
 	sd_devt = NULL;
  out_put:
 	put_disk(gd);
- out_free:
-	kfree(sdkp);
  out_free_devt:
 	kfree(sd_devt);
+ out_free:
+	kfree(sdkp);
  out:
 	scsi_autopm_put_device(sdp);
 	return error;
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi, block: fix memory leak of sdpk on when gd fails to allocate
  2017-02-03 19:38 [PATCH] scsi, block: fix memory leak of sdpk on when gd fails to allocate Colin King
@ 2017-02-15 18:03 ` Bart Van Assche
  2017-02-23  0:19 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Van Assche @ 2017-02-15 18:03 UTC (permalink / raw)
  To: jejb, colin.king, linux-scsi, martin.petersen
  Cc: linux-kernel, axboe, kernel-janitors

On Fri, 2017-02-03 at 19:38 +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> On an allocation failure of gd, the current exit path is via out_free_devt
> which leaves sdpk still allocated and hence it gets leaked. Fix this by
> correcting the order of resource free'ing with a change in the error exit
> path labels.
> 
> Detected by CoverityScan, CID#1399519 ("Resource Leak")
> 
> Fixes: 0dba1314d4f81115dc ("scsi, block: fix duplicate bdi name registration crashes")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/scsi/sd.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index cb6e68d..99e1206 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -3213,10 +3213,10 @@ static int sd_probe(struct device *dev)
>  	sd_devt = NULL;
>   out_put:
>  	put_disk(gd);
> - out_free:
> -	kfree(sdkp);
>   out_free_devt:
>  	kfree(sd_devt);
> + out_free:
> +	kfree(sdkp);
>   out:
>  	scsi_autopm_put_device(sdp);
>  	return error;

Hello Colin,

This patch looks fine to me. But since it is a fix for a patch that exists
in Jens' tree and that is not yet upstream, please resubmit it to Jens.

Bart.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi, block: fix memory leak of sdpk on when gd fails to allocate
  2017-02-03 19:38 [PATCH] scsi, block: fix memory leak of sdpk on when gd fails to allocate Colin King
  2017-02-15 18:03 ` Bart Van Assche
@ 2017-02-23  0:19 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2017-02-23  0:19 UTC (permalink / raw)
  To: Colin King
  Cc: James E . J . Bottomley, Martin K . Petersen, linux-scsi,
	kernel-janitors, linux-kernel

>>>>> "Colin" == Colin King <colin.king@canonical.com> writes:

Colin> On an allocation failure of gd, the current exit path is via
Colin> out_free_devt which leaves sdpk still allocated and hence it gets
Colin> leaked. Fix this by correcting the order of resource free'ing
Colin> with a change in the error exit path labels.

Applied to 4.11/scsi-fixes.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-23  0:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-03 19:38 [PATCH] scsi, block: fix memory leak of sdpk on when gd fails to allocate Colin King
2017-02-15 18:03 ` Bart Van Assche
2017-02-23  0:19 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).