linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] media: i2c: adv748x: Use devm to allocate the device struct
@ 2019-01-11 16:17 Kieran Bingham
  2019-01-14 13:06 ` Niklas Söderlund
  0 siblings, 1 reply; 3+ messages in thread
From: Kieran Bingham @ 2019-01-11 16:17 UTC (permalink / raw)
  To: linux-media, linux-renesas-soc, Kieran Bingham; +Cc: Steve Longerbeam

From: Steve Longerbeam <steve_longerbeam@mentor.com>

Switch to devm_kzalloc() when allocating the adv748x device struct.

The sizeof() is updated to determine the correct allocation size from
the dereferenced pointer type rather than hardcoding the struct type.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
[Kieran: Change sizeof() to dereference the pointer type]
Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
---
 drivers/media/i2c/adv748x/adv748x-core.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c
index 060d0c5b4989..1e5c7bbcf6b2 100644
--- a/drivers/media/i2c/adv748x/adv748x-core.c
+++ b/drivers/media/i2c/adv748x/adv748x-core.c
@@ -674,7 +674,7 @@ static int adv748x_probe(struct i2c_client *client,
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return -EIO;
 
-	state = kzalloc(sizeof(struct adv748x_state), GFP_KERNEL);
+	state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
 	if (!state)
 		return -ENOMEM;
 
@@ -772,7 +772,6 @@ static int adv748x_probe(struct i2c_client *client,
 	adv748x_dt_cleanup(state);
 err_free_mutex:
 	mutex_destroy(&state->mutex);
-	kfree(state);
 
 	return ret;
 }
@@ -791,8 +790,6 @@ static int adv748x_remove(struct i2c_client *client)
 	adv748x_dt_cleanup(state);
 	mutex_destroy(&state->mutex);
 
-	kfree(state);
-
 	return 0;
 }
 
-- 
2.17.1


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

* Re: [PATCH v2] media: i2c: adv748x: Use devm to allocate the device struct
  2019-01-11 16:17 [PATCH v2] media: i2c: adv748x: Use devm to allocate the device struct Kieran Bingham
@ 2019-01-14 13:06 ` Niklas Söderlund
  2019-01-14 13:15   ` Kieran Bingham
  0 siblings, 1 reply; 3+ messages in thread
From: Niklas Söderlund @ 2019-01-14 13:06 UTC (permalink / raw)
  To: Kieran Bingham; +Cc: linux-media, linux-renesas-soc, Steve Longerbeam

Hi Kieran,

Thanks for your work.

On 2019-01-11 16:17:03 +0000, Kieran Bingham wrote:
> From: Steve Longerbeam <steve_longerbeam@mentor.com>
> 
> Switch to devm_kzalloc() when allocating the adv748x device struct.
> 
> The sizeof() is updated to determine the correct allocation size from
> the dereferenced pointer type rather than hardcoding the struct type.

I would put this under a changes since v1 section and not for inclusion 
on the commit message upstream. Apart from that

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> 
> Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
> Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
> [Kieran: Change sizeof() to dereference the pointer type]
> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
> ---
>  drivers/media/i2c/adv748x/adv748x-core.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c
> index 060d0c5b4989..1e5c7bbcf6b2 100644
> --- a/drivers/media/i2c/adv748x/adv748x-core.c
> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
> @@ -674,7 +674,7 @@ static int adv748x_probe(struct i2c_client *client,
>  	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
>  		return -EIO;
>  
> -	state = kzalloc(sizeof(struct adv748x_state), GFP_KERNEL);
> +	state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
>  	if (!state)
>  		return -ENOMEM;
>  
> @@ -772,7 +772,6 @@ static int adv748x_probe(struct i2c_client *client,
>  	adv748x_dt_cleanup(state);
>  err_free_mutex:
>  	mutex_destroy(&state->mutex);
> -	kfree(state);
>  
>  	return ret;
>  }
> @@ -791,8 +790,6 @@ static int adv748x_remove(struct i2c_client *client)
>  	adv748x_dt_cleanup(state);
>  	mutex_destroy(&state->mutex);
>  
> -	kfree(state);
> -
>  	return 0;
>  }
>  
> -- 
> 2.17.1
> 

-- 
Regards,
Niklas Söderlund

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

* Re: [PATCH v2] media: i2c: adv748x: Use devm to allocate the device struct
  2019-01-14 13:06 ` Niklas Söderlund
@ 2019-01-14 13:15   ` Kieran Bingham
  0 siblings, 0 replies; 3+ messages in thread
From: Kieran Bingham @ 2019-01-14 13:15 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: linux-media, linux-renesas-soc, Steve Longerbeam

Hi Niklas,

On 14/01/2019 13:06, Niklas Söderlund wrote:
> Hi Kieran,
> 
> Thanks for your work.
> 
> On 2019-01-11 16:17:03 +0000, Kieran Bingham wrote:
>> From: Steve Longerbeam <steve_longerbeam@mentor.com>
>>
>> Switch to devm_kzalloc() when allocating the adv748x device struct.
>>
>> The sizeof() is updated to determine the correct allocation size from
>> the dereferenced pointer type rather than hardcoding the struct type.
> 
> I would put this under a changes since v1 section and not for inclusion 
> on the commit message upstream. Apart from that

I considered that, but this is an actual change as well as the
s/kzalloc/devm_kzalloc/ on top of the existing code - so I felt it was
worthy of keeping in the changelog.

(The original code uses sizeof(struct...) instead of sizeof(*s))

> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

Thanks

Kieran


> 
>>
>> Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
>> Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
>> [Kieran: Change sizeof() to dereference the pointer type]
>> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
>> ---
>>  drivers/media/i2c/adv748x/adv748x-core.c | 5 +----
>>  1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c
>> index 060d0c5b4989..1e5c7bbcf6b2 100644
>> --- a/drivers/media/i2c/adv748x/adv748x-core.c
>> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
>> @@ -674,7 +674,7 @@ static int adv748x_probe(struct i2c_client *client,
>>  	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
>>  		return -EIO;
>>  
>> -	state = kzalloc(sizeof(struct adv748x_state), GFP_KERNEL);
>> +	state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
>>  	if (!state)
>>  		return -ENOMEM;
>>  
>> @@ -772,7 +772,6 @@ static int adv748x_probe(struct i2c_client *client,
>>  	adv748x_dt_cleanup(state);
>>  err_free_mutex:
>>  	mutex_destroy(&state->mutex);
>> -	kfree(state);
>>  
>>  	return ret;
>>  }
>> @@ -791,8 +790,6 @@ static int adv748x_remove(struct i2c_client *client)
>>  	adv748x_dt_cleanup(state);
>>  	mutex_destroy(&state->mutex);
>>  
>> -	kfree(state);
>> -
>>  	return 0;
>>  }
>>  
>> -- 
>> 2.17.1
>>
> 


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

end of thread, other threads:[~2019-01-14 13:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 16:17 [PATCH v2] media: i2c: adv748x: Use devm to allocate the device struct Kieran Bingham
2019-01-14 13:06 ` Niklas Söderlund
2019-01-14 13:15   ` Kieran Bingham

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).