@@ -506,6 +506,9 @@ static int genpd_dev_pm_set_performance_state(struct device *dev,
struct generic_pm_domain *genpd = dev_to_genpd(dev);
int ret = 0;
+ if (IS_ERR(genpd))
+ return PTR_ERR(genpd);
+
genpd_lock(genpd);
if (pm_runtime_suspended(dev)) {
dev_gpd_data(dev)->rpm_pstate = state;
@@ -963,6 +966,9 @@ static int genpd_dev_pm_start(struct device *dev)
{
struct generic_pm_domain *genpd = dev_to_genpd(dev);
+ if (IS_ERR(genpd))
+ return PTR_ERR(genpd);
+
return genpd_start_dev(genpd, dev);
}
Fix an issue detected by the Smatch tool: drivers/pmdomain/core.c:509 genpd_dev_pm_set_performance_state() error: 'genpd' dereferencing possible ERR_PTR() drivers/pmdomain/core.c:970 genpd_dev_pm_start() error: 'genpd' dereferencing possible ERR_PTR() The function `dev_to_genpd(dev)` may return an error pointer, and the code does not check whether it is valid before dereferencing. This can lead to undefined behavior. To fix this, checks were added to ensure that `genpd` is not an error pointer before using it. If an error pointer is encountered, the function returns the error value using `PTR_ERR(genpd)`. Signed-off-by: Suraj Sonawane <surajsonawane0215@gmail.com> --- drivers/pmdomain/core.c | 6 ++++++ 1 file changed, 6 insertions(+)