* [PATCH] thermal: sysfs: Fall back to vmalloc() for cooling device's statistics
@ 2020-08-21 2:44 Yue Hu
2020-08-21 5:00 ` Viresh Kumar
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Yue Hu @ 2020-08-21 2:44 UTC (permalink / raw)
To: rui.zhang, daniel.lezcano, amit.kucheria, viresh.kumar
Cc: linux-pm, linux-kernel, huyue2, zhangwen
From: Yue Hu <huyue2@yulong.com>
We observed warning about kzalloc() when register thermal cooling device
in backlight_device_register(). backlight display can be a cooling device
since reducing screen brightness will can help reduce temperature.
However, ->get_max_state of backlight will assign max brightness of 1024
to states. The memory size can be getting 1MB+ due to states * states.
That is so large to trigger kmalloc() warning.
So, let's use kvzalloc() to avoid the issue, also change kfree -> kvfree.
Suggested-by: Amit Kucheria <amitk@kernel.org>
Signed-off-by: Yue Hu <huyue2@yulong.com>
---
drivers/thermal/thermal_sysfs.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index aa99edb..d1703ee 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -16,6 +16,7 @@
#include <linux/device.h>
#include <linux/err.h>
#include <linux/slab.h>
+#include <linux/mm.h>
#include <linux/string.h>
#include <linux/jiffies.h>
@@ -919,7 +920,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
var += sizeof(*stats->time_in_state) * states;
var += sizeof(*stats->trans_table) * states * states;
- stats = kzalloc(var, GFP_KERNEL);
+ stats = kvzalloc(var, GFP_KERNEL);
if (!stats)
return;
@@ -938,7 +939,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
static void cooling_device_stats_destroy(struct thermal_cooling_device *cdev)
{
- kfree(cdev->stats);
+ kvfree(cdev->stats);
cdev->stats = NULL;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] thermal: sysfs: Fall back to vmalloc() for cooling device's statistics
2020-08-21 2:44 [PATCH] thermal: sysfs: Fall back to vmalloc() for cooling device's statistics Yue Hu
@ 2020-08-21 5:00 ` Viresh Kumar
2020-08-21 7:02 ` Amit Kucheria
2020-08-21 8:39 ` David Laight
2 siblings, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2020-08-21 5:00 UTC (permalink / raw)
To: Yue Hu
Cc: rui.zhang, daniel.lezcano, amit.kucheria, linux-pm, linux-kernel,
huyue2, zhangwen
On 21-08-20, 10:44, Yue Hu wrote:
> From: Yue Hu <huyue2@yulong.com>
>
> We observed warning about kzalloc() when register thermal cooling device
> in backlight_device_register(). backlight display can be a cooling device
> since reducing screen brightness will can help reduce temperature.
>
> However, ->get_max_state of backlight will assign max brightness of 1024
> to states. The memory size can be getting 1MB+ due to states * states.
> That is so large to trigger kmalloc() warning.
>
> So, let's use kvzalloc() to avoid the issue, also change kfree -> kvfree.
>
> Suggested-by: Amit Kucheria <amitk@kernel.org>
> Signed-off-by: Yue Hu <huyue2@yulong.com>
> ---
> drivers/thermal/thermal_sysfs.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] thermal: sysfs: Fall back to vmalloc() for cooling device's statistics
2020-08-21 2:44 [PATCH] thermal: sysfs: Fall back to vmalloc() for cooling device's statistics Yue Hu
2020-08-21 5:00 ` Viresh Kumar
@ 2020-08-21 7:02 ` Amit Kucheria
2020-08-21 8:39 ` David Laight
2 siblings, 0 replies; 5+ messages in thread
From: Amit Kucheria @ 2020-08-21 7:02 UTC (permalink / raw)
To: Yue Hu
Cc: Zhang Rui, Daniel Lezcano, Viresh Kumar, Linux PM list, LKML,
huyue2, zhangwen
On Fri, Aug 21, 2020 at 8:14 AM Yue Hu <zbestahu@gmail.com> wrote:
>
> From: Yue Hu <huyue2@yulong.com>
>
> We observed warning about kzalloc() when register thermal cooling device
> in backlight_device_register(). backlight display can be a cooling device
> since reducing screen brightness will can help reduce temperature.
>
> However, ->get_max_state of backlight will assign max brightness of 1024
> to states. The memory size can be getting 1MB+ due to states * states.
> That is so large to trigger kmalloc() warning.
>
> So, let's use kvzalloc() to avoid the issue, also change kfree -> kvfree.
>
> Suggested-by: Amit Kucheria <amitk@kernel.org>
> Signed-off-by: Yue Hu <huyue2@yulong.com>
Reviewed-by: Amit Kucheria <amitk@kernel.org>
> ---
> drivers/thermal/thermal_sysfs.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
> index aa99edb..d1703ee 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -16,6 +16,7 @@
> #include <linux/device.h>
> #include <linux/err.h>
> #include <linux/slab.h>
> +#include <linux/mm.h>
> #include <linux/string.h>
> #include <linux/jiffies.h>
>
> @@ -919,7 +920,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
> var += sizeof(*stats->time_in_state) * states;
> var += sizeof(*stats->trans_table) * states * states;
>
> - stats = kzalloc(var, GFP_KERNEL);
> + stats = kvzalloc(var, GFP_KERNEL);
> if (!stats)
> return;
>
> @@ -938,7 +939,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
>
> static void cooling_device_stats_destroy(struct thermal_cooling_device *cdev)
> {
> - kfree(cdev->stats);
> + kvfree(cdev->stats);
> cdev->stats = NULL;
> }
>
> --
> 1.9.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] thermal: sysfs: Fall back to vmalloc() for cooling device's statistics
2020-08-21 2:44 [PATCH] thermal: sysfs: Fall back to vmalloc() for cooling device's statistics Yue Hu
2020-08-21 5:00 ` Viresh Kumar
2020-08-21 7:02 ` Amit Kucheria
@ 2020-08-21 8:39 ` David Laight
2020-08-21 9:06 ` Yue Hu
2 siblings, 1 reply; 5+ messages in thread
From: David Laight @ 2020-08-21 8:39 UTC (permalink / raw)
To: 'Yue Hu', rui.zhang, daniel.lezcano, amit.kucheria, viresh.kumar
Cc: linux-pm, linux-kernel, huyue2, zhangwen
From: Yue Hu
> Sent: 21 August 2020 03:44
>
> From: Yue Hu <huyue2@yulong.com>
>
> We observed warning about kzalloc() when register thermal cooling device
> in backlight_device_register(). backlight display can be a cooling device
> since reducing screen brightness will can help reduce temperature.
>
> However, ->get_max_state of backlight will assign max brightness of 1024
> to states. The memory size can be getting 1MB+ due to states * states.
> That is so large to trigger kmalloc() warning.
I can't help feeling that there is an 'adequate' implementation
that doesn't require anywhere near 1MB of memory.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] thermal: sysfs: Fall back to vmalloc() for cooling device's statistics
2020-08-21 8:39 ` David Laight
@ 2020-08-21 9:06 ` Yue Hu
0 siblings, 0 replies; 5+ messages in thread
From: Yue Hu @ 2020-08-21 9:06 UTC (permalink / raw)
To: David Laight
Cc: rui.zhang, daniel.lezcano, amit.kucheria, viresh.kumar, linux-pm,
linux-kernel, huyue2, zhangwen
On Fri, 21 Aug 2020 08:39:45 +0000
David Laight <David.Laight@ACULAB.COM> wrote:
> From: Yue Hu
> > Sent: 21 August 2020 03:44
> >
> > From: Yue Hu <huyue2@yulong.com>
> >
> > We observed warning about kzalloc() when register thermal cooling device
> > in backlight_device_register(). backlight display can be a cooling device
> > since reducing screen brightness will can help reduce temperature.
> >
> > However, ->get_max_state of backlight will assign max brightness of 1024
> > to states. The memory size can be getting 1MB+ due to states * states.
> > That is so large to trigger kmalloc() warning.
>
> I can't help feeling that there is an 'adequate' implementation
> that doesn't require anywhere near 1MB of memory.
However, it should be a potential issue due to what i described above, rt?
Thx.
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-08-21 9:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-21 2:44 [PATCH] thermal: sysfs: Fall back to vmalloc() for cooling device's statistics Yue Hu
2020-08-21 5:00 ` Viresh Kumar
2020-08-21 7:02 ` Amit Kucheria
2020-08-21 8:39 ` David Laight
2020-08-21 9:06 ` Yue Hu
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).