* [PATCH] soc: imx: imx8m-blk-ctrl: off by one in imx8m_blk_ctrl_xlate()
@ 2021-10-11 12:36 Dan Carpenter
2021-10-12 8:29 ` Lucas Stach
2021-10-15 3:10 ` Shawn Guo
0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-10-11 12:36 UTC (permalink / raw)
To: Shawn Guo
Cc: Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
NXP Linux Team, Lucas Stach, Peng Fan, Philipp Zabel,
Frieder Schrempf, linux-arm-kernel, linux-kernel,
kernel-janitors
The > comparison should be >= to prevent reading one element beyond the
end of the array. The onecell_data->domains[] array is allocated in
imx8m_blk_ctrl_probe() and it has "onecell_data->num_domains" elements.
Fixes: 5b340e7813d4 ("soc: imx: add i.MX8M blk-ctrl driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
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 e172d295c441..519b3651d1d9 100644
--- a/drivers/soc/imx/imx8m-blk-ctrl.c
+++ b/drivers/soc/imx/imx8m-blk-ctrl.c
@@ -139,7 +139,7 @@ imx8m_blk_ctrl_xlate(struct of_phandle_args *args, void *data)
unsigned int index = args->args[0];
if (args->args_count != 1 ||
- index > onecell_data->num_domains)
+ index >= onecell_data->num_domains)
return ERR_PTR(-EINVAL);
return onecell_data->domains[index];
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] soc: imx: imx8m-blk-ctrl: off by one in imx8m_blk_ctrl_xlate()
2021-10-11 12:36 [PATCH] soc: imx: imx8m-blk-ctrl: off by one in imx8m_blk_ctrl_xlate() Dan Carpenter
@ 2021-10-12 8:29 ` Lucas Stach
2021-10-12 9:33 ` Dan Carpenter
2021-10-15 3:10 ` Shawn Guo
1 sibling, 1 reply; 4+ messages in thread
From: Lucas Stach @ 2021-10-12 8:29 UTC (permalink / raw)
To: Dan Carpenter, Shawn Guo
Cc: Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
NXP Linux Team, Peng Fan, Philipp Zabel, Frieder Schrempf,
linux-arm-kernel, linux-kernel, kernel-janitors
Hi Dan,
Am Montag, dem 11.10.2021 um 15:36 +0300 schrieb Dan Carpenter:
> The > comparison should be >= to prevent reading one element beyond the
> end of the array. The onecell_data->domains[] array is allocated in
> imx8m_blk_ctrl_probe() and it has "onecell_data->num_domains" elements.
Thanks for the patch! I guess this was found via smatch? I should
really make it a habit to use smatch on my submissions...
> Fixes: 5b340e7813d4 ("soc: imx: add i.MX8M blk-ctrl driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
> ---
> 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 e172d295c441..519b3651d1d9 100644
> --- a/drivers/soc/imx/imx8m-blk-ctrl.c
> +++ b/drivers/soc/imx/imx8m-blk-ctrl.c
> @@ -139,7 +139,7 @@ imx8m_blk_ctrl_xlate(struct of_phandle_args *args, void *data)
> unsigned int index = args->args[0];
>
> if (args->args_count != 1 ||
> - index > onecell_data->num_domains)
> + index >= onecell_data->num_domains)
> return ERR_PTR(-EINVAL);
>
> return onecell_data->domains[index];
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] soc: imx: imx8m-blk-ctrl: off by one in imx8m_blk_ctrl_xlate()
2021-10-12 8:29 ` Lucas Stach
@ 2021-10-12 9:33 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-10-12 9:33 UTC (permalink / raw)
To: Lucas Stach
Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
NXP Linux Team, Peng Fan, Philipp Zabel, Frieder Schrempf,
linux-arm-kernel, linux-kernel, kernel-janitors
On Tue, Oct 12, 2021 at 10:29:27AM +0200, Lucas Stach wrote:
> Hi Dan,
>
> Am Montag, dem 11.10.2021 um 15:36 +0300 schrieb Dan Carpenter:
> > The > comparison should be >= to prevent reading one element beyond the
> > end of the array. The onecell_data->domains[] array is allocated in
> > imx8m_blk_ctrl_probe() and it has "onecell_data->num_domains" elements.
>
> Thanks for the patch! I guess this was found via smatch? I should
> really make it a habit to use smatch on my submissions...
Yeah, but not a from a published check. I have a private check for
off by one errors that warns about any > vs >= comparisons that cannot
be proved as correct.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] soc: imx: imx8m-blk-ctrl: off by one in imx8m_blk_ctrl_xlate()
2021-10-11 12:36 [PATCH] soc: imx: imx8m-blk-ctrl: off by one in imx8m_blk_ctrl_xlate() Dan Carpenter
2021-10-12 8:29 ` Lucas Stach
@ 2021-10-15 3:10 ` Shawn Guo
1 sibling, 0 replies; 4+ messages in thread
From: Shawn Guo @ 2021-10-15 3:10 UTC (permalink / raw)
To: Dan Carpenter
Cc: Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
NXP Linux Team, Lucas Stach, Peng Fan, Philipp Zabel,
Frieder Schrempf, linux-arm-kernel, linux-kernel,
kernel-janitors
On Mon, Oct 11, 2021 at 03:36:38PM +0300, Dan Carpenter wrote:
> The > comparison should be >= to prevent reading one element beyond the
> end of the array. The onecell_data->domains[] array is allocated in
> imx8m_blk_ctrl_probe() and it has "onecell_data->num_domains" elements.
>
> Fixes: 5b340e7813d4 ("soc: imx: add i.MX8M blk-ctrl driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-15 3:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-11 12:36 [PATCH] soc: imx: imx8m-blk-ctrl: off by one in imx8m_blk_ctrl_xlate() Dan Carpenter
2021-10-12 8:29 ` Lucas Stach
2021-10-12 9:33 ` Dan Carpenter
2021-10-15 3:10 ` Shawn Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).