thermal: sysfs: Fall back to vmalloc() for cooling device's statistics
PATCH 1/1 thermal: sysfs: Fall back to vmalloc() for cooling device's statistics
From: Yue Hu <[email protected]>
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.
--- drivers/thermal/thermal_sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/thermal_sysfs.c +3 -2
@@ -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 ; }
Signature · 1 line
1.9.1
Quoted 10 lines · Yue Hu
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_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.
Quoted 7 lines
So, let's use
kvzalloc()to avoid the issue, also change kfree -> kvfree.Suggested-by Amit Kucheria <[email protected]>Signed-off-by Yue Hu <[email protected]>--- drivers/thermal/thermal_sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
viresh
Quoted 7 lines · Yue Hu
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_device_register(). backlight display can be a cooling device since reducing screen brightness will can help reduce temperature.
Quoted 8 lines
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 <[email protected]>Signed-off-by Yue Hu <[email protected]>
Quoted 37 lines
--- drivers/thermal/thermal_sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/thermal/thermal_sysfs.c +3
-3@@ -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
From: Yue Hu
Quoted 11 lines
Sent: 21 August 2020 03:44
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_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)
Quoted 9 lines · On Fri, 21 Aug 2020 08:39:45 +0000 David Laight <[email protected]> wrote:
From: Yue Hu
Quoted 8 lines
Sent: 21 August 2020 03:44
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_device_register(). backlight display can be a cooling device since reducing screen brightness will can help reduce temperature.
Quoted 6 lines
Quoted 3 lines
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.
Quoted 7 lines
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)