All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] adv7343: use devm_kzalloc() instead of kzalloc()
@ 2013-01-03 13:22 Lad, Prabhakar
  2013-01-03 13:22 ` [PATCH] ths7303: " Lad, Prabhakar
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Lad, Prabhakar @ 2013-01-03 13:22 UTC (permalink / raw)
  To: LMML
  Cc: LKML, Mauro Carvalho Chehab, DLOS, Hans Verkuil, Lad, Prabhakar,
	Manjunath Hadli

I2C drivers can use devm_kzalloc() too in their .probe() methods. Doing so
simplifies their clean up paths.

Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com>
---
 drivers/media/i2c/adv7343.c |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/media/i2c/adv7343.c b/drivers/media/i2c/adv7343.c
index 2b5aa67..ceaf548 100644
--- a/drivers/media/i2c/adv7343.c
+++ b/drivers/media/i2c/adv7343.c
@@ -397,7 +397,8 @@ static int adv7343_probe(struct i2c_client *client,
 	v4l_info(client, "chip found @ 0x%x (%s)\n",
 			client->addr << 1, client->adapter->name);
 
-	state = kzalloc(sizeof(struct adv7343_state), GFP_KERNEL);
+	state = devm_kzalloc(&client->dev, sizeof(struct adv7343_state),
+			     GFP_KERNEL);
 	if (state == NULL)
 		return -ENOMEM;
 
@@ -428,19 +429,14 @@ static int adv7343_probe(struct i2c_client *client,
 				       ADV7343_GAIN_DEF);
 	state->sd.ctrl_handler = &state->hdl;
 	if (state->hdl.error) {
-		int err = state->hdl.error;
-
 		v4l2_ctrl_handler_free(&state->hdl);
-		kfree(state);
-		return err;
+		return state->hdl.error;
 	}
 	v4l2_ctrl_handler_setup(&state->hdl);
 
 	err = adv7343_initialize(&state->sd);
-	if (err) {
+	if (err)
 		v4l2_ctrl_handler_free(&state->hdl);
-		kfree(state);
-	}
 	return err;
 }
 
@@ -451,7 +447,6 @@ static int adv7343_remove(struct i2c_client *client)
 
 	v4l2_device_unregister_subdev(sd);
 	v4l2_ctrl_handler_free(&state->hdl);
-	kfree(state);
 
 	return 0;
 }
-- 
1.7.4.1


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

* [PATCH] ths7303: use devm_kzalloc() instead of kzalloc()
  2013-01-03 13:22 [PATCH] adv7343: use devm_kzalloc() instead of kzalloc() Lad, Prabhakar
@ 2013-01-03 13:22 ` Lad, Prabhakar
  2013-01-03 13:22 ` [PATCH] tvp514x: " Lad, Prabhakar
  2013-01-03 13:22 ` [PATCH] tvp7002: " Lad, Prabhakar
  2 siblings, 0 replies; 7+ messages in thread
From: Lad, Prabhakar @ 2013-01-03 13:22 UTC (permalink / raw)
  To: LMML
  Cc: LKML, Mauro Carvalho Chehab, DLOS, Hans Verkuil, Lad, Prabhakar,
	Manjunath Hadli

I2C drivers can use devm_kzalloc() too in their .probe() methods. Doing so
simplifies their clean up paths.

Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com>
---
 drivers/media/i2c/ths7303.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ths7303.c b/drivers/media/i2c/ths7303.c
index c31cc04..e747524 100644
--- a/drivers/media/i2c/ths7303.c
+++ b/drivers/media/i2c/ths7303.c
@@ -175,7 +175,7 @@ static int ths7303_probe(struct i2c_client *client,
 	v4l_info(client, "chip found @ 0x%x (%s)\n",
 			client->addr << 1, client->adapter->name);
 
-	sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
+	sd = devm_kzalloc(&client->dev, sizeof(struct v4l2_subdev), GFP_KERNEL);
 	if (sd == NULL)
 		return -ENOMEM;
 
@@ -189,7 +189,6 @@ static int ths7303_remove(struct i2c_client *client)
 	struct v4l2_subdev *sd = i2c_get_clientdata(client);
 
 	v4l2_device_unregister_subdev(sd);
-	kfree(sd);
 
 	return 0;
 }
-- 
1.7.4.1


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

