Message ID | 20221215034800.275502-1-marex@denx.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/2] soc: imx: imx8m-blk-ctrl: Fix NULL pointer dereference | expand |
On Thu, Dec 15, 2022 at 04:47:59AM +0100, Marek Vasut wrote: > Check domain->power_dev = dev_pm_domain_attach_by_name() return value using > IS_ERR_OR_NULL() instead of plain IS_ERR(), and fail if domain->power_dev is > either error or NULL. > > In case a power domain attached by dev_pm_domain_attach_by_name() is not > described in DT, dev_pm_domain_attach_by_name() returns NULL, which is > then used a few lines below in dev_set_name(domain->power_dev, ...);, > which leads to NULL pointer dereference. This is no longer the case since b64b46fbaa1da ("Revert "soc: imx: imx8m-blk-ctrl: set power device name"") > > Fixes: 2684ac05a8c4 ("soc: imx: add i.MX8M blk-ctrl driver") > Signed-off-by: Marek Vasut <marex@denx.de> > --- > Cc: Adam Ford <aford173@gmail.com> > Cc: Benjamin Gaignard <benjamin.gaignard@collabora.com> > Cc: Fabio Estevam <festevam@gmail.com> > Cc: Lucas Stach <l.stach@pengutronix.de> > Cc: Marco Felsch <m.felsch@pengutronix.de> > Cc: Marek Vasut <marex@denx.de> > Cc: NXP Linux Team <linux-imx@nxp.com> > Cc: Paul Elder <paul.elder@ideasonboard.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> > To: linux-arm-kernel@lists.infradead.org > --- > drivers/soc/imx/imx8m-blk-ctrl.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/soc/imx/imx8m-blk-ctrl.c b/drivers/soc/imx/imx8m-blk-ctrl.c > index ddcf6be3d8b4a..2fbc8e6b2644b 100644 > --- a/drivers/soc/imx/imx8m-blk-ctrl.c > +++ b/drivers/soc/imx/imx8m-blk-ctrl.c > @@ -256,7 +256,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); Calling dev_err_probe() with an error value of 0 looks wrong. Jumping to the error path with an error value of 0 also looks wrong. Sascha
Hi Marek, On 22-12-15, Marek Vasut wrote: > Check domain->power_dev = dev_pm_domain_attach_by_name() return value using > IS_ERR_OR_NULL() instead of plain IS_ERR(), and fail if domain->power_dev is > either error or NULL. > > In case a power domain attached by dev_pm_domain_attach_by_name() is not > described in DT, dev_pm_domain_attach_by_name() returns NULL, which is > then used a few lines below in dev_set_name(domain->power_dev, ...);, > which leads to NULL pointer dereference. This is already fixed by b64b46fbaa1da626324f304bcb5fe0662f28b6ce. Regards, Marco > > Fixes: 2684ac05a8c4 ("soc: imx: add i.MX8M blk-ctrl driver") > Signed-off-by: Marek Vasut <marex@denx.de> > --- > Cc: Adam Ford <aford173@gmail.com> > Cc: Benjamin Gaignard <benjamin.gaignard@collabora.com> > Cc: Fabio Estevam <festevam@gmail.com> > Cc: Lucas Stach <l.stach@pengutronix.de> > Cc: Marco Felsch <m.felsch@pengutronix.de> > Cc: Marek Vasut <marex@denx.de> > Cc: NXP Linux Team <linux-imx@nxp.com> > Cc: Paul Elder <paul.elder@ideasonboard.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> > To: linux-arm-kernel@lists.infradead.org > --- > drivers/soc/imx/imx8m-blk-ctrl.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/soc/imx/imx8m-blk-ctrl.c b/drivers/soc/imx/imx8m-blk-ctrl.c > index ddcf6be3d8b4a..2fbc8e6b2644b 100644 > --- a/drivers/soc/imx/imx8m-blk-ctrl.c > +++ b/drivers/soc/imx/imx8m-blk-ctrl.c > @@ -256,7 +256,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); > -- > 2.35.1 > >
diff --git a/drivers/soc/imx/imx8m-blk-ctrl.c b/drivers/soc/imx/imx8m-blk-ctrl.c index ddcf6be3d8b4a..2fbc8e6b2644b 100644 --- a/drivers/soc/imx/imx8m-blk-ctrl.c +++ b/drivers/soc/imx/imx8m-blk-ctrl.c @@ -256,7 +256,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);
Check domain->power_dev = dev_pm_domain_attach_by_name() return value using IS_ERR_OR_NULL() instead of plain IS_ERR(), and fail if domain->power_dev is either error or NULL. In case a power domain attached by dev_pm_domain_attach_by_name() is not described in DT, dev_pm_domain_attach_by_name() returns NULL, which is then used a few lines below in dev_set_name(domain->power_dev, ...);, which leads to NULL pointer dereference. Fixes: 2684ac05a8c4 ("soc: imx: add i.MX8M blk-ctrl driver") Signed-off-by: Marek Vasut <marex@denx.de> --- Cc: Adam Ford <aford173@gmail.com> Cc: Benjamin Gaignard <benjamin.gaignard@collabora.com> Cc: Fabio Estevam <festevam@gmail.com> Cc: Lucas Stach <l.stach@pengutronix.de> Cc: Marco Felsch <m.felsch@pengutronix.de> Cc: Marek Vasut <marex@denx.de> Cc: NXP Linux Team <linux-imx@nxp.com> Cc: Paul Elder <paul.elder@ideasonboard.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> To: linux-arm-kernel@lists.infradead.org --- drivers/soc/imx/imx8m-blk-ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)