From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754194AbcDVOd5 (ORCPT ); Fri, 22 Apr 2016 10:33:57 -0400 Received: from www.linutronix.de ([62.245.132.108]:54190 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752473AbcDVOdz (ORCPT ); Fri, 22 Apr 2016 10:33:55 -0400 From: John Ogness To: Mark Brown Cc: linux-kernel@vger.kernel.org Subject: [PATCH] regulator: core: grab supply info before unlocking Date: Fri, 22 Apr 2016 16:33:51 +0200 Message-ID: <87wpnp90hc.fsf@linutronix.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is necessary to check if there is a supply while still holding the regulator lock. Otherwise a theoretical race can occur that someone else can add a supply and then we incorrectly try to unlock that newly added regulator. Signed-off-by: John Ogness --- patch against next-20160421 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 9348c78..629f92f 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -161,10 +161,10 @@ static void regulator_unlock_supply(struct regulator_dev *rdev) struct regulator *supply; while (1) { - mutex_unlock(&rdev->mutex); supply = rdev->supply; + mutex_unlock(&rdev->mutex); - if (!rdev->supply) + if (!supply) return; rdev = supply->rdev; -- 1.7.10.4