pwm: devm: alloc correct pointer size
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
@@ -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
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
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?
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
Thierry Reding
AppliedQuoted 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