Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1724696 > unrolled thread

[PATCH] thermal: tegra: dereference the pointer after null check

Started byNicolin Chen <nicoleotsuka@gmail.com>
First post2017-09-01 02:00 +0200
Last post2017-09-01 21:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] thermal: tegra: dereference the pointer after null check Nicolin Chen <nicoleotsuka@gmail.com> - 2017-09-01 02:00 +0200
    Re: [PATCH] thermal: tegra: dereference the pointer after null check Thierry Reding <thierry.reding@gmail.com> - 2017-09-01 21:10 +0200

#1724696 — [PATCH] thermal: tegra: dereference the pointer after null check

FromNicolin Chen <nicoleotsuka@gmail.com>
Date2017-09-01 02:00 +0200
Subject[PATCH] thermal: tegra: dereference the pointer after null check
Message-ID<ukHxo-45L-23@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1725297

FromThierry Reding <thierry.reding@gmail.com>
Date2017-09-01 21:10 +0200
Message-ID<ukZuj-Os-29@gated-at.bofh.it>
In reply to#1724696

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web