From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933260AbdBVSUt (ORCPT ); Wed, 22 Feb 2017 13:20:49 -0500 Received: from h1.radempa.de ([176.9.142.194]:34783 "EHLO mail.cosmopool.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932394AbdBVSUO (ORCPT ); Wed, 22 Feb 2017 13:20:14 -0500 X-Greylist: delayed 1800 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Feb 2017 13:20:13 EST From: Harald Geyer To: Liam Girdwood , Mark Brown , Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, Harald Geyer Subject: [PATCH 2/2] regulator: core: Fix race on multiple calls to regulator_disable_deferred() Date: Wed, 22 Feb 2017 17:41:25 +0000 Message-Id: <1487785285-3567-2-git-send-email-harald@ccbib.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1487785285-3567-1-git-send-email-harald@ccbib.org> References: <1487785285-3567-1-git-send-email-harald@ccbib.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The old code has two issues: 1) When multiple consumers call regulator_disable_deferred() close in time, always the delay requested in the first call is used. 2) When a consumer calls regulator_disable_deferred(), but enables and calls regulator_disable_deferred() again before the timer fires, the timer isn't reset. Both issues can cause the regulator to get disabled early. Signed-off-by: Harald Geyer --- drivers/regulator/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index cc68604..ce4923b 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2449,8 +2449,8 @@ int regulator_disable_deferred(struct regulator *regulator, int ms) rdev->deferred_disables++; mutex_unlock(&rdev->mutex); - queue_delayed_work(system_power_efficient_wq, &rdev->disable_work, - msecs_to_jiffies(ms)); + mod_fwd_delayed_work(system_power_efficient_wq, &rdev->disable_work, + msecs_to_jiffies(ms)); return 0; } EXPORT_SYMBOL_GPL(regulator_disable_deferred); -- 2.1.4