[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1586777552-17524-1-git-send-email-huawei.libin@huawei.com>
Date: Mon, 13 Apr 2020 19:32:32 +0800
From: Li Bin <huawei.libin@...wei.com>
To: <dgilbert@...erlog.com>, <jejb@...ux.ibm.com>,
<martin.petersen@...cle.com>
CC: <linux-scsi@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<huawei.libin@...wei.com>, <xiexiuqi@...wei.com>
Subject: [PATCH] scsi: sg: fix memory leak in sg_build_indirect
Fix a memory leak when there have failed, that we should free the pages
under the condition rem_sz > 0.
Signed-off-by: Li Bin <huawei.libin@...wei.com>
---
drivers/scsi/sg.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 4e6af592..8441ac5 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1959,8 +1959,12 @@ static long sg_compat_ioctl(struct file *filp, unsigned int cmd_in, unsigned lon
k, rem_sz));
schp->bufflen = blk_size;
- if (rem_sz > 0) /* must have failed */
+ if (rem_sz > 0) { /* must have failed */
+ for (i = 0; i < k; i++)
+ __free_pages(schp->pages[i], order);
+
return -ENOMEM;
+ }
return 0;
out:
for (i = 0; i < k; i++)
--
1.7.12.4
Powered by blists - more mailing lists