FROMLIST: 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>

Bug: 211709650
Link: https://lore.kernel.org/linux-pm/1640162489-7847-1-git-send-email-quic_manafm@quicinc.com/
Change-Id: Id1aa63da9c4e43272c78b50b8b61a92b2d4f617d
Signed-off-by: Manaf Meethalavalappu Pallikunhi <quic_manafm@quicinc.com>
This commit is contained in:
Manaf Meethalavalappu Pallikunhi
2021-12-13 15:51:16 +05:30
committed by Steve Muckle
parent fc64efcd06
commit b90fe5ef8f

View File

@@ -132,6 +132,7 @@ void power_supply_changed(struct power_supply *psy)
} }
EXPORT_SYMBOL_GPL(power_supply_changed); EXPORT_SYMBOL_GPL(power_supply_changed);
static int psy_register_cooler(struct power_supply *psy);
/* /*
* Notify that power supply was registered after parent finished the probing. * Notify that power supply was registered after parent finished the probing.
* *
@@ -139,6 +140,8 @@ EXPORT_SYMBOL_GPL(power_supply_changed);
* calling power_supply_changed() directly from power_supply_register() * calling power_supply_changed() directly from power_supply_register()
* would lead to execution of get_property() function provided by the driver * would lead to execution of get_property() function provided by the driver
* too early - before the probe ends. * 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. * Avoid that by waiting on parent's mutex.
*/ */
@@ -156,6 +159,7 @@ static void power_supply_deferred_register_work(struct work_struct *work)
} }
power_supply_changed(psy); power_supply_changed(psy);
psy_register_cooler(psy);
if (psy->dev.parent) if (psy->dev.parent)
mutex_unlock(&psy->dev.parent->mutex); mutex_unlock(&psy->dev.parent->mutex);
@@ -1238,10 +1242,6 @@ __power_supply_register(struct device *parent,
if (rc) if (rc)
goto register_thermal_failed; goto register_thermal_failed;
rc = psy_register_cooler(psy);
if (rc)
goto register_cooler_failed;
rc = power_supply_create_triggers(psy); rc = power_supply_create_triggers(psy);
if (rc) if (rc)
goto create_triggers_failed; goto create_triggers_failed;
@@ -1271,8 +1271,6 @@ __power_supply_register(struct device *parent,
add_hwmon_sysfs_failed: add_hwmon_sysfs_failed:
power_supply_remove_triggers(psy); power_supply_remove_triggers(psy);
create_triggers_failed: create_triggers_failed:
psy_unregister_cooler(psy);
register_cooler_failed:
psy_unregister_thermal(psy); psy_unregister_thermal(psy);
register_thermal_failed: register_thermal_failed:
device_del(dev); device_del(dev);