Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751700AbdDCF2x (ORCPT ); Mon, 3 Apr 2017 01:28:53 -0400 Received: from cdptpa-outbound-snat.email.rr.com ([107.14.166.227]:45145 "EHLO cdptpa-oedge-vip.email.rr.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751058AbdDCF2v (ORCPT ); Mon, 3 Apr 2017 01:28:51 -0400 From: Jeremy Linton To: linux-kernel@vger.kernel.org Cc: broonie@kernel.org, lgirdwood@gmail.com, puck.chen@hisilicon.com, lee.jones@linaro.org, Jeremy Linton Subject: [PATCH v2 2/2] regulator: hi655x: Bump parent pmic module use count Date: Mon, 3 Apr 2017 00:28:43 -0500 Message-Id: <20170403052843.12711-3-lintonrjeremy@gmail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170403052843.12711-1-lintonrjeremy@gmail.com> References: <20170403052843.12711-1-lintonrjeremy@gmail.com> X-RR-Connecting-IP: 107.14.168.88:25 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3038 Lines: 91 The hi655x-regulator driver depends on the parent pmic/mfc device driver but doesn't increase its use count. This results in system crashes if the parent module is unloaded while the regulators are still in use. Add explicit module get/put calls to keep the parent from being unloaded. example crash: Unable to handle kernel paging request at virtual address ffff800078fc5c78 ... [] 0xffff800078fc5c78 [] regulator_set_voltage_sel_regmap+0x50/0x98 [] _regulator_do_set_voltage+0x4c8/0x7c0 [] regulator_set_voltage_unlocked+0xc4/0x258 [] regulator_set_voltage+0x3c/0x70 [] mmc_regulator_set_ocr+0x48/0x100 [mmc_core] [] dw_mci_set_ios+0x1e8/0x280 [dw_mmc] [] mmc_set_initial_state+0x84/0xf8 [mmc_core] [] mmc_power_up.part.13+0x5c/0x1f8 [mmc_core] [] mmc_rescan+0x270/0x3b0 [mmc_core] [] process_one_work+0x264/0x7c0 [] worker_thread+0x54/0x430 [] kthread+0x104/0x130 [] ret_from_fork+0x10/0x50 Signed-off-by: Jeremy Linton --- drivers/regulator/hi655x-regulator.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/hi655x-regulator.c b/drivers/regulator/hi655x-regulator.c index 36ae54b..336aaed 100644 --- a/drivers/regulator/hi655x-regulator.c +++ b/drivers/regulator/hi655x-regulator.c @@ -185,16 +185,29 @@ static int hi655x_regulator_probe(struct platform_device *pdev) struct hi655x_pmic *pmic; struct regulator_config config = { }; struct regulator_dev *rdev; + struct device *parent = pdev->dev.parent; - pmic = dev_get_drvdata(pdev->dev.parent); + if (!parent) { + dev_err(&pdev->dev, "no regulator parent node\n"); + return -ENODEV; + } + + pmic = dev_get_drvdata(parent); if (!pmic) { dev_err(&pdev->dev, "no pmic in the regulator parent node\n"); return -ENODEV; } + if (!try_module_get(parent->driver->owner)) { + dev_err(&pdev->dev, "unable to get parent module\n"); + return -ENODEV; + } + regulator = devm_kzalloc(&pdev->dev, sizeof(*regulator), GFP_KERNEL); - if (!regulator) + if (!regulator) { + module_put(parent->driver->owner); return -ENOMEM; + } platform_set_drvdata(pdev, regulator); @@ -214,6 +227,14 @@ static int hi655x_regulator_probe(struct platform_device *pdev) return 0; } +static int hi655x_regulator_remove(struct platform_device *pdev) +{ + struct device *parent = pdev->dev.parent; + + module_put(parent->driver->owner); + return 0; +} + static const struct platform_device_id hi655x_regulator_table[] = { { .name = "hi655x-regulator" }, {}, @@ -226,6 +247,7 @@ static struct platform_driver hi655x_regulator_driver = { .name = "hi655x-regulator", }, .probe = hi655x_regulator_probe, + .remove = hi655x_regulator_remove }; module_platform_driver(hi655x_regulator_driver); -- 2.10.2