Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1776587imu; Wed, 21 Nov 2018 01:37:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/W3b2xQH9iMPckfJaYGYYDYd2laEBp0lQTIjGEs/kl0NXHp4GLdp+aZwh3cENufq9inNE3w X-Received: by 2002:a17:902:6bc1:: with SMTP id m1-v6mr6176481plt.34.1542793061970; Wed, 21 Nov 2018 01:37:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542793061; cv=none; d=google.com; s=arc-20160816; b=uDLUPDY+ILt5NNRZZ4zCIyrqsovBHGmexod2jO5PT726cICITdQTbaQLKGSb94XqU6 Z5J6hzPjKecrxjMdvKzi54OL878CkUUtGpcZWV7ldSVFi9WoQ8z38a+ermmQSb1IJ0XX WpN9/plvYA4cXu95RzYVTGa8Ki7MEQa8kdf5ewjs2lxylboGWVtKV69jqUqoLb40BXtu UDxWXMRj/AryGXQUhPSvcPGmBUInxv3ktw2nGQib4QfyIjl0emAIKsbhZkJWObvrOV9t jqafcF9nHOKqx01ZOEj8Kex6Mj7FtL5E9sEhtOwavK3YGlEo1CJA+bkSozZVIyUcb+YI 0odg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:cc:to:from:subject:dkim-signature:dkim-filter; bh=1YImgLiMc3yuuyubE8ao6Cn2JjmAkSSoMqGwuD+ClNo=; b=s0FAkXIPL8BPOyl1eV/F3fu4WwWjzdVTRDGvBtj+qwKDQx87prxx6KNhhfCI2UXmSs a+CWh+VaX2Dx5aSYpOUhgg0qVEZkygK81e/KQ847tTORPXplLD3sqnUY60tl9Ch7H/w0 5GZdjcm3NpzbH8WAN5cIfHBDYv4Hmlb/ypt0MaguaIrE0wP3Y9bA5N8XUwX7zgjeB6Jz dWfDo0sLPVd/iWDzmjShQPG4rvSC58W4QzHCt2ox00RhGt7vyYWlvVuND2FB5Xwpbk4F 3I7j1PV18YszB4M1dK8rkuF7IXtF25+ykbLdPxpsPM1RgAWC2vN/OpC68BzGc4Z8aZ8W GwyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=hnugkDcP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l186si43898279pge.205.2018.11.21.01.37.27; Wed, 21 Nov 2018 01:37:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=hnugkDcP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728587AbeKUUAS (ORCPT + 99 others); Wed, 21 Nov 2018 15:00:18 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:58361 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728467AbeKUUAR (ORCPT ); Wed, 21 Nov 2018 15:00:17 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20181121092633euoutp01e8d8719abd7cd81a70027c48f841b264~pGYH9Aaod2151121511euoutp01- for ; Wed, 21 Nov 2018 09:26:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20181121092633euoutp01e8d8719abd7cd81a70027c48f841b264~pGYH9Aaod2151121511euoutp01- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1542792393; bh=1YImgLiMc3yuuyubE8ao6Cn2JjmAkSSoMqGwuD+ClNo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=hnugkDcP5RFC8pB7h3hJvkQlq2+Jdij3H9bA+/w+Mlv9q3mes8NDmGHUIKVGmLxxV LjXIvRLPd3qYR6rB0Wn9RWA6aB8WN3Q2e48R7+0LaFE2R7ESmqz42WwfWaEGFnhkp3 IFaRGB3LkZZkj71X1yz/owlaXSufxHGT25qo9V6c= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181121092632eucas1p252c235ec446d65fbd62bead9043a7688~pGYHgsCm11842118421eucas1p2O; Wed, 21 Nov 2018 09:26:32 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id FE.42.04441.8C425FB5; Wed, 21 Nov 2018 09:26:32 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20181121092631eucas1p1c153ccafac4a3c8a38439065003644ed~pGYGgLUWz2587825878eucas1p1F; Wed, 21 Nov 2018 09:26:31 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20181121092631eusmtrp1a08200c80427c5622026f71562ec054f~pGYGRy5PM2822228222eusmtrp1_; Wed, 21 Nov 2018 09:26:31 +0000 (GMT) X-AuditID: cbfec7f2-5e3ff70000001159-b2-5bf524c8c8b0 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 69.E6.04284.7C425FB5; Wed, 21 Nov 2018 09:26:31 +0000 (GMT) Received: from [106.116.147.30] (unknown [106.116.147.30]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20181121092631eusmtip21130cd043e5c6db44edef4c20d0edec2~pGYF7ru8J0277202772eusmtip2s; Wed, 21 Nov 2018 09:26:31 +0000 (GMT) Subject: Re: [PATCH] regulator: wm8994: Don't use devres for enable GPIOs From: Marek Szyprowski To: Charles Keepax , broonie@kernel.org Cc: linus.walleij@linaro.org, lgirdwood@gmail.com, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com Message-ID: Date: Wed, 21 Nov 2018 10:26:30 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: Content-Transfer-Encoding: 8bit Content-Language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKKsWRmVeSWpSXmKPExsWy7djPc7onVL5GG7xarm0x9eETNosrrZsY Lb5d6WCymPJnOZPF5V1z2Cw+v9/P6sDmsXPWXXaPTas62TzuXNvD5jF9zn9Gj8+b5AJYo7hs UlJzMstSi/TtErgyvuy9wFSwwrxiw/TdrA2MT/S6GDk5JARMJK6+X8fSxcjFISSwglHiwMeH zBDOF0aJw+0v2ECqhAQ+M0osnpIG03H2/FVGiKLljBIv31yAct4zSnx48RWsQ1jAU+LGtoOM IDabgKFE19susLiIgJvE6/trmEFsZoECiW+9T8BsXgE7ifl/vrOC2CwCqhJfG76CxUUFYiSO rbzBCFEjKHFy5hMWEJtTwF7iz4fn7BBz5CWat86GmikucevJfCaQgyQEVrFLLNi8FyjBAeS4 SCw8qgnxgbDEq+Nb2CFsGYnTk3tYIOqbGSXaZ8xih3B6GCW2ztnBBlFlLXH4+EVWkEHMApoS 63fpQ4QdJW7N28IIMZ9P4sZbQYgb+CQmbZsOtZZXoqNNCKJaTWLW8XVwaw9euMQ8gVFpFpLP ZiH5ZhaSb2Yh7F3AyLKKUTy1tDg3PbXYMC+1XK84Mbe4NC9dLzk/dxMjMPGc/nf80w7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r7HizVTbG33Xvv/A2ZtHlDiv+kgHs7bf7fEhNyOMN/TfbS4rO9vJs6 g27FCgYf8vspnnXgr8QKg65aFbEX63mW8Nw5cW5VdmWh/LJXCybVchQ6ySuxFGckGmoxFxUn AgAr5WqHzAIAAA== X-CMS-MailID: 20181121092631eucas1p1c153ccafac4a3c8a38439065003644ed X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20181120170248epcas1p2a93ec9ff7f74ad4908166590ed548386 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181120170248epcas1p2a93ec9ff7f74ad4908166590ed548386 References: <20181120170152.24652-1-ckeepax@opensource.cirrus.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2018-11-20 18:25, Marek Szyprowski wrote: > Hi Charles, > > On 2018-11-20 18:01, Charles Keepax wrote: >> We need to manage the life time of the enable GPIO against the regulator >> device but the OF node lives on the parent MFD device. As such we can't >> use the devm functions which assume the same device will be used for >> both. >> >> Reported-by: Marek Szyprowski >> Signed-off-by: Charles Keepax >> --- >> >> This patch is only build tested so it would be good to get a >> tested by from Marek before applying. > Sadly it looks that it is not enough. The issue is still there: > > wm8994 4-001a: Failed to get supply 'DBVDD1': -517 > wm8994 4-001a: Failed to get supplies: -517 > ------------[ cut here ]------------ > WARNING: CPU: 0 PID: 1 at drivers/gpio/gpiolib.c:2421 > regulator_ena_gpio_free+0x70/0xa0 > Modules linked in: > CPU: 0 PID: 1 Comm: swapper/0 Not tainted > 4.20.0-rc3-next-20181120-00001-g330f37c7fb0c #5090 > Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) > [] (unwind_backtrace) from [] (show_stack+0x10/0x14) > [] (show_stack) from [] (dump_stack+0x90/0xc8) > [] (dump_stack) from [] (__warn+0xf8/0x124) > [] (__warn) from [] (warn_slowpath_null+0x40/0x48) > [] (warn_slowpath_null) from [] > (regulator_ena_gpio_free+0x70/0xa0) > [] (regulator_ena_gpio_free) from [] > (regulator_unregister+0x134/0x17c) > [] (regulator_unregister) from [] > (release_nodes+0x164/0x1dc) > [] (release_nodes) from [] > (device_release_driver_internal+0x18c/0x21c) > [] (device_release_driver_internal) from [] > (bus_remove_device+0xdc/0x12c) > [] (bus_remove_device) from [] (device_del+0x108/0x2e0) > [] (device_del) from [] (platform_device_del+0x20/0x8c) > [] (platform_device_del) from [] > (platform_device_unregister+0xc/0x18) > [] (platform_device_unregister) from [] > (mfd_remove_devices_fn+0x58/0x64) > [] (mfd_remove_devices_fn) from [] > (device_for_each_child_reverse+0x34/0x74) > [] (device_for_each_child_reverse) from [] > (mfd_remove_devices+0x20/0x30) > [] (mfd_remove_devices) from [] > (wm8994_i2c_probe+0x2dc/0x8d0) > [] (wm8994_i2c_probe) from [] > (i2c_device_probe+0x234/0x2b0) > [] (i2c_device_probe) from [] (really_probe+0x224/0x3f4) > [] (really_probe) from [] > (driver_probe_device+0x70/0x1c4) > [] (driver_probe_device) from [] > (__driver_attach+0x120/0x144) > [] (__driver_attach) from [] > (bus_for_each_dev+0x58/0x7c) > [] (bus_for_each_dev) from [] > (bus_add_driver+0x174/0x250) > [] (bus_add_driver) from [] (driver_register+0x7c/0x110) > [] (driver_register) from [] > (i2c_register_driver+0x38/0xa8) > [] (i2c_register_driver) from [] > (do_one_initcall+0x80/0x408) > [] (do_one_initcall) from [] > (kernel_init_freeable+0x3a0/0x4fc) > [] (kernel_init_freeable) from [] > (kernel_init+0x8/0x118) > [] (kernel_init) from [] (ret_from_fork+0x14/0x20) > Exception stack(0xef0e3fb0 to 0xef0e3ff8) > 3fa0:                                     00000000 00000000 00000000 > 00000000 > 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 > 00000000 > 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000 > irq event stamp: 176913 > hardirqs last  enabled at (176921): [] console_unlock+0x460/0x6ec > hardirqs last disabled at (176940): [] console_unlock+0xb8/0x6ec > softirqs last  enabled at (176956): [] __do_softirq+0x3a4/0x66c > softirqs last disabled at (176967): [] irq_exit+0x140/0x168 > > I will check more tomorrow. I've checked a bit more and it looks that the issue is caused by gpiod_put() in regulator_ena_gpio_free(). I've removed gpiod_put() call from wm8994_ldo_remove(), switched to regulator_register() in wm8994_ldo_probe() and added regulator_unregister() in wm8994_ldo_remove(). This way the warning is gone. If there is any other, simpler way to fix it, let me know. When regulator_register() fails, gpiod will be freed only in some cases, depending what caused failure. It looks that this needs some clarification... > >> Thanks, >> Charles >> >> drivers/regulator/wm8994-regulator.c | 28 +++++++++++++++++++++++----- >> 1 file changed, 23 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c >> index d7fec533c403..f2592c30d0ca 100644 >> --- a/drivers/regulator/wm8994-regulator.c >> +++ b/drivers/regulator/wm8994-regulator.c >> @@ -31,6 +31,7 @@ struct wm8994_ldo { >> struct wm8994 *wm8994; >> struct regulator_consumer_supply supply; >> struct regulator_init_data init_data; >> + struct gpio_desc *ena_gpiod; >> }; >> >> #define WM8994_LDO1_MAX_SELECTOR 0x7 >> @@ -147,14 +148,19 @@ static int wm8994_ldo_probe(struct platform_device *pdev) >> config.regmap = wm8994->regmap; >> config.init_data = &ldo->init_data; >> >> - /* Look up LDO enable GPIO from the parent device node */ >> - gpiod = devm_gpiod_get_optional(pdev->dev.parent, >> - id ? "wlf,ldo2ena" : "wlf,ldo1ena", >> - GPIOD_OUT_LOW | >> - GPIOD_FLAGS_BIT_NONEXCLUSIVE); >> + /* >> + * Look up LDO enable GPIO from the parent device node, we can't >> + * use devm because it assumes the device we want to allocate >> + * against is the same one that holds the OF node >> + */ >> + gpiod = gpiod_get_optional(pdev->dev.parent, >> + id ? "wlf,ldo2ena" : "wlf,ldo1ena", >> + GPIOD_OUT_LOW | >> + GPIOD_FLAGS_BIT_NONEXCLUSIVE); >> if (IS_ERR(gpiod)) >> return PTR_ERR(gpiod); >> config.ena_gpiod = gpiod; >> + ldo->ena_gpiod = gpiod; >> >> /* Use default constraints if none set up */ >> if (!pdata || !pdata->ldo[id].init_data || wm8994->dev->of_node) { >> @@ -184,11 +190,23 @@ static int wm8994_ldo_probe(struct platform_device *pdev) >> return 0; >> >> err: >> + gpiod_put(gpiod); >> return ret; >> } >> >> +static int wm8994_ldo_remove(struct platform_device *pdev) >> +{ >> + struct wm8994_ldo *ldo = platform_get_drvdata(pdev); >> + >> + if (ldo->ena_gpiod) >> + gpiod_put(ldo->ena_gpiod); >> + >> + return 0; >> +} >> + >> static struct platform_driver wm8994_ldo_driver = { >> .probe = wm8994_ldo_probe, >> + .remove = wm8994_ldo_remove, >> .driver = { >> .name = "wm8994-ldo", >> }, > Best regards Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland