[bug report] thermal: devfreq_cooling: refactor code and add get_voltage function
From: Dan Carpenter <hidden>
Date: 2017-03-31 15:19:28
Hello Lukasz Luba,
The patch 88db6ba9fd98: "thermal: devfreq_cooling: refactor code and
add get_voltage function" from Mar 14, 2017, leads to the following
static checker warning:
drivers/thermal/devfreq_cooling.c:187 get_voltage()
error: 'opp' dereferencing possible ERR_PTR()
drivers/thermal/devfreq_cooling.c
176 static unsigned long get_voltage(struct devfreq *df, unsigned long freq)
177 {
178 struct device *dev = df->dev.parent;
179 unsigned long voltage;
180 struct dev_pm_opp *opp;
181
182 opp = dev_pm_opp_find_freq_exact(dev, freq, true);
183 if (IS_ERR(opp) && (PTR_ERR(opp) == -ERANGE))
Let's imagine that opp is ERR_PTR(-ENOMEM);
184 opp = dev_pm_opp_find_freq_exact(dev, freq, false);
185
186 voltage = dev_pm_opp_get_voltage(opp) / 1000; /* mV */
187 dev_pm_opp_put(opp);
^^^
Then we would Oops here.
188
189 if (voltage == 0) {
190 dev_warn_ratelimited(dev,
191 "Failed to get voltage for frequency %lu: %ld\n",
192 freq, IS_ERR(opp) ? PTR_ERR(opp) : 0);
193 }
194
195 return voltage;
196 }
regards,
dan carpenter