Skip to contentSkip to conversation

thermal: tegra: dereference the pointer after null check

PATCH In review Nicolin Chen 2 participants 2 messages Aug 31, 2017 – Sep 1, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: tegra: dereference the pointer after null check

The dev pointer is going through a null check after a dereference. So this patch just reverses that.

---
 drivers/thermal/tegra/soctherm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/thermal/tegra/soctherm.c +3 -1
index 7d2db23..6718799 100644
@@ -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 */
Signature · 1 line
2.1.4
#1 lore raw
Quoted 22 lines · Nicolin Chen

The dev pointer is going through a null check after a dereference. So this patch just reverses that.

---
 drivers/thermal/tegra/soctherm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/thermal/tegra/soctherm.c +1 -1
index 7d2db23..6718799 100644
@@ -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;

drivers/thermal/tegra/soctherm.c static int throttrip_program(struct device *dev, · line 493

Quoted 8 lines
drivers/thermal/tegra/soctherm.c +2 -0
@@ -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