* [PATCH] tvp514x: use devm_kzalloc() instead of kzalloc()
  2013-01-03 13:22 [PATCH] adv7343: use devm_kzalloc() instead of kzalloc() Lad, Prabhakar
  2013-01-03 13:22 ` [PATCH] ths7303: " Lad, Prabhakar
@ 2013-01-03 13:22 ` Lad, Prabhakar
  2013-01-03 13:22 ` [PATCH] tvp7002: " Lad, Prabhakar
  2 siblings, 0 replies; 7+ messages in thread
From: Lad, Prabhakar @ 2013-01-03 13:22 UTC (permalink / raw)
  To: LMML
  Cc: LKML, Mauro Carvalho Chehab, DLOS, Hans Verkuil, Lad, Prabhakar,
	Manjunath Hadli

I2C drivers can use devm_kzalloc() too in their .probe() methods. Doing so
simplifies their clean up paths.

Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com>
---
 drivers/media/i2c/tvp514x.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index d5e1021..53608ee 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -951,7 +951,7 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		return -ENODEV;
 	}
 
-	decoder = kzalloc(sizeof(*decoder), GFP_KERNEL);
+	decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
 	if (!decoder)
 		return -ENOMEM;
 
@@ -995,11 +995,8 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
 	sd->ctrl_handler = &decoder->hdl;
 	if (decoder->hdl.error) {
-		int err = decoder->hdl.error;
-
 		v4l2_ctrl_handler_free(&decoder->hdl);
-		kfree(decoder);
-		return err;
+		return decoder->hdl.error;
 	}
 	v4l2_ctrl_handler_setup(&decoder->hdl);
 
@@ -1023,7 +1020,6 @@ static int tvp514x_remove(struct i2c_client *client)
 
 	v4l2_device_unregister_subdev(sd);
 	v4l2_ctrl_handler_free(&decoder->hdl);
-	kfree(decoder);
 	return 0;
 }
 /* TVP5146 Init/Power on Sequence */
-- 
1.7.4.1


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

* [PATCH] tvp7002: use devm_kzalloc() instead of kzalloc()
  2013-01-03 13:22 [PATCH] adv7343: use devm_kzalloc() instead of kzalloc() Lad, Prabhakar
  2013-01-03 13:22 ` [PATCH] ths7303: " Lad, Prabhakar
  2013-01-03 13:22 ` [PATCH] tvp514x: " Lad, Prabhakar
@ 2013-01-03 13:22 ` Lad, Prabhakar
  2013-01-03 13:31   ` Laurent Pinchart
  2 siblings, 1 reply; 7+ messages in thread
From: Lad, Prabhakar @ 2013-01-03 13:22 UTC (permalink / raw)
  To: LMML
  Cc: LKML, Mauro Carvalho Chehab, DLOS, Hans Verkuil, Lad, Prabhakar,
	Manjunath Hadli

I2C drivers can use devm_kzalloc() too in their .probe() methods. Doing so
simplifies their clean up paths.

Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com>
---
 drivers/media/i2c/tvp7002.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
index fb6a5b5..2d4c86e 100644
--- a/drivers/media/i2c/tvp7002.c
+++ b/drivers/media/i2c/tvp7002.c
@@ -1036,7 +1036,7 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
 		return -ENODEV;
 	}
 
-	device = kzalloc(sizeof(struct tvp7002), GFP_KERNEL);
+	device = devm_kzalloc(&c->dev, sizeof(struct tvp7002), GFP_KERNEL);
 
 	if (!device)
 		return -ENOMEM;
@@ -1088,17 +1088,12 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
 			V4L2_CID_GAIN, 0, 255, 1, 0);
 	sd->ctrl_handler = &device->hdl;
 	if (device->hdl.error) {
-		int err = device->hdl.error;
-
 		v4l2_ctrl_handler_free(&device->hdl);
-		kfree(device);
-		return err;
+		return device->hdl.error;
 	}
 	v4l2_ctrl_handler_setup(&device->hdl);
 
 found_error:
-	if (error < 0)
-		kfree(device);
 
 	return error;
 }
@@ -1120,7 +1115,6 @@ static int tvp7002_remove(struct i2c_client *c)
 
 	v4l2_device_unregister_subdev(sd);
 	v4l2_ctrl_handler_free(&device->hdl);
-	kfree(device);
 	return 0;
 }
 
-- 
1.7.4.1


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

* Re: [PATCH] tvp7002: use devm_kzalloc() instead of kzalloc()
  2013-01-03 13:22 ` [PATCH] tvp7002: " Lad, Prabhakar
@ 2013-01-03 13:31   ` Laurent Pinchart
  2013-01-03 13:32     ` Laurent Pinchart
  0 siblings, 1 reply; 7+ messages in thread
From: Laurent Pinchart @ 2013-01-03 13:31 UTC (permalink / raw)
  To: davinci-linux-open-source
  Cc: Lad, Prabhakar, LMML, LKML, Hans Verkuil, Mauro Carvalho Chehab

Hi Prabhakar,

Thanks for the patch.

