kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal: intel_powerclamp: Use bitmap_zalloc/bitmap_free when applicable
@ 2021-09-26  7:17 Christophe JAILLET
  2021-10-05 14:42 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2021-09-26  7:17 UTC (permalink / raw)
  To: rui.zhang, daniel.lezcano, amitk
  Cc: linux-pm, linux-kernel, kernel-janitors, Christophe JAILLET

'cpu_clamping_mask' is a bitmap. So use 'bitmap_zalloc()' and
'bitmap_free()' to simplify code, improve the semantic of the code and
avoid some open-coded arithmetic in allocator arguments.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/thermal/intel/intel_powerclamp.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c
index a5b58ea89cc6..9b68489a2356 100644
--- a/drivers/thermal/intel/intel_powerclamp.c
+++ b/drivers/thermal/intel/intel_powerclamp.c
@@ -705,10 +705,8 @@ static enum cpuhp_state hp_state;
 static int __init powerclamp_init(void)
 {
 	int retval;
-	int bitmap_size;
 
-	bitmap_size = BITS_TO_LONGS(num_possible_cpus()) * sizeof(long);
-	cpu_clamping_mask = kzalloc(bitmap_size, GFP_KERNEL);
+	cpu_clamping_mask = bitmap_zalloc(num_possible_cpus(), GFP_KERNEL);
 	if (!cpu_clamping_mask)
 		return -ENOMEM;
 
@@ -753,7 +751,7 @@ static int __init powerclamp_init(void)
 exit_unregister:
 	cpuhp_remove_state_nocalls(hp_state);
 exit_free:
-	kfree(cpu_clamping_mask);
+	bitmap_free(cpu_clamping_mask);
 	return retval;
 }
 module_init(powerclamp_init);
@@ -764,7 +762,7 @@ static void __exit powerclamp_exit(void)
 	cpuhp_remove_state_nocalls(hp_state);
 	free_percpu(worker_data);
 	thermal_cooling_device_unregister(cooling_dev);
-	kfree(cpu_clamping_mask);
+	bitmap_free(cpu_clamping_mask);
 
 	cancel_delayed_work_sync(&poll_pkg_cstate_work);
 	debugfs_remove_recursive(debug_dir);
-- 
2.30.2


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

* Re: [PATCH] thermal: intel_powerclamp: Use bitmap_zalloc/bitmap_free when applicable
  2021-09-26  7:17 [PATCH] thermal: intel_powerclamp: Use bitmap_zalloc/bitmap_free when applicable Christophe JAILLET
@ 2021-10-05 14:42 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2021-10-05 14:42 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Zhang, Rui, Daniel Lezcano, Amit Kucheria, Linux PM,
	Linux Kernel Mailing List, kernel-janitors, Srinivas Pandruvada,
	Jacob Pan

On Sun, Sep 26, 2021 at 9:17 AM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> 'cpu_clamping_mask' is a bitmap. So use 'bitmap_zalloc()' and
> 'bitmap_free()' to simplify code, improve the semantic of the code and
> avoid some open-coded arithmetic in allocator arguments.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/thermal/intel/intel_powerclamp.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c
> index a5b58ea89cc6..9b68489a2356 100644
> --- a/drivers/thermal/intel/intel_powerclamp.c
> +++ b/drivers/thermal/intel/intel_powerclamp.c
> @@ -705,10 +705,8 @@ static enum cpuhp_state hp_state;
>  static int __init powerclamp_init(void)
>  {
>         int retval;
> -       int bitmap_size;
>
> -       bitmap_size = BITS_TO_LONGS(num_possible_cpus()) * sizeof(long);
> -       cpu_clamping_mask = kzalloc(bitmap_size, GFP_KERNEL);
> +       cpu_clamping_mask = bitmap_zalloc(num_possible_cpus(), GFP_KERNEL);
>         if (!cpu_clamping_mask)
>                 return -ENOMEM;
>
> @@ -753,7 +751,7 @@ static int __init powerclamp_init(void)
>  exit_unregister:
>         cpuhp_remove_state_nocalls(hp_state);
>  exit_free:
> -       kfree(cpu_clamping_mask);
> +       bitmap_free(cpu_clamping_mask);
>         return retval;
>  }
>  module_init(powerclamp_init);
> @@ -764,7 +762,7 @@ static void __exit powerclamp_exit(void)
>         cpuhp_remove_state_nocalls(hp_state);
>         free_percpu(worker_data);
>         thermal_cooling_device_unregister(cooling_dev);
> -       kfree(cpu_clamping_mask);
> +       bitmap_free(cpu_clamping_mask);
>
>         cancel_delayed_work_sync(&poll_pkg_cstate_work);
>         debugfs_remove_recursive(debug_dir);
> --

Applied as 5.16 material, thanks!

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

end of thread, other threads:[~2021-10-05 14:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-26  7:17 [PATCH] thermal: intel_powerclamp: Use bitmap_zalloc/bitmap_free when applicable Christophe JAILLET
2021-10-05 14:42 ` Rafael J. Wysocki

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