From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: zhangjiao2 <zhangjiao2@cmss.chinamobile.com>, rafael@kernel.org
Cc: rui.zhang@intel.com, lukasz.luba@arm.com,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/thermal: Fix common realloc mistake
Date: Thu, 14 Nov 2024 09:08:37 +0100 [thread overview]
Message-ID: <2c70b9c3-e0f0-4551-864d-5d5252fccf99@linaro.org> (raw)
In-Reply-To: <20241108044700.37633-1-zhangjiao2@cmss.chinamobile.com>
Hi Zhang,
thanks for spotting the issue
On 08/11/2024 05:47, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
>
> Do not set thermometer->tz NULL when realloc failed.
You may describe a bit more the change.
eg.
If the 'realloc' fails, the thermal zones pointer is set to NULL. This
makes all thermal zones references which were previously successfully
initialized to be lost.
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> ---
> tools/thermal/thermometer/thermometer.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/thermal/thermometer/thermometer.c b/tools/thermal/thermometer/thermometer.c
> index 1a87a0a77f9f..e08291a97fd8 100644
> --- a/tools/thermal/thermometer/thermometer.c
> +++ b/tools/thermal/thermometer/thermometer.c
> @@ -259,6 +259,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling,
> {
> int fd;
> char tz_path[PATH_MAX];
> + void *tmp;
Please use right type:
struct tz *tz;
> sprintf(tz_path, CLASS_THERMAL"/%s/temp", path);
>
> @@ -268,12 +269,13 @@ static int thermometer_add_tz(const char *path, const char *name, int polling,
> return -1;
> }
>
> - thermometer->tz = realloc(thermometer->tz,
> + tmp = realloc(thermometer->tz,
> sizeof(*thermometer->tz) * (thermometer->nr_tz + 1));
> - if (!thermometer->tz) {
> + if (!tmp) {
> ERROR("Failed to allocate thermometer->tz\n");
> return -1;
> }
> + thermometer->tz = tmp;
>
> thermometer->tz[thermometer->nr_tz].fd_temp = fd;
> thermometer->tz[thermometer->nr_tz].name = strdup(name);
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
prev parent reply other threads:[~2024-11-14 8:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-08 4:47 zhangjiao2
2024-11-08 12:09 ` Rafael J. Wysocki
2024-11-11 8:19 ` zhangjiao2
2024-11-14 8:08 ` Daniel Lezcano [this message]
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=2c70b9c3-e0f0-4551-864d-5d5252fccf99@linaro.org \
--to=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
--cc=zhangjiao2@cmss.chinamobile.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
all inboxes | Powered by JetHome®