linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal: tegra: dereference the pointer after null check
@ 2017-08-31 23:52 Nicolin Chen
       [not found] ` <1504223549-4152-1-git-send-email-nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolin Chen @ 2017-08-31 23:52 UTC (permalink / raw)
  To: rui.zhang
  Cc: edubezval, thierry.reding, jonathanh, wni, linux-pm, linux-tegra,
	linux-kernel, srikars

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 */
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] thermal: tegra: dereference the pointer after null check
       [not found] ` <1504223549-4152-1-git-send-email-nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-09-01 19:08   ` Thierry Reding
  0 siblings, 0 replies; 2+ messages in thread
From: Thierry Reding @ 2017-09-01 19:08 UTC (permalink / raw)
  To: Nicolin Chen
  Cc: rui.zhang-ral2JQCrhuEAvxtiuMwx3w,
	edubezval-Re5JQEeQqe8AvxtiuMwx3w,
	jonathanh-DDmLM1+adcrQT0dZR+AlfA, wni-DDmLM1+adcrQT0dZR+AlfA,
	linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	srikars-DDmLM1+adcrQT0dZR+AlfA

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-01 19:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).