From: Marek Vasut <marex@denx.de>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: linux-pm@vger.kernel.org, Peng Fan <peng.fan@nxp.com>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Jindong Yue <jindong.yue@nxp.com>,
Marco Felsch <m.felsch@pengutronix.de>,
NXP Linux Team <linux-imx@nxp.com>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Ulf Hansson <ulf.hansson@linaro.org>,
Fabio Estevam <festevam@gmail.com>,
linux-arm-kernel@lists.infradead.org,
Lucas Stach <l.stach@pengutronix.de>
Subject: Re: [PATCH v2] pmdomain: imx8m-blk-ctrl: imx8mp-blk-ctrl: Error out if domains are missing in DT
Date: Fri, 19 Jan 2024 11:58:54 +0100 [thread overview]
Message-ID: <73886bd9-e2ab-40ef-a1a0-a82222d97201@denx.de> (raw)
In-Reply-To: <asamq53uiegrgwo5c25sjn7n47bsv6xa3ybkueuhb2d42m66ze@t6ujdompm2gs>
On 1/19/24 08:42, Uwe Kleine-König wrote:
> On Fri, Jan 19, 2024 at 02:47:41AM +0100, Marek Vasut wrote:
>> This driver assumes that domain->power_dev is non-NULL in its suspend/resume
>> path. The assumption is valid, since all the devices that are being looked up
>> here should be described in DT. In case they are not described in DT, beause
>> the DT is faulty, suspend/resume attempt would trigger NULL pointer dereference.
>> To avoid this failure, check whether the power_dev assignment is not NULL right
>> away in probe callback and fail early if it is.
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> ---
>> Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
>> Cc: Fabio Estevam <festevam@gmail.com>
>> Cc: Jindong Yue <jindong.yue@nxp.com>
>> Cc: Lucas Stach <l.stach@pengutronix.de>
>> Cc: Marco Felsch <m.felsch@pengutronix.de>
>> Cc: NXP Linux Team <linux-imx@nxp.com>
>> Cc: Peng Fan <peng.fan@nxp.com>
>> Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
>> Cc: Sascha Hauer <s.hauer@pengutronix.de>
>> Cc: Shawn Guo <shawnguo@kernel.org>
>> Cc: Ulf Hansson <ulf.hansson@linaro.org>
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: linux-pm@vger.kernel.org
>> ---
>> V2: Add extra check for domain being NULL (thanks Peng)
>> ---
>> drivers/pmdomain/imx/imx8m-blk-ctrl.c | 9 ++++++---
>> drivers/pmdomain/imx/imx8mp-blk-ctrl.c | 9 ++++++---
>> 2 files changed, 12 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/pmdomain/imx/imx8m-blk-ctrl.c b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
>> index 1341a707f61bc..ca942d7929c2b 100644
>> --- a/drivers/pmdomain/imx/imx8m-blk-ctrl.c
>> +++ b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
>> @@ -258,11 +258,14 @@ static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
>>
>> domain->power_dev =
>> dev_pm_domain_attach_by_name(dev, data->gpc_name);
>> - if (IS_ERR(domain->power_dev)) {
>> - dev_err_probe(dev, PTR_ERR(domain->power_dev),
>> + if (IS_ERR_OR_NULL(domain->power_dev)) {
>> + if (!domain->power_dev)
>> + ret = -ENODEV;
>> + else
>> + ret = PTR_ERR(domain->power_dev);
>> + dev_err_probe(dev, ret,
>> "failed to attach power domain \"%s\"\n",
>> data->gpc_name);
>> - ret = PTR_ERR(domain->power_dev);
>> goto cleanup_pds;
>> }
>>
>> diff --git a/drivers/pmdomain/imx/imx8mp-blk-ctrl.c b/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
>> index e3203eb6a0229..e488cf79b8007 100644
>> --- a/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
>> +++ b/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
>> @@ -687,11 +687,14 @@ static int imx8mp_blk_ctrl_probe(struct platform_device *pdev)
>>
>> domain->power_dev =
>> dev_pm_domain_attach_by_name(dev, data->gpc_name);
>> - if (IS_ERR(domain->power_dev)) {
>> - dev_err_probe(dev, PTR_ERR(domain->power_dev),
>> + if (IS_ERR_OR_NULL(domain->power_dev)) {
>> + if (!domain->power_dev)
>> + ret = -ENODEV;
>> + else
>> + ret = PTR_ERR(domain->power_dev);
>> + dev_err_probe(dev, ret,
>> "failed to attach power domain %s\n",
>> data->gpc_name);
>> - ret = PTR_ERR(domain->power_dev);
>
> This could be made a bit more compact using:
>
> domain->power_dev =
> dev_pm_domain_attach_by_name(dev, data->gpc_name) ||
> ERR_PTR(-ENODEV);
> if (IS_ERR(domain->power_dev)) {
> ret = PTR_ERR(domain->power_dev);
> ...
>
> I'm unsure though if this is human friendly enough?!
I think it is only more cryptic and doesn't improve readability.
> Having said that I wonder about dev_pm_domain_attach_by_name(). IMHO if
> NULL is an error case it and other errors are signaled by error
> pointers, there is something to fix there.
I don't think dev_pm_domain_attach_by_name() returning NULL is an error
-- the domain may be missing from DT and that is legitimate use case I
think.
But not here, where all the domains should be described in DT because
the driver makes assumptions about their presence in the suspend/resume
part, and because the DT should fully describe the domains of this
hardware anyway, so we better catch such DT issues.
next prev parent reply other threads:[~2024-01-19 11:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-19 1:47 [PATCH v2] pmdomain: imx8m-blk-ctrl: imx8mp-blk-ctrl: Error out if domains are missing in DT Marek Vasut
2024-01-19 1:54 ` Peng Fan
2024-01-19 7:42 ` Uwe Kleine-König
2024-01-19 10:58 ` Marek Vasut [this message]
2024-01-22 15:21 ` Ulf Hansson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=73886bd9-e2ab-40ef-a1a0-a82222d97201@denx.de \
--to=marex@denx.de \
--cc=festevam@gmail.com \
--cc=jindong.yue@nxp.com \
--cc=kernel@pengutronix.de \
--cc=l.stach@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-pm@vger.kernel.org \
--cc=m.felsch@pengutronix.de \
--cc=peng.fan@nxp.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
--cc=ulf.hansson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox