All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Nicolin Chen <nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: rui.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	edubezval-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org,
	wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org,
	linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	srikars-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH] thermal: tegra: dereference the pointer after null check
Date: Fri, 1 Sep 2017 21:08:35 +0200	[thread overview]
Message-ID: <20170901190835.GA14011@ulmo> (raw)
In-Reply-To: <1504223549-4152-1-git-send-email-nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1385 bytes --]

On Thu, Aug 31, 2017 at 04:52:29PM -0700, Nicolin Chen wrote:
> The dev pointer is going through a null check after a dereference.
> So this patch just reverses that.
> 
> Signed-off-by: Nicolin Chen <nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  drivers/thermal/tegra/soctherm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
> index 7d2db23..6718799 100644
> --- a/drivers/thermal/tegra/soctherm.c
> +++ b/drivers/thermal/tegra/soctherm.c
> @@ -478,7 +478,7 @@ static int throttrip_program(struct device *dev,
>  			     struct soctherm_throt_cfg *stc,
>  			     int trip_temp)
>  {
> -	struct tegra_soctherm *ts = dev_get_drvdata(dev);
> +	struct tegra_soctherm *ts;
>  	int temp, cpu_throt, gpu_throt;
>  	unsigned int throt;
>  	u32 r, reg_off;
> @@ -486,6 +486,8 @@ static int throttrip_program(struct device *dev,
>  	if (!dev || !sg || !stc || !stc->init)
>  		return -EINVAL;
>  
> +	ts = dev_get_drvdata(dev);
> +
>  	temp = enforce_temp_range(dev, trip_temp) / ts->soc->thresh_grain;
>  
>  	/* Hardcode LIGHT on LEVEL1 and HEAVY on LEVEL2 */

I don't see a case where dev is ever going to be NULL here. Therefore, I
think a better patch would be to just drop the !dev test and leave the
rest of the code as-is.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Thierry Reding <thierry.reding@gmail.com>
To: Nicolin Chen <nicoleotsuka@gmail.com>
Cc: rui.zhang@intel.com, edubezval@gmail.com, jonathanh@nvidia.com,
	wni@nvidia.com, linux-pm@vger.kernel.org,
	linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org,
	srikars@nvidia.com
Subject: Re: [PATCH] thermal: tegra: dereference the pointer after null check
Date: Fri, 1 Sep 2017 21:08:35 +0200	[thread overview]
Message-ID: <20170901190835.GA14011@ulmo> (raw)
In-Reply-To: <1504223549-4152-1-git-send-email-nicoleotsuka@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1355 bytes --]

On Thu, Aug 31, 2017 at 04:52:29PM -0700, Nicolin Chen wrote:
> The dev pointer is going through a null check after a dereference.
> So this patch just reverses that.
> 
> Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
> ---
>  drivers/thermal/tegra/soctherm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
> index 7d2db23..6718799 100644
> --- a/drivers/thermal/tegra/soctherm.c
> +++ b/drivers/thermal/tegra/soctherm.c
> @@ -478,7 +478,7 @@ static int throttrip_program(struct device *dev,
>  			     struct soctherm_throt_cfg *stc,
>  			     int trip_temp)
>  {
> -	struct tegra_soctherm *ts = dev_get_drvdata(dev);
> +	struct tegra_soctherm *ts;
>  	int temp, cpu_throt, gpu_throt;
>  	unsigned int throt;
>  	u32 r, reg_off;
> @@ -486,6 +486,8 @@ static int throttrip_program(struct device *dev,
>  	if (!dev || !sg || !stc || !stc->init)
>  		return -EINVAL;
>  
> +	ts = dev_get_drvdata(dev);
> +
>  	temp = enforce_temp_range(dev, trip_temp) / ts->soc->thresh_grain;
>  
>  	/* Hardcode LIGHT on LEVEL1 and HEAVY on LEVEL2 */

I don't see a case where dev is ever going to be NULL here. Therefore, I
think a better patch would be to just drop the !dev test and leave the
rest of the code as-is.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2017-09-01 19:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 23:52 [PATCH] thermal: tegra: dereference the pointer after null check Nicolin Chen
     [not found] ` <1504223549-4152-1-git-send-email-nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-09-01 19:08   ` Thierry Reding [this message]
2017-09-01 19:08     ` Thierry Reding

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=20170901190835.GA14011@ulmo \
    --to=thierry.reding-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=edubezval-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=rui.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=srikars-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.