Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: smb347-charger: Replace mutex with IRQ disable/enable

Let's simply disable/enable IRQ rather than use a mutex that protects from
racing with the interrupt handler. The result of this patch is that it's a
bit easier now to follow the driver's code.

Tested-by: David Heidelberg <david@ixit.cz>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Dmitry Osipenko and committed by
Sebastian Reichel
99298de5 db14d3b4

+20 -18
+20 -18
drivers/power/supply/smb347-charger.c
··· 16 16 #include <linux/init.h> 17 17 #include <linux/interrupt.h> 18 18 #include <linux/i2c.h> 19 - #include <linux/mutex.h> 20 19 #include <linux/power_supply.h> 21 20 #include <linux/power/smb347-charger.h> 22 21 #include <linux/regmap.h> ··· 121 122 122 123 /** 123 124 * struct smb347_charger - smb347 charger instance 124 - * @lock: protects concurrent access to online variables 125 125 * @dev: pointer to device 126 126 * @regmap: pointer to driver regmap 127 127 * @mains: power_supply instance for AC/DC power ··· 132 134 * @pdata: pointer to platform data 133 135 */ 134 136 struct smb347_charger { 135 - struct mutex lock; 136 137 struct device *dev; 137 138 struct regmap *regmap; 138 139 struct power_supply *mains; ··· 240 243 if (smb->pdata->use_usb) 241 244 usb = !(val & IRQSTAT_E_USBIN_UV_STAT); 242 245 243 - mutex_lock(&smb->lock); 244 246 ret = smb->mains_online != dc || smb->usb_online != usb; 245 247 smb->mains_online = dc; 246 248 smb->usb_online = usb; 247 - mutex_unlock(&smb->lock); 248 249 249 250 return ret; 250 251 } ··· 258 263 */ 259 264 static bool smb347_is_ps_online(struct smb347_charger *smb) 260 265 { 261 - bool ret; 262 - 263 - mutex_lock(&smb->lock); 264 - ret = smb->usb_online || smb->mains_online; 265 - mutex_unlock(&smb->lock); 266 - 267 - return ret; 266 + return smb->usb_online || smb->mains_online; 268 267 } 269 268 270 269 /** ··· 292 303 return 0; 293 304 } 294 305 295 - mutex_lock(&smb->lock); 296 306 if (smb->charging_enabled != enable) { 297 307 ret = regmap_update_bits(smb->regmap, CMD_A, CMD_A_CHG_ENABLED, 298 308 enable ? CMD_A_CHG_ENABLED : 0); 299 309 if (!ret) 300 310 smb->charging_enabled = enable; 301 311 } 302 - mutex_unlock(&smb->lock); 312 + 303 313 return ret; 304 314 } 305 315 ··· 983 995 return status; 984 996 } 985 997 986 - static int smb347_get_property(struct power_supply *psy, 987 - enum power_supply_property prop, 988 - union power_supply_propval *val) 998 + static int smb347_get_property_locked(struct power_supply *psy, 999 + enum power_supply_property prop, 1000 + union power_supply_propval *val) 989 1001 { 990 1002 struct smb347_charger *smb = power_supply_get_drvdata(psy); 991 1003 int ret; ··· 1050 1062 } 1051 1063 1052 1064 return 0; 1065 + } 1066 + 1067 + static int smb347_get_property(struct power_supply *psy, 1068 + enum power_supply_property prop, 1069 + union power_supply_propval *val) 1070 + { 1071 + struct smb347_charger *smb = power_supply_get_drvdata(psy); 1072 + struct i2c_client *client = to_i2c_client(smb->dev); 1073 + int ret; 1074 + 1075 + disable_irq(client->irq); 1076 + ret = smb347_get_property_locked(psy, prop, val); 1077 + enable_irq(client->irq); 1078 + 1079 + return ret; 1053 1080 } 1054 1081 1055 1082 static enum power_supply_property smb347_properties[] = { ··· 1276 1273 1277 1274 i2c_set_clientdata(client, smb); 1278 1275 1279 - mutex_init(&smb->lock); 1280 1276 smb->dev = &client->dev; 1281 1277 smb->id = id->driver_data; 1282 1278