mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Thierry Reding <thierry.reding@gmail.com>,
	Zhang Rui <rui.zhang@intel.com>
Cc: Amit Kucheria <amitk@kernel.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] thermal: Fix zone lookup by ID
Date: Fri, 24 Jul 2020 19:12:49 +0200	[thread overview]
Message-ID: <db6efeab-b2bc-bad5-9c75-89e3e306256c@linaro.org> (raw)
In-Reply-To: <20200724170105.2705467-1-thierry.reding@gmail.com>

Hi Thierry,

Applied, thanks for the fix!


On 24/07/2020 19:01, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> When a thermal zone is looked up by an ID and no zone is found matching
> that ID, the thermal_zone_get_by_id() function will return a pointer to
> the thermal zone list head which isn't actually a valid thermal zone.
> 
> This can lead to a subsequent crash because a valid pointer is returned
> to the called, but dereferencing that pointer as struct thermal_zone is
> not safe.
> 
> Fixes: 329b064fbd13 ("thermal: core: Get thermal zone by id")
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  drivers/thermal/thermal_core.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 007f9618e20a..9748fbb9a3a1 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -751,16 +751,18 @@ int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
>  
>  struct thermal_zone_device *thermal_zone_get_by_id(int id)
>  {
> -	struct thermal_zone_device *tz = NULL;
> +	struct thermal_zone_device *tz, *match = NULL;
>  
>  	mutex_lock(&thermal_list_lock);
>  	list_for_each_entry(tz, &thermal_tz_list, node) {
> -		if (tz->id == id)
> +		if (tz->id == id) {
> +			match = tz;
>  			break;
> +		}
>  	}
>  	mutex_unlock(&thermal_list_lock);
>  
> -	return tz;
> +	return match;
>  }
>  
>  void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,
> 


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

  reply	other threads:[~2020-07-24 17:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-24 17:01 Thierry Reding
2020-07-24 17:12 ` Daniel Lezcano [this message]
2020-07-27  9:01   ` Thierry Reding
2020-07-27  9:04     ` Daniel Lezcano

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=db6efeab-b2bc-bad5-9c75-89e3e306256c@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=amitk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=thierry.reding@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

all inboxes | Powered by JetHome®