Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753877AbcDUQNd (ORCPT ); Thu, 21 Apr 2016 12:13:33 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:18901 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753739AbcDUQMM (ORCPT ); Thu, 21 Apr 2016 12:12:12 -0400 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Thu, 21 Apr 2016 09:12:02 -0700 From: Jon Hunter To: Liam Girdwood , Mark Brown CC: , , Thierry Reding , Jon Hunter Subject: [PATCH 2/5] regulator: core: Clear the supply pointer if enabling fails Date: Thu, 21 Apr 2016 17:11:58 +0100 Message-ID: <1461255121-5245-3-git-send-email-jonathanh@nvidia.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1461255121-5245-1-git-send-email-jonathanh@nvidia.com> References: <1461255121-5245-1-git-send-email-jonathanh@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1055 Lines: 28 During the resolution of a regulator's supply, we may attempt to enable the supply if the regulator itself is already enabled. If enabling the supply fails, then we will call _regulator_put() for the supply. However, the pointer to the supply has not been cleared for the regulator and this will cause a crash if we then unregister the regulator and attempt to call regulator_put() a second time for the supply. Fix this by clearing the supply pointer if enabling the supply after fails when resolving the supply for a regulator. Signed-off-by: Jon Hunter --- drivers/regulator/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index a0b52ef11c30..39d05fcc07e9 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1545,6 +1545,7 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) ret = regulator_enable(rdev->supply); if (ret < 0) { _regulator_put(rdev->supply); + rdev->supply = NULL; return ret; } } -- 2.1.4