summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorVenkat Reddy Talla <vreddytalla@nvidia.com>2014-05-20 17:13:10 +0530
committerMandar Padmawar <mpadmawar@nvidia.com>2014-05-28 02:55:30 -0700
commit755b2fb9e20857f7c55a5335f11ce6f90bfa87f6 (patch)
tree26acfba3b84640d5565b4aa200dc68210fceaa35 /drivers/power
parent512e7cb3c0107235f0de3271fa12c32215874974 (diff)
power: extcon:add mutex lock to avoid race condition on usb events
adding mutex lock to avoid race condition while notifying charger cable connected/removed events from USB module. Change-Id: I77708441dd8215533a165c688ba96cf9c10dc8a3 Signed-off-by: Venkat Reddy Talla <vreddytalla@nvidia.com> Reviewed-on: http://git-master/r/412017 (cherry picked from commit 5e6c7197c2e984f8201b59043e714dfff5586df3) Reviewed-on: http://git-master/r/413311 Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com> Tested-by: Laxman Dewangan <ldewangan@nvidia.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/power_supply_extcon.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/drivers/power/power_supply_extcon.c b/drivers/power/power_supply_extcon.c
index 5d5cb1a9efd6..eda9c69014d6 100644
--- a/drivers/power/power_supply_extcon.c
+++ b/drivers/power/power_supply_extcon.c
@@ -30,6 +30,7 @@
#include <linux/power/power_supply_extcon.h>
#include <linux/slab.h>
#include <linux/extcon.h>
+#include <linux/mutex.h>
#define CHARGER_TYPE_DETECTION_DEFAULT_DEBOUNCE_TIME_MS 500
@@ -41,6 +42,7 @@ struct power_supply_extcon {
uint8_t ac_online;
uint8_t usb_online;
struct power_supply_extcon_plat_data *pdata;
+ struct mutex lock;
};
struct power_supply_cables {
@@ -192,11 +194,17 @@ static int psy_extcon_extcon_notifier(struct notifier_block *self,
{
struct power_supply_cables *cable = container_of(self,
struct power_supply_cables, nb);
+ struct power_supply_extcon *psy_extcon = cable->psy_extcon;
+ struct extcon_dev *edev = cable->extcon_dev->edev;
+ mutex_lock(&psy_extcon->lock);
cable->event = event;
- cancel_delayed_work(&cable->extcon_notifier_work);
- schedule_delayed_work(&cable->extcon_notifier_work,
- msecs_to_jiffies(CHARGER_TYPE_DETECTION_DEFAULT_DEBOUNCE_TIME_MS));
+ if (cable->event == 0)
+ power_supply_extcon_remove_cable(psy_extcon, edev);
+ else if (cable->event == 1)
+ power_supply_extcon_attach_cable(psy_extcon, edev);
+
+ mutex_unlock(&psy_extcon->lock);
return NOTIFY_DONE;
}
@@ -248,6 +256,7 @@ static int psy_extcon_probe(struct platform_device *pdev)
psy_extcon->dev = &pdev->dev;
dev_set_drvdata(&pdev->dev, psy_extcon);
+ mutex_init(&psy_extcon->lock);
dev_info(psy_extcon->dev, "Extcon name %s\n", pdata->extcon_name);
@@ -304,7 +313,9 @@ static int psy_extcon_probe(struct platform_device *pdev)
goto econ_err;
}
+ mutex_lock(&psy_extcon->lock);
power_supply_extcon_attach_cable(psy_extcon, psy_extcon->edev);
+ mutex_unlock(&psy_extcon->lock);
dev_info(&pdev->dev, "%s() get success\n", __func__);
return 0;