From: Amit Kucheria <amitk@kernel.org>
To: Yue Hu <zbestahu@gmail.com>
Cc: Zhang Rui <rui.zhang@intel.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Linux PM list <linux-pm@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
huyue2@yulong.com, zbestahu@163.com
Subject: Re: [PATCH] thermal: sysfs: fall back to vzalloc for cooling device's statistics
Date: Wed, 19 Aug 2020 16:47:01 +0530 [thread overview]
Message-ID: <CAHLCerPpsFoy=MZSQiHyCCoHLU2X=pT=NR6b0pkX93C+cd5uCg@mail.gmail.com> (raw)
In-Reply-To: <20200818063005.13828-1-zbestahu@gmail.com>
On Tue, Aug 18, 2020 at 12:00 PM 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 remove it and try vzalloc() if kzalloc() fails.
>
> Signed-off-by: Yue Hu <huyue2@yulong.com>
> ---
> drivers/thermal/thermal_sysfs.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
> index aa99edb..9bae0b6 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -16,6 +16,8 @@
> #include <linux/device.h>
> #include <linux/err.h>
> #include <linux/slab.h>
> +#include <linux/vmalloc.h>
> +#include <linux/mm.h>
> #include <linux/string.h>
> #include <linux/jiffies.h>
>
> @@ -919,7 +921,9 @@ 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 = kzalloc(var, GFP_KERNEL | __GFP_NOWARN);
> + if (!stats)
> + stats = vzalloc(var);
Couldn't this be replaced by kvzalloc()?
> if (!stats)
> return;
>
> @@ -938,7 +942,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
>
next prev parent reply other threads:[~2020-08-19 11:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-18 6:30 [PATCH] thermal: sysfs: fall back to vzalloc for cooling device's statistics Yue Hu
2020-08-19 11:05 ` Amit Kucheria
2020-08-19 11:17 ` Amit Kucheria [this message]
2020-08-20 2:57 ` Yue Hu
2020-08-24 10:40 ` Daniel Lezcano
2020-08-26 2:13 ` Yue Hu
2020-08-26 9:19 ` Daniel Lezcano
2020-08-27 4:03 ` Yue Hu
2020-08-27 5:14 ` Viresh Kumar
2020-08-27 6:20 ` Yue Hu
2020-08-27 6:26 ` Viresh Kumar
2020-08-27 6:40 ` Yue Hu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHLCerPpsFoy=MZSQiHyCCoHLU2X=pT=NR6b0pkX93C+cd5uCg@mail.gmail.com' \
--to=amitk@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=huyue2@yulong.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rui.zhang@intel.com \
--cc=viresh.kumar@linaro.org \
--cc=zbestahu@163.com \
--cc=zbestahu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).