From 96784c4520a8270de98f47be0e70586a8474a0d5 Mon Sep 17 00:00:00 2001 From: Rama Aparna Mallavarapu Date: Wed, 10 Oct 2018 14:53:32 -0700 Subject: [PATCH] PM / devfreq: Fix race condition between suspend/resume and governor_store There is a race condition when the event governor_store is being executed from sysfs and the device issues a suspend. The devfreq data structures would become stale when the suspend tries to access them in the middle of the governor_store operation. Fix this issue by taking a lock around suspend and resume operations so that these operations are not concurrent with the other events from sysfs. Change-Id: Ifa0e93915a920cec3e0429966328a1128d61098b Signed-off-by: Rama Aparna Mallavarapu [avajid@codeaurora.org: updated to merge better with upstream changes and removed renaming since done in previous commit] Signed-off-by: Amir Vajid --- drivers/devfreq/devfreq.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index a076b1dac541..55ef66a11266 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -896,8 +896,10 @@ int devfreq_suspend_device(struct devfreq *devfreq) return 0; if (devfreq->governor) { + event_mutex_lock(devfreq); ret = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_SUSPEND, NULL); + event_mutex_unlock(devfreq); if (ret) return ret; } @@ -937,8 +939,10 @@ int devfreq_resume_device(struct devfreq *devfreq) } if (devfreq->governor) { + event_mutex_lock(devfreq); ret = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_RESUME, NULL); + event_mutex_unlock(devfreq); if (ret) return ret; }