File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change 1414#include <linux/types.h>
1515#include <linux/init.h>
1616#include <linux/slab.h>
17+ #include <linux/delay.h>
1718#include <linux/device.h>
1819#include <linux/notifier.h>
1920#include <linux/err.h>
@@ -140,8 +141,13 @@ static void power_supply_deferred_register_work(struct work_struct *work)
140141 struct power_supply * psy = container_of (work , struct power_supply ,
141142 deferred_register_work .work );
142143
143- if (psy -> dev .parent )
144- mutex_lock (& psy -> dev .parent -> mutex );
144+ if (psy -> dev .parent ) {
145+ while (!mutex_trylock (& psy -> dev .parent -> mutex )) {
146+ if (psy -> removing )
147+ return ;
148+ msleep (10 );
149+ }
150+ }
145151
146152 power_supply_changed (psy );
147153
@@ -1082,6 +1088,7 @@ EXPORT_SYMBOL_GPL(devm_power_supply_register_no_ws);
10821088void power_supply_unregister (struct power_supply * psy )
10831089{
10841090 WARN_ON (atomic_dec_return (& psy -> use_cnt ));
1091+ psy -> removing = true;
10851092 cancel_work_sync (& psy -> changed_work );
10861093 cancel_delayed_work_sync (& psy -> deferred_register_work );
10871094 sysfs_remove_link (& psy -> dev .kobj , "powers" );
Original file line number Diff line number Diff line change @@ -269,6 +269,7 @@ struct power_supply {
269269 spinlock_t changed_lock ;
270270 bool changed ;
271271 bool initialized ;
272+ bool removing ;
272273 atomic_t use_cnt ;
273274#ifdef CONFIG_THERMAL
274275 struct thermal_zone_device * tzd ;
You can’t perform that action at this time.
0 commit comments