All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] infiniband: hfi1: fix memory leaks
@ 2019-08-18 18:54 Wenwen Wang
  2019-08-19 12:03 ` Leon Romanovsky
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Wenwen Wang @ 2019-08-18 18:54 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Mike Marciniszyn, Dennis Dalessandro, Doug Ledford,
	Jason Gunthorpe, open list:HFI1 DRIVER, open list

In fault_opcodes_write(), 'data' is allocated through kcalloc(). However,
it is not deallocated in the following execution if an error occurs,
leading to memory leaks. To fix this issue, introduce the 'free_data' label
to free 'data' before returning the error.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 drivers/infiniband/hw/hfi1/fault.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/hw/hfi1/fault.c b/drivers/infiniband/hw/hfi1/fault.c
index 93613e5..a999183 100644
--- a/drivers/infiniband/hw/hfi1/fault.c
+++ b/drivers/infiniband/hw/hfi1/fault.c
@@ -141,12 +141,14 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf,
 	if (!data)
 		return -ENOMEM;
 	copy = min(len, datalen - 1);
-	if (copy_from_user(data, buf, copy))
-		return -EFAULT;
+	if (copy_from_user(data, buf, copy)) {
+		ret = -EFAULT;
+		goto free_data;
+	}
 
 	ret = debugfs_file_get(file->f_path.dentry);
 	if (unlikely(ret))
-		return ret;
+		goto free_data;
 	ptr = data;
 	token = ptr;
 	for (ptr = data; *ptr; ptr = end + 1, token = ptr) {
@@ -195,6 +197,7 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf,
 	ret = len;
 
 	debugfs_file_put(file->f_path.dentry);
+free_data:
 	kfree(data);
 	return ret;
 }
-- 
2.7.4


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

* Re: [PATCH] infiniband: hfi1: fix memory leaks
  2019-08-18 18:54 [PATCH] infiniband: hfi1: fix memory leaks Wenwen Wang
@ 2019-08-19 12:03 ` Leon Romanovsky
  2019-08-19 13:11 ` Dennis Dalessandro
  2019-08-20 17:26 ` Doug Ledford
  2 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2019-08-19 12:03 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Mike Marciniszyn, Dennis Dalessandro, Doug Ledford,
	Jason Gunthorpe, open list:HFI1 DRIVER, open list

On Sun, Aug 18, 2019 at 01:54:46PM -0500, Wenwen Wang wrote:
> In fault_opcodes_write(), 'data' is allocated through kcalloc(). However,
> it is not deallocated in the following execution if an error occurs,
> leading to memory leaks. To fix this issue, introduce the 'free_data' label
> to free 'data' before returning the error.
>
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> ---
>  drivers/infiniband/hw/hfi1/fault.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>

Thanks,
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>

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

* Re: [PATCH] infiniband: hfi1: fix memory leaks
  2019-08-18 18:54 [PATCH] infiniband: hfi1: fix memory leaks Wenwen Wang
  2019-08-19 12:03 ` Leon Romanovsky
@ 2019-08-19 13:11 ` Dennis Dalessandro
  2019-08-20 17:26 ` Doug Ledford
  2 siblings, 0 replies; 4+ messages in thread
From: Dennis Dalessandro @ 2019-08-19 13:11 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Mike Marciniszyn, Doug Ledford, Jason Gunthorpe,
	open list:HFI1 DRIVER, open list

On 8/18/2019 2:54 PM, Wenwen Wang wrote:
> In fault_opcodes_write(), 'data' is allocated through kcalloc(). However,
> it is not deallocated in the following execution if an error occurs,
> leading to memory leaks. To fix this issue, introduce the 'free_data' label
> to free 'data' before returning the error.
> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>

Acked-by: Dennis Dalessandro <dennis.dalessandro@intel.com>


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

* Re: [PATCH] infiniband: hfi1: fix memory leaks
  2019-08-18 18:54 [PATCH] infiniband: hfi1: fix memory leaks Wenwen Wang
  2019-08-19 12:03 ` Leon Romanovsky
  2019-08-19 13:11 ` Dennis Dalessandro
@ 2019-08-20 17:26 ` Doug Ledford
  2 siblings, 0 replies; 4+ messages in thread
From: Doug Ledford @ 2019-08-20 17:26 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Mike Marciniszyn, Dennis Dalessandro, Jason Gunthorpe,
	open list:HFI1 DRIVER, open list

[-- Attachment #1: Type: text/plain, Size: 565 bytes --]

On Sun, 2019-08-18 at 13:54 -0500, Wenwen Wang wrote:
> In fault_opcodes_write(), 'data' is allocated through kcalloc().
> However,
> it is not deallocated in the following execution if an error occurs,
> leading to memory leaks. To fix this issue, introduce the 'free_data'
> label
> to free 'data' before returning the error.
> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>

Applied to for-rc, thanks.

-- 
Doug Ledford <dledford@redhat.com>
    GPG KeyID: B826A3330E572FDD
    Fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2019-08-20 17:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-18 18:54 [PATCH] infiniband: hfi1: fix memory leaks Wenwen Wang
2019-08-19 12:03 ` Leon Romanovsky
2019-08-19 13:11 ` Dennis Dalessandro
2019-08-20 17:26 ` Doug Ledford

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.