linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geordan Neukum <gneukum1@gmail.com>
To: gneukum1@gmail.com,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/5] staging: kpc2000: kpc_i2c: prevent memory leak in probe() error case
Date: Sat, 18 May 2019 02:29:58 +0000	[thread overview]
Message-ID: <ff94cd3b0d13c2785bc4d2cc7ac6d63f11691fd1.1558146549.git.gneukum1@gmail.com> (raw)
In-Reply-To: <cover.1558146549.git.gneukum1@gmail.com>

The probe() function performs a kzalloc to dynamically allocate memory
at runtime. If the allocation succeeds, yet invoking the function
i2c_add_adapter fails, the dynamically allocated memory is never freed.
Change the allocation to use the managed allocation API instead and
remove the manual freeing of the memory in the remove() function.

Signed-off-by: Geordan Neukum <gneukum1@gmail.com>
---
 drivers/staging/kpc2000/kpc_i2c/i2c_driver.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc_i2c/i2c_driver.c b/drivers/staging/kpc2000/kpc_i2c/i2c_driver.c
index 6cb63d20b00f..9b9de81c8548 100644
--- a/drivers/staging/kpc2000/kpc_i2c/i2c_driver.c
+++ b/drivers/staging/kpc2000/kpc_i2c/i2c_driver.c
@@ -628,7 +628,7 @@ int pi2c_probe(struct platform_device *pldev)
 
 	dev_dbg(&pldev->dev, "pi2c_probe(pldev = %p '%s')\n", pldev, pldev->name);
 
-	priv = kzalloc(sizeof(struct i2c_device), GFP_KERNEL);
+	priv = devm_kzalloc(&pldev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv) {
 		return -ENOMEM;
 	}
@@ -685,10 +685,6 @@ int pi2c_remove(struct platform_device *pldev)
 	//pci_set_drvdata(dev, NULL);
 
 	//cdev_del(&lddev->cdev);
-	if(lddev != 0) {
-		kfree(lddev);
-		pldev->dev.platform_data = 0;
-	}
 
 	return 0;
 }
-- 
2.21.0


  parent reply	other threads:[~2019-05-18  2:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-18  2:29 [PATCH 0/5] Updates to staging driver: kpc_i2c Geordan Neukum
2019-05-18  2:29 ` [PATCH 1/5] staging: kpc2000: kpc_i2c: reindent i2c_driver.c Geordan Neukum
2019-05-18  2:29 ` [PATCH 2/5] staging: kpc2000: kpc_i2c: reformat copyright for better readability Geordan Neukum
2019-05-18  2:29 ` Geordan Neukum [this message]
2019-05-18  2:29 ` [PATCH 4/5] staging: kpc2000: kpc_i2c: use %s with __func__ identifier in log messages Geordan Neukum
2019-05-18  2:58   ` Joe Perches
2019-05-18  3:28     ` Geordan Neukum
2019-05-18  2:30 ` [PATCH 5/5] staging: kpc2000: kpc_i2c: fixup block comment style in i2c_driver.c Geordan Neukum
2019-05-20  8:30 ` [PATCH 0/5] Updates to staging driver: kpc_i2c Greg Kroah-Hartman
2019-05-21  8:15   ` Geordan Neukum
2019-05-21  8:34     ` Geordan Neukum
2019-05-21  8:37     ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ff94cd3b0d13c2785bc4d2cc7ac6d63f11691fd1.1558146549.git.gneukum1@gmail.com \
    --to=gneukum1@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).