mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] thermal/debugfs: change kzalloc to kcalloc
@ 2025-01-19 18:34 Ethan Carter Edwards
  2025-02-09  3:44 ` Ethan Carter Edwards
  2025-02-09 12:04 ` Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Ethan Carter Edwards @ 2025-01-19 18:34 UTC (permalink / raw)
  To: rafael
  Cc: daniel.lezcano, linux-pm, linux-kernel, kernel-hardening,
	linux-hardening

We are replacing any instances of kzalloc(size * count, ...) with
kcalloc(count, size, ...) due to risk of overflow [1].

[1] https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
Link: https://github.com/KSPP/linux/issues/162

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
 v3: fix description and email client formatting
 v2: fix typo
 drivers/thermal/thermal_debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/thermal/thermal_debugfs.c b/drivers/thermal/thermal_debugfs.c
index c800504c3cfe..29dc1431a252 100644
--- a/drivers/thermal/thermal_debugfs.c
+++ b/drivers/thermal/thermal_debugfs.c
@@ -876,7 +876,7 @@ void thermal_debug_tz_add(struct thermal_zone_device *tz)
 
 	tz_dbg->tz = tz;
 
-	tz_dbg->trips_crossed = kzalloc(sizeof(int) * tz->num_trips, GFP_KERNEL);
+	tz_dbg->trips_crossed = kcalloc(tz->num_trips, sizeof(int), GFP_KERNEL);
 	if (!tz_dbg->trips_crossed) {
 		thermal_debugfs_remove_id(thermal_dbg);
 		return;
-- 
2.47.1


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

* Re: [PATCH v3] thermal/debugfs: change kzalloc to kcalloc
  2025-01-19 18:34 [PATCH v3] thermal/debugfs: change kzalloc to kcalloc Ethan Carter Edwards
@ 2025-02-09  3:44 ` Ethan Carter Edwards
  2025-02-09 12:04 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Ethan Carter Edwards @ 2025-02-09  3:44 UTC (permalink / raw)
  To: rafael
  Cc: daniel.lezcano, linux-pm, linux-kernel, kernel-hardening,
	linux-hardening

I wanted to check in on this. Anything I need to change?

Thanks,
Ethan

On 25/01/19 01:35PM, Ethan Carter Edwards wrote:
> We are replacing any instances of kzalloc(size * count, ...) with
> kcalloc(count, size, ...) due to risk of overflow [1].
> 
> [1] https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
> Link: https://github.com/KSPP/linux/issues/162
> 
> Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
> ---
>  v3: fix description and email client formatting
>  v2: fix typo
>  drivers/thermal/thermal_debugfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/thermal_debugfs.c b/drivers/thermal/thermal_debugfs.c
> index c800504c3cfe..29dc1431a252 100644
> --- a/drivers/thermal/thermal_debugfs.c
> +++ b/drivers/thermal/thermal_debugfs.c
> @@ -876,7 +876,7 @@ void thermal_debug_tz_add(struct thermal_zone_device *tz)
>  
>  	tz_dbg->tz = tz;
>  
> -	tz_dbg->trips_crossed = kzalloc(sizeof(int) * tz->num_trips, GFP_KERNEL);
> +	tz_dbg->trips_crossed = kcalloc(tz->num_trips, sizeof(int), GFP_KERNEL);
>  	if (!tz_dbg->trips_crossed) {
>  		thermal_debugfs_remove_id(thermal_dbg);
>  		return;
> -- 
> 2.47.1
> 

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

* Re: [PATCH v3] thermal/debugfs: change kzalloc to kcalloc
  2025-01-19 18:34 [PATCH v3] thermal/debugfs: change kzalloc to kcalloc Ethan Carter Edwards
  2025-02-09  3:44 ` Ethan Carter Edwards
@ 2025-02-09 12:04 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-02-09 12:04 UTC (permalink / raw)
  To: Ethan Carter Edwards, kernel-hardening, linux-hardening,
	linux-pm, Rafael J. Wysocki
  Cc: LKML, Daniel Lezcano

> We are replacing any instances of kzalloc(size * count, ...) with
> kcalloc(count, size, ...) due to risk of overflow [1].

* See also:
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.13#n94

* Would you like to improve the summary phrase another bit?


…
> +++ b/drivers/thermal/thermal_debugfs.c
> @@ -876,7 +876,7 @@ void thermal_debug_tz_add(struct thermal_zone_device *tz)
>
>  	tz_dbg->tz = tz;
>
> -	tz_dbg->trips_crossed = kzalloc(sizeof(int) * tz->num_trips, GFP_KERNEL);
> +	tz_dbg->trips_crossed = kcalloc(tz->num_trips, sizeof(int), GFP_KERNEL);
…

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.13#n941

Regards,
Markus

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

end of thread, other threads:[~2025-02-09 12:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-19 18:34 [PATCH v3] thermal/debugfs: change kzalloc to kcalloc Ethan Carter Edwards
2025-02-09  3:44 ` Ethan Carter Edwards
2025-02-09 12:04 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®