* [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size
@ 2024-06-16 9:54 Zijun Hu
2024-06-16 9:58 ` Greg KH
2024-06-16 10:02 ` Greg KH
0 siblings, 2 replies; 6+ messages in thread
From: Zijun Hu @ 2024-06-16 9:54 UTC (permalink / raw)
To: gregkh, rafael; +Cc: andriy.shevchenko, brgl, linux-kernel, Zijun Hu
Kernel API devm_krealloc() calls alloc_dr() with wrong argument
@total_new_size, and it will cause more memory to be allocated
than required, fixed by using @new_size as alloc_dr()'s argument.
Fixes: f82485722e5d ("devres: provide devm_krealloc()")
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
drivers/base/devres.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 3df0025d12aa..1cf87ddf1f55 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -898,7 +898,7 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp)
* taking the lock as most probably the caller uses GFP_KERNEL.
*/
new_dr = alloc_dr(devm_kmalloc_release,
- total_new_size, gfp, dev_to_node(dev));
+ new_size, gfp, dev_to_node(dev));
if (!new_dr)
return NULL;
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size
2024-06-16 9:54 [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size Zijun Hu
@ 2024-06-16 9:58 ` Greg KH
2024-06-16 10:02 ` Greg KH
1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2024-06-16 9:58 UTC (permalink / raw)
To: Zijun Hu; +Cc: rafael, andriy.shevchenko, brgl, linux-kernel
On Sun, Jun 16, 2024 at 05:54:15PM +0800, Zijun Hu wrote:
> Kernel API devm_krealloc() calls alloc_dr() with wrong argument
> @total_new_size, and it will cause more memory to be allocated
> than required, fixed by using @new_size as alloc_dr()'s argument.
>
> Fixes: f82485722e5d ("devres: provide devm_krealloc()")
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
> drivers/base/devres.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
> index 3df0025d12aa..1cf87ddf1f55 100644
> --- a/drivers/base/devres.c
> +++ b/drivers/base/devres.c
> @@ -898,7 +898,7 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp)
> * taking the lock as most probably the caller uses GFP_KERNEL.
> */
> new_dr = alloc_dr(devm_kmalloc_release,
> - total_new_size, gfp, dev_to_node(dev));
> + new_size, gfp, dev_to_node(dev));
> if (!new_dr)
> return NULL;
>
> --
> 2.7.4
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- You have marked a patch with a "Fixes:" tag for a commit that is in an
older released kernel, yet you do not have a cc: stable line in the
signed-off-by area at all, which means that the patch will not be
applied to any older kernel releases. To properly fix this, please
follow the documented rules in the
Documentation/process/stable-kernel-rules.rst file for how to resolve
this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size
2024-06-16 9:54 [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size Zijun Hu
2024-06-16 9:58 ` Greg KH
@ 2024-06-16 10:02 ` Greg KH
2024-06-16 10:10 ` quic_zijuhu
1 sibling, 1 reply; 6+ messages in thread
From: Greg KH @ 2024-06-16 10:02 UTC (permalink / raw)
To: Zijun Hu; +Cc: rafael, andriy.shevchenko, brgl, linux-kernel
On Sun, Jun 16, 2024 at 05:54:15PM +0800, Zijun Hu wrote:
> Kernel API devm_krealloc() calls alloc_dr() with wrong argument
> @total_new_size, and it will cause more memory to be allocated
> than required, fixed by using @new_size as alloc_dr()'s argument.
>
> Fixes: f82485722e5d ("devres: provide devm_krealloc()")
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
> drivers/base/devres.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
> index 3df0025d12aa..1cf87ddf1f55 100644
> --- a/drivers/base/devres.c
> +++ b/drivers/base/devres.c
> @@ -898,7 +898,7 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp)
> * taking the lock as most probably the caller uses GFP_KERNEL.
> */
> new_dr = alloc_dr(devm_kmalloc_release,
> - total_new_size, gfp, dev_to_node(dev));
> + new_size, gfp, dev_to_node(dev));
Wait, are you sure? Did you properly test this? What is the actual
savings and how do you handle the fact that you are now not allocating
the space reserved for the devres structure itself?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size
2024-06-16 10:02 ` Greg KH
@ 2024-06-16 10:10 ` quic_zijuhu
2024-06-16 10:17 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: quic_zijuhu @ 2024-06-16 10:10 UTC (permalink / raw)
To: Greg KH; +Cc: rafael, andriy.shevchenko, brgl, linux-kernel
On 6/16/2024 6:02 PM, Greg KH wrote:
> On Sun, Jun 16, 2024 at 05:54:15PM +0800, Zijun Hu wrote:
>> Kernel API devm_krealloc() calls alloc_dr() with wrong argument
>> @total_new_size, and it will cause more memory to be allocated
>> than required, fixed by using @new_size as alloc_dr()'s argument.
>>
>> Fixes: f82485722e5d ("devres: provide devm_krealloc()")
>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
>> ---
>> drivers/base/devres.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
>> index 3df0025d12aa..1cf87ddf1f55 100644
>> --- a/drivers/base/devres.c
>> +++ b/drivers/base/devres.c
>> @@ -898,7 +898,7 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp)
>> * taking the lock as most probably the caller uses GFP_KERNEL.
>> */
>> new_dr = alloc_dr(devm_kmalloc_release,
>> - total_new_size, gfp, dev_to_node(dev));
>> + new_size, gfp, dev_to_node(dev));
>
> Wait, are you sure? Did you properly test this? What is the actual
> savings and how do you handle the fact that you are now not allocating
> the space reserved for the devres structure itself?
>
sure even if i did not test it.
beware that alloc_dr() will call check_dr_size() to reserve space for
devres structure.
it will reserve the devres structure two times if using wrong
@total_new_size. it is obvious wrong.
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size
2024-06-16 10:10 ` quic_zijuhu
@ 2024-06-16 10:17 ` Greg KH
2024-06-16 10:22 ` quic_zijuhu
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2024-06-16 10:17 UTC (permalink / raw)
To: quic_zijuhu; +Cc: rafael, andriy.shevchenko, brgl, linux-kernel
On Sun, Jun 16, 2024 at 06:10:02PM +0800, quic_zijuhu wrote:
> On 6/16/2024 6:02 PM, Greg KH wrote:
> > On Sun, Jun 16, 2024 at 05:54:15PM +0800, Zijun Hu wrote:
> >> Kernel API devm_krealloc() calls alloc_dr() with wrong argument
> >> @total_new_size, and it will cause more memory to be allocated
> >> than required, fixed by using @new_size as alloc_dr()'s argument.
> >>
> >> Fixes: f82485722e5d ("devres: provide devm_krealloc()")
> >> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> >> ---
> >> drivers/base/devres.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
> >> index 3df0025d12aa..1cf87ddf1f55 100644
> >> --- a/drivers/base/devres.c
> >> +++ b/drivers/base/devres.c
> >> @@ -898,7 +898,7 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp)
> >> * taking the lock as most probably the caller uses GFP_KERNEL.
> >> */
> >> new_dr = alloc_dr(devm_kmalloc_release,
> >> - total_new_size, gfp, dev_to_node(dev));
> >> + new_size, gfp, dev_to_node(dev));
> >
> > Wait, are you sure? Did you properly test this? What is the actual
> > savings and how do you handle the fact that you are now not allocating
> > the space reserved for the devres structure itself?
> >
> sure even if i did not test it.
> beware that alloc_dr() will call check_dr_size() to reserve space for
> devres structure.
>
> it will reserve the devres structure two times if using wrong
> @total_new_size. it is obvious wrong.
Ah, I missed that, that is tricky. Please document this better when you
resubmit a new version.
And of course, please test it.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size
2024-06-16 10:17 ` Greg KH
@ 2024-06-16 10:22 ` quic_zijuhu
0 siblings, 0 replies; 6+ messages in thread
From: quic_zijuhu @ 2024-06-16 10:22 UTC (permalink / raw)
To: Greg KH; +Cc: rafael, andriy.shevchenko, brgl, linux-kernel
On 6/16/2024 6:17 PM, Greg KH wrote:
> On Sun, Jun 16, 2024 at 06:10:02PM +0800, quic_zijuhu wrote:
>> On 6/16/2024 6:02 PM, Greg KH wrote:
>>> On Sun, Jun 16, 2024 at 05:54:15PM +0800, Zijun Hu wrote:
>>>> Kernel API devm_krealloc() calls alloc_dr() with wrong argument
>>>> @total_new_size, and it will cause more memory to be allocated
>>>> than required, fixed by using @new_size as alloc_dr()'s argument.
>>>>
>>>> Fixes: f82485722e5d ("devres: provide devm_krealloc()")
>>>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
>>>> ---
>>>> drivers/base/devres.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
>>>> index 3df0025d12aa..1cf87ddf1f55 100644
>>>> --- a/drivers/base/devres.c
>>>> +++ b/drivers/base/devres.c
>>>> @@ -898,7 +898,7 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp)
>>>> * taking the lock as most probably the caller uses GFP_KERNEL.
>>>> */
>>>> new_dr = alloc_dr(devm_kmalloc_release,
>>>> - total_new_size, gfp, dev_to_node(dev));
>>>> + new_size, gfp, dev_to_node(dev));
>>>
>>> Wait, are you sure? Did you properly test this? What is the actual
>>> savings and how do you handle the fact that you are now not allocating
>>> the space reserved for the devres structure itself?
>>>
>> sure even if i did not test it.
>> beware that alloc_dr() will call check_dr_size() to reserve space for
>> devres structure.
>>
>> it will reserve the devres structure two times if using wrong
>> @total_new_size. it is obvious wrong.
>
> Ah, I missed that, that is tricky. Please document this better when you
> resubmit a new version.
>
okay. will send v2.
> And of course, please test it.
okay.
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-06-16 10:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-16 9:54 [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size Zijun Hu
2024-06-16 9:58 ` Greg KH
2024-06-16 10:02 ` Greg KH
2024-06-16 10:10 ` quic_zijuhu
2024-06-16 10:17 ` Greg KH
2024-06-16 10:22 ` quic_zijuhu
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.