Skip to contentSkip to conversation

pwm: devm: alloc correct pointer size

PATCH Applied Wolfram Sang 3 participants 5 messages Jun 3, 2013 – Jun 10, 2013 PWM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwm: devm: alloc correct pointer size

The allocated object should be the size of what the pointer is pointing to and not the size of the pointer itself.

---
 drivers/pwm/core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pwm/core.c +2 -2
index 32221cb..0cf0f65 100644
@@ -694,7 +694,7 @@ struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id)
 {
 	struct pwm_device **ptr, *pwm;
 
-	ptr = devres_alloc(devm_pwm_release, sizeof(**ptr), GFP_KERNEL);
+	ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
 	if (!ptr)
 		return ERR_PTR(-ENOMEM);
 
@@ -724,7 +724,7 @@ struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
 {
 	struct pwm_device **ptr, *pwm;
 
-	ptr = devres_alloc(devm_pwm_release, sizeof(**ptr), GFP_KERNEL);
+	ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
 	if (!ptr)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 2 lines · Wolfram Sang

The allocated object should be the size of what the pointer is pointing to and not the size of the pointer itself.

All devm_* functions in this module use **ptr as a parameter (except allocation).
May be we first should understand why it so?
If it wrong approach, than probably you have to change **ptr -> *ptr. But without answer on first question I don't know if it proper solution or not.

--
With Best Regards,
Andy Shevchenko

#2 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Wolfram Sang

The allocated object should be the size of what the pointer is pointing to and not the size of the pointer itself.

All devm_* functions in this module use **ptr as a parameter (except allocation).
May be we first should understand why it so?

Huh? **ptr is already created on the stack, but assigned the alloced memory. Later, the mem it points to is set to 'pwm' which is then added to devres. So, the alloced memory must be able to contain '*ptr' (or *pwm which would be more readable IMO, but other subsystems also stick to *ptr), no?

#3 lore raw
Quoted 9 lines · Wolfram Sang
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Wolfram Sang

The allocated object should be the size of what the pointer is pointing to and not the size of the pointer itself.

All devm_* functions in this module use **ptr as a parameter (except allocation).
May be we first should understand why it so?

Quoted 5 lines

Huh? **ptr is already created on the stack, but assigned the alloced memory. Later, the mem it points to is set to 'pwm' which is then added to devres. So, the alloced memory must be able to contain '*ptr' (or *pwm which would be more readable IMO, but other subsystems also stick to *ptr), no?

Yes, you right.
Take my Reviewed-by: Andy Shevchenko <[email protected]>

--
With Best Regards,
Andy Shevchenko

#4 lore raw
Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · Wolfram Sang
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Wolfram Sang

The allocated object should be the size of what the pointer is pointing to and not the size of the pointer itself.

All devm_* functions in this module use **ptr as a parameter (except allocation).
May be we first should understand why it so?

Quoted 8 lines
Quoted 5 lines

Huh? **ptr is already created on the stack, but assigned the alloced memory. Later, the mem it points to is set to 'pwm' which is then added to devres. So, the alloced memory must be able to contain '*ptr' (or *pwm which would be more readable IMO, but other subsystems also stick to *ptr), no?

Yes, you right.
Take my Reviewed-by: Andy Shevchenko <[email protected]>

Applied, thanks.

Thierry