public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [media] marvell-ccic: fix memory leak on failure path in cafe_smbus_setup()
@ 2015-04-04  0:16 Alexey Khoroshilov
  2015-04-04 13:36 ` Jonathan Corbet
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Khoroshilov @ 2015-04-04  0:16 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab
  Cc: Alexey Khoroshilov, ldv-project, linux-media, linux-kernel

If i2c_add_adapter() fails, adap is not deallocated.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/media/platform/marvell-ccic/cafe-driver.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/marvell-ccic/cafe-driver.c b/drivers/media/platform/marvell-ccic/cafe-driver.c
index 562845361246..9d45505370cd 100644
--- a/drivers/media/platform/marvell-ccic/cafe-driver.c
+++ b/drivers/media/platform/marvell-ccic/cafe-driver.c
@@ -339,17 +339,21 @@ static int cafe_smbus_setup(struct cafe_camera *cam)
 	adap = kzalloc(sizeof(*adap), GFP_KERNEL);
 	if (adap == NULL)
 		return -ENOMEM;
-	cam->mcam.i2c_adapter = adap;
-	cafe_smbus_enable_irq(cam);
 	adap->owner = THIS_MODULE;
 	adap->algo = &cafe_smbus_algo;
 	strcpy(adap->name, "cafe_ccic");
 	adap->dev.parent = &cam->pdev->dev;
 	i2c_set_adapdata(adap, cam);
 	ret = i2c_add_adapter(adap);
-	if (ret)
+	if (ret) {
 		printk(KERN_ERR "Unable to register cafe i2c adapter\n");
-	return ret;
+		kfree(adap);
+		return ret;
+	}
+
+	cam->mcam.i2c_adapter = adap;
+	cafe_smbus_enable_irq(cam);
+	return 0;
 }
 
 static void cafe_smbus_shutdown(struct cafe_camera *cam)
-- 
1.9.1


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

* Re: [PATCH] [media] marvell-ccic: fix memory leak on failure path in cafe_smbus_setup()
  2015-04-04  0:16 [PATCH] [media] marvell-ccic: fix memory leak on failure path in cafe_smbus_setup() Alexey Khoroshilov
@ 2015-04-04 13:36 ` Jonathan Corbet
  2015-04-04 16:59   ` Alexey Khoroshilov
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Corbet @ 2015-04-04 13:36 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Mauro Carvalho Chehab, ldv-project, linux-media, linux-kernel

On Sat,  4 Apr 2015 03:16:01 +0300
Alexey Khoroshilov <khoroshilov@ispras.ru> wrote:

> If i2c_add_adapter() fails, adap is not deallocated.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>

Actually, the worse thing is that it leaves the IRQ enabled...it's good
you moved that lines down.  Even better, of course, that the failure path
has probably never been run during the life of this driver...:)

Should there be some sort of proper reported-by line for the driver
verification project?

Acked-by: Jonathan Corbet <corbet@lwn.net>

jon

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

* Re: [PATCH] [media] marvell-ccic: fix memory leak on failure path in cafe_smbus_setup()
  2015-04-04 13:36 ` Jonathan Corbet
@ 2015-04-04 16:59   ` Alexey Khoroshilov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexey Khoroshilov @ 2015-04-04 16:59 UTC (permalink / raw)
  To: Jonathan Corbet
  Cc: Mauro Carvalho Chehab, ldv-project, linux-media, linux-kernel

On 04.04.2015 16:36, Jonathan Corbet wrote:
> On Sat,  4 Apr 2015 03:16:01 +0300
> Alexey Khoroshilov <khoroshilov@ispras.ru> wrote:
> 
>> If i2c_add_adapter() fails, adap is not deallocated.
>>
>> Found by Linux Driver Verification project (linuxtesting.org).
>>
>> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> 
> Actually, the worse thing is that it leaves the IRQ enabled...it's good
> you moved that lines down.  Even better, of course, that the failure path
> has probably never been run during the life of this driver...:)

And hopefully it will not, but we will be ready:)

> 
> Should there be some sort of proper reported-by line for the driver
> verification project?

Till now, we used "Found by" line, but we are open to any better way.

> 
> Acked-by: Jonathan Corbet <corbet@lwn.net>

--
Alexey

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

end of thread, other threads:[~2015-04-04 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-04  0:16 [PATCH] [media] marvell-ccic: fix memory leak on failure path in cafe_smbus_setup() Alexey Khoroshilov
2015-04-04 13:36 ` Jonathan Corbet
2015-04-04 16:59   ` Alexey Khoroshilov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox