From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936491AbdAJLBi (ORCPT ); Tue, 10 Jan 2017 06:01:38 -0500 Received: from hqemgate15.nvidia.com ([216.228.121.64]:11143 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932470AbdAJLBf (ORCPT ); Tue, 10 Jan 2017 06:01:35 -0500 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Mon, 09 Jan 2017 14:57:24 -0800 From: Jon Hunter To: Liam Girdwood , Mark Brown CC: , , Jon Hunter Subject: [PATCH] regulator: core: Don't use regulators as supplies until the parent is bound Date: Tue, 10 Jan 2017 11:01:09 +0000 Message-ID: <1484046069-7893-1-git-send-email-jonathanh@nvidia.com> X-Mailer: git-send-email 2.7.4 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 When regulators are successfully registered, we check to see if the regulator is a supply for any other registered regulator and if so add the new regulator as the supply for the existing regulator(s). Some devices, such as Power Management ICs, may register a series of regulators when probed and there are cases where one of the regulators may fail to register and defer the probing of the parent device. In this case any successfully registered regulators would be unregistered so that they can be re-registered at some time later when the probe is attempted again. However, if one of the regulators that was registered was added as a supply to another registered regulator (that did not belong to the same parent device), then this supply regulator was unregister again because the parent device is probe deferred, then a regulator could be holding an invalid reference to a supply regulator that has been unregistered. This will lead to a system crash if that regulator is then used. Although it would be possible to check when unregistering a regulator if any other regulator in the system is using it as a supply, it still may not be possible to remove it as a supply if this other regulator is in use. Therefore, fix this by preventing any regulator from adding another regulator as a supply if the parent device for the supply regulator has not been bound. This will allow a parent device that is registering regulators to be probe deferred and ensure that none of the regulators it has registered are used as supplies for any other regulator. Signed-off-by: Jon Hunter --- drivers/regulator/core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 04baac9a165b..8adadcdfed1c 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1553,6 +1553,11 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) } } + if (r->dev.parent && !device_is_bound(r->dev.parent)) { + put_device(&r->dev); + return -EPROBE_DEFER; + } + /* Recursively resolve the supply of the supply */ ret = regulator_resolve_supply(r); if (ret < 0) { -- 2.7.4