Skip to contentSkip to conversation

PM / OPP: Update OPP users to put reference

bug report Dan Carpenter 1 participant 1 message Feb 6, 2017

lore
Share & tools
lore
#0 lore raw

Hello Viresh Kumar,

The patch 8a31d9d94297: "PM / OPP: Update OPP users to put reference" from Jan 23, 2017, leads to the following static checker warning:

drivers/thermal/devfreq_cooling.c:193 get_static_power()
error: 'opp' dereferencing possible ERR_PTR()

drivers/thermal/devfreq_cooling.c

   177  static unsigned long
   178  get_static_power(struct devfreq_cooling_device *dfc, unsigned long freq)
   179  {
   180          struct devfreq *df = dfc->devfreq;
   181          struct device *dev = df->dev.parent;
   182          unsigned long voltage;
   183          struct dev_pm_opp *opp;

184
185 if (!dfc->power_ops->get_static_power)
186 return 0;
187
188 opp = dev_pm_opp_find_freq_exact(dev, freq, true);
189 if (IS_ERR(opp) && (PTR_ERR(opp) == -ERANGE))

You could just write:

		if (PTR_ERR(opp) == -ERANGE))

Or was || intended instead of &&?

   190                  opp = dev_pm_opp_find_freq_exact(dev, freq, false);
   191  
   192          voltage = dev_pm_opp_get_voltage(opp) / 1000; /* mV */
   193          dev_pm_opp_put(opp);

Anyway, we added a new dereference here, inside the function.

   194  
   195          if (voltage == 0) {
   196                  dev_warn_ratelimited(dev,
   197                                       "Failed to get voltage for frequency %lu: %ld\n",
   198                                       freq, IS_ERR(opp) ? PTR_ERR(opp) : 0);
   199                  return 0;
   200          }
   201  
   202          return dfc->power_ops->get_static_power(df, voltage);
   203  }

The same thing for get_static_power() in drivers/thermal/cpu_cooling.c.

drivers/thermal/cpu_cooling.c:399 get_static_power()
error: 'opp' dereferencing possible ERR_PTR()

regards,
dan carpenter