Skip to content
Permalink
Browse files
power_supply: Register cooling device outside of probe
Registering the cooling device from the probe can result in the
execution of get_property() function before it gets initialized.

To avoid this, register the cooling device from a workqueue
instead of registering in the probe.

Signed-off-by: Manaf Meethalavalappu Pallikunhi <quic_manafm@quicinc.com>
  • Loading branch information
Manaf Meethalavalappu Pallikunhi authored and intel-lab-lkp committed Dec 13, 2021
1 parent 9652c02 commit e5930a7ed9ae1b121e0dde177184ff74abbf0371
Showing 1 changed file with 4 additions and 6 deletions.
@@ -126,13 +126,16 @@ void power_supply_changed(struct power_supply *psy)
}
EXPORT_SYMBOL_GPL(power_supply_changed);

static int psy_register_cooler(struct device *dev, struct power_supply *psy);
/*
* Notify that power supply was registered after parent finished the probing.
*
* Often power supply is registered from driver's probe function. However
* calling power_supply_changed() directly from power_supply_register()
* would lead to execution of get_property() function provided by the driver
* too early - before the probe ends.
* Also, registering cooling device from the probe will execute the
* get_property() function. So register the cooling device after the probe.
*
* Avoid that by waiting on parent's mutex.
*/
@@ -150,6 +153,7 @@ static void power_supply_deferred_register_work(struct work_struct *work)
}

power_supply_changed(psy);
psy_register_cooler(psy->dev.parent, psy);

if (psy->dev.parent)
mutex_unlock(&psy->dev.parent->mutex);
@@ -1189,10 +1193,6 @@ __power_supply_register(struct device *parent,
if (rc)
goto register_thermal_failed;

rc = psy_register_cooler(psy);
if (rc)
goto register_cooler_failed;

rc = power_supply_create_triggers(psy);
if (rc)
goto create_triggers_failed;
@@ -1222,8 +1222,6 @@ __power_supply_register(struct device *parent,
add_hwmon_sysfs_failed:
power_supply_remove_triggers(psy);
create_triggers_failed:
psy_unregister_cooler(psy);
register_cooler_failed:
psy_unregister_thermal(psy);
register_thermal_failed:
device_del(dev);

0 comments on commit e5930a7

Please sign in to comment.