diff mbox series

pmdomain: imx8m-blk-ctrl: imx8mp-blk-ctrl: Error out if domains are missing in DT

Message ID 20240118191235.145549-1-marex@denx.de
State New
Headers show
Series pmdomain: imx8m-blk-ctrl: imx8mp-blk-ctrl: Error out if domains are missing in DT | expand

Commit Message

Marek Vasut Jan. 18, 2024, 7:12 p.m. UTC
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
---
 drivers/pmdomain/imx/imx8m-blk-ctrl.c  | 2 +-
 drivers/pmdomain/imx/imx8mp-blk-ctrl.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Peng Fan Jan. 19, 2024, 1:31 a.m. UTC | #1
> Subject: [PATCH] pmdomain: imx8m-blk-ctrl: imx8mp-blk-ctrl: Error out if
> domains are missing in DT
> 
> 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
> ---
>  drivers/pmdomain/imx/imx8m-blk-ctrl.c  | 2 +-
> drivers/pmdomain/imx/imx8mp-blk-ctrl.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pmdomain/imx/imx8m-blk-ctrl.c
> b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
> index 1341a707f61bc..1b83c9c2d5b77 100644
> --- a/drivers/pmdomain/imx/imx8m-blk-ctrl.c
> +++ b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
> @@ -258,7 +258,7 @@ 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)) {
> +		if (IS_ERR_OR_NULL(domain->power_dev)) {

The ret = PTR_ERR(domain->power_dev) will make the probe return
success if domain->power_dev is NULL.

Regards,
Peng.

>  			dev_err_probe(dev, PTR_ERR(domain->power_dev),
>  				      "failed to attach power domain
> \"%s\"\n",
>  				      data->gpc_name);
> diff --git a/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
> b/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
> index e3203eb6a0229..3d6888afb416c 100644
> --- a/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
> +++ b/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
> @@ -687,7 +687,7 @@ 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)) {
> +		if (IS_ERR_OR_NULL(domain->power_dev)) {
>  			dev_err_probe(dev, PTR_ERR(domain->power_dev),
>  				      "failed to attach power domain %s\n",
>  				      data->gpc_name);
> --
> 2.43.0
diff mbox series

Patch

diff --git a/drivers/pmdomain/imx/imx8m-blk-ctrl.c b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
index 1341a707f61bc..1b83c9c2d5b77 100644
--- a/drivers/pmdomain/imx/imx8m-blk-ctrl.c
+++ b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
@@ -258,7 +258,7 @@  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)) {
+		if (IS_ERR_OR_NULL(domain->power_dev)) {
 			dev_err_probe(dev, PTR_ERR(domain->power_dev),
 				      "failed to attach power domain \"%s\"\n",
 				      data->gpc_name);
diff --git a/drivers/pmdomain/imx/imx8mp-blk-ctrl.c b/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
index e3203eb6a0229..3d6888afb416c 100644
--- a/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
+++ b/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
@@ -687,7 +687,7 @@  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)) {
+		if (IS_ERR_OR_NULL(domain->power_dev)) {
 			dev_err_probe(dev, PTR_ERR(domain->power_dev),
 				      "failed to attach power domain %s\n",
 				      data->gpc_name);