On Thursday 03 January 2013 18:52:42 Lad, Prabhakar wrote:
> I2C drivers can use devm_kzalloc() too in their .probe() methods. Doing so
> simplifies their clean up paths.
> 
> Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
> Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com>
> ---
>  drivers/media/i2c/tvp7002.c |   10 ++--------
>  1 files changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
> index fb6a5b5..2d4c86e 100644
> --- a/drivers/media/i2c/tvp7002.c
> +++ b/drivers/media/i2c/tvp7002.c
> @@ -1036,7 +1036,7 @@ static int tvp7002_probe(struct i2c_client *c, const
> struct i2c_device_id *id) return -ENODEV;
>  	}
> 
> -	device = kzalloc(sizeof(struct tvp7002), GFP_KERNEL);
> +	device = devm_kzalloc(&c->dev, sizeof(struct tvp7002), GFP_KERNEL);
> 
>  	if (!device)
>  		return -ENOMEM;
> @@ -1088,17 +1088,12 @@ static int tvp7002_probe(struct i2c_client *c, const
> struct i2c_device_id *id) V4L2_CID_GAIN, 0, 255, 1, 0);
>  	sd->ctrl_handler = &device->hdl;
>  	if (device->hdl.error) {
> -		int err = device->hdl.error;
> -
>  		v4l2_ctrl_handler_free(&device->hdl);
> -		kfree(device);
> -		return err;
> +		return device->hdl.error;

At this point device->hdl as been freed (or rather uninitialized, as the 
structure is not dynamically allocated by the control framework), so device-
>hdl.error is undefined. That's why you need the local err variable.

>  	}
>  	v4l2_ctrl_handler_setup(&device->hdl);
> 
>  found_error:
> -	if (error < 0)
> -		kfree(device);

You can remove the found_error label and return errors directly instead of 
using goto's.

>  	return error;

And this can then be turned into return 0.

>  }
> @@ -1120,7 +1115,6 @@ static int tvp7002_remove(struct i2c_client *c)
> 
>  	v4l2_device_unregister_subdev(sd);
>  	v4l2_ctrl_handler_free(&device->hdl);
> -	kfree(device);
>  	return 0;
>  }
-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH] tvp7002: use devm_kzalloc() instead of kzalloc()
  2013-01-03 13:31   ` Laurent Pinchart
@ 2013-01-03 13:32     ` Laurent Pinchart
  2013-01-03 13:33       ` Prabhakar Lad
  0 siblings, 1 reply; 7+ messages in thread
From: Laurent Pinchart @ 2013-01-03 13:32 UTC (permalink / raw)
  To: davinci-linux-open-source; +Cc: Mauro Carvalho Chehab, Hans Verkuil, LKML, LMML

On Thursday 03 January 2013 14:31:20 Laurent Pinchart wrote:
> On Thursday 03 January 2013 18:52:42 Lad, Prabhakar wrote:
> > I2C drivers can use devm_kzalloc() too in their .probe() methods. Doing so
> > simplifies their clean up paths.
> > 
> > Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
> > Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com>
> > ---
> > 
> >  drivers/media/i2c/tvp7002.c |   10 ++--------
> >  1 files changed, 2 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
> > index fb6a5b5..2d4c86e 100644
> > --- a/drivers/media/i2c/tvp7002.c
> > +++ b/drivers/media/i2c/tvp7002.c
> > @@ -1036,7 +1036,7 @@ static int tvp7002_probe(struct i2c_client *c, const
> > struct i2c_device_id *id) return -ENODEV;
> > 
> >  	}
> > 
> > -	device = kzalloc(sizeof(struct tvp7002), GFP_KERNEL);
> > +	device = devm_kzalloc(&c->dev, sizeof(struct tvp7002), GFP_KERNEL);
> > 
> >  	if (!device)
> >  	
> >  		return -ENOMEM;
> > 
> > @@ -1088,17 +1088,12 @@ static int tvp7002_probe(struct i2c_client *c,
> > const struct i2c_device_id *id) V4L2_CID_GAIN, 0, 255, 1, 0);
> > 
> >  	sd->ctrl_handler = &device->hdl;
> >  	if (device->hdl.error) {
> > 
> > -		int err = device->hdl.error;
> > -
> > 
> >  		v4l2_ctrl_handler_free(&device->hdl);
> > 
> > -		kfree(device);
> > -		return err;
> > +		return device->hdl.error;
> 
> At this point device->hdl as been freed (or rather uninitialized, as the
> structure is not dynamically allocated by the control framework), so device-
> >hdl.error is undefined. That's why you need the local err variable.

And this comment holds true for the other patches in this series.

> >
> >  	}
> >  	v4l2_ctrl_handler_setup(&device->hdl);
> >  
> >  found_error:
> > -	if (error < 0)
> > -		kfree(device);
> 
> You can remove the found_error label and return errors directly instead of
> using goto's.
> 
> >  	return error;
> 
> And this can then be turned into return 0.
> 
> >  }
> > 
> > @@ -1120,7 +1115,6 @@ static int tvp7002_remove(struct i2c_client *c)
> > 
> >  	v4l2_device_unregister_subdev(sd);
> >  	v4l2_ctrl_handler_free(&device->hdl);
> > 
> > -	kfree(device);
> > 
> >  	return 0;
> >  
> >  }

-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH] tvp7002: use devm_kzalloc() instead of kzalloc()
  2013-01-03 13:32     ` Laurent Pinchart
@ 2013-01-03 13:33       ` Prabhakar Lad
  0 siblings, 0 replies; 7+ messages in thread
From: Prabhakar Lad @ 2013-01-03 13:33 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: davinci-linux-open-source, Mauro Carvalho Chehab, Hans Verkuil,
	LKML, LMML

Hi Laurent,

Thanks for the quick review!

On Thu, Jan 3, 2013 at 7:02 PM, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
> On Thursday 03 January 2013 14:31:20 Laurent Pinchart wrote:
>> On Thursday 03 January 2013 18:52:42 Lad, Prabhakar wrote:
>> > I2C drivers can use devm_kzalloc() too in their .probe() methods. Doing so
>> > simplifies their clean up paths.
>> >
>> > Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
>> > Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com>
>> > ---
>> >
>> >  drivers/media/i2c/tvp7002.c |   10 ++--------
>> >  1 files changed, 2 insertions(+), 8 deletions(-)
>> >
>> > diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
>> > index fb6a5b5..2d4c86e 100644
>> > --- a/drivers/media/i2c/tvp7002.c
>> > +++ b/drivers/media/i2c/tvp7002.c
>> > @@ -1036,7 +1036,7 @@ static int tvp7002_probe(struct i2c_client *c, const
>> > struct i2c_device_id *id) return -ENODEV;
>> >
>> >     }
>> >
>> > -   device = kzalloc(sizeof(struct tvp7002), GFP_KERNEL);
>> > +   device = devm_kzalloc(&c->dev, sizeof(struct tvp7002), GFP_KERNEL);
>> >
>> >     if (!device)
>> >
>> >             return -ENOMEM;
>> >
>> > @@ -1088,17 +1088,12 @@ static int tvp7002_probe(struct i2c_client *c,
>> > const struct i2c_device_id *id) V4L2_CID_GAIN, 0, 255, 1, 0);
>> >
>> >     sd->ctrl_handler = &device->hdl;
>> >     if (device->hdl.error) {
>> >
>> > -           int err = device->hdl.error;
>> > -
>> >
>> >             v4l2_ctrl_handler_free(&device->hdl);
>> >
>> > -           kfree(device);
>> > -           return err;
>> > +           return device->hdl.error;
>>
>> At this point device->hdl as been freed (or rather uninitialized, as the
>> structure is not dynamically allocated by the control framework), so device-
>> >hdl.error is undefined. That's why you need the local err variable.
>
> And this comment holds true for the other patches in this series.
>
Ok I'll fix it respin a v2.

>> >
>> >     }
>> >     v4l2_ctrl_handler_setup(&device->hdl);
>> >
>> >  found_error:
>> > -   if (error < 0)
>> > -           kfree(device);
>>
>> You can remove the found_error label and return errors directly instead of
>> using goto's.
>>
Ok

>> >     return error;
>>
>> And this can then be turned into return 0.
Ok.

Regards,
--Prabhakar

>>
>> >  }
>> >
>> > @@ -1120,7 +1115,6 @@ static int tvp7002_remove(struct i2c_client *c)
>> >
>> >     v4l2_device_unregister_subdev(sd);
>> >     v4l2_ctrl_handler_free(&device->hdl);
>> >
>> > -   kfree(device);
>> >
>> >     return 0;
>> >
>> >  }
>
> --
> Regards,
>
> Laurent Pinchart
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2013-01-03 13:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-03 13:22 [PATCH] adv7343: use devm_kzalloc() instead of kzalloc() Lad, Prabhakar
2013-01-03 13:22 ` [PATCH] ths7303: " Lad, Prabhakar
2013-01-03 13:22 ` [PATCH] tvp514x: " Lad, Prabhakar
2013-01-03 13:22 ` [PATCH] tvp7002: " Lad, Prabhakar
2013-01-03 13:31   ` Laurent Pinchart
2013-01-03 13:32     ` Laurent Pinchart
2013-01-03 13:33       ` Prabhakar Lad

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.