* [PATCH v2] mtd: sa1100: avoid VLA in sa1100_setup_mtd
@ 2018-11-05 7:58 Boris Brezillon
2018-11-05 8:11 ` Boris Brezillon
2018-11-06 13:12 ` Boris Brezillon
0 siblings, 2 replies; 3+ messages in thread
From: Boris Brezillon @ 2018-11-05 7:58 UTC (permalink / raw)
To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
Richard Weinberger, linux-mtd
Cc: linux-kernel, Kees Cook, Olof Johansson
Enabling -Wvla found another variable-length array with randconfig
testing:
drivers/mtd/maps/sa1100-flash.c: In function 'sa1100_setup_mtd':
drivers/mtd/maps/sa1100-flash.c:224:10: error: ISO C90 forbids variable length array 'cdev' [-Werror=vla]
Dynamically allocate the cdev array passed to mtd_concat_create()
instead of using a VLA.
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Olof Johansson <olof@lixom.net>
---
Changes in v2:
- Allocate cdev dynamically instead of having a fixed-size array
Hello,
I'm planning to queue this patch to the mtd/fixes PR. Arnd, Kees, feel
free to add your R-b.
Regards,
Boris
---
drivers/mtd/maps/sa1100-flash.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index 784c6e1a0391..fd5fe12d7461 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -221,7 +221,14 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
info->mtd = info->subdev[0].mtd;
ret = 0;
} else if (info->num_subdev > 1) {
- struct mtd_info *cdev[nr];
+ struct mtd_info **cdev;
+
+ cdev = kmalloc_array(nr, sizeof(*cdev), GFP_KERNEL);
+ if (!cdev) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
/*
* We detected multiple devices. Concatenate them together.
*/
@@ -230,6 +237,7 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
info->mtd = mtd_concat_create(cdev, info->num_subdev,
plat->name);
+ kfree(cdev);
if (info->mtd == NULL) {
ret = -ENXIO;
goto err;
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mtd: sa1100: avoid VLA in sa1100_setup_mtd
2018-11-05 7:58 [PATCH v2] mtd: sa1100: avoid VLA in sa1100_setup_mtd Boris Brezillon
@ 2018-11-05 8:11 ` Boris Brezillon
2018-11-06 13:12 ` Boris Brezillon
1 sibling, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2018-11-05 8:11 UTC (permalink / raw)
To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
Richard Weinberger, linux-mtd
Cc: linux-kernel, Kees Cook, Olof Johansson
On Mon, 5 Nov 2018 08:58:35 +0100
Boris Brezillon <boris.brezillon@bootlin.com> wrote:
> Enabling -Wvla found another variable-length array with randconfig
> testing:
>
> drivers/mtd/maps/sa1100-flash.c: In function 'sa1100_setup_mtd':
> drivers/mtd/maps/sa1100-flash.c:224:10: error: ISO C90 forbids variable length array 'cdev' [-Werror=vla]
>
> Dynamically allocate the cdev array passed to mtd_concat_create()
> instead of using a VLA.
>
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Olof Johansson <olof@lixom.net>
> ---
> Changes in v2:
> - Allocate cdev dynamically instead of having a fixed-size array
>
> Hello,
>
> I'm planning to queue this patch to the mtd/fixes PR. Arnd, Kees, feel
^ I meant branch,
not PR, but this patch should also be part of the 4.20-rc2 fixes PR.
> free to add your R-b.
>
> Regards,
>
> Boris
> ---
> drivers/mtd/maps/sa1100-flash.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
> index 784c6e1a0391..fd5fe12d7461 100644
> --- a/drivers/mtd/maps/sa1100-flash.c
> +++ b/drivers/mtd/maps/sa1100-flash.c
> @@ -221,7 +221,14 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
> info->mtd = info->subdev[0].mtd;
> ret = 0;
> } else if (info->num_subdev > 1) {
> - struct mtd_info *cdev[nr];
> + struct mtd_info **cdev;
> +
> + cdev = kmalloc_array(nr, sizeof(*cdev), GFP_KERNEL);
> + if (!cdev) {
> + ret = -ENOMEM;
> + goto err;
> + }
> +
> /*
> * We detected multiple devices. Concatenate them together.
> */
> @@ -230,6 +237,7 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
>
> info->mtd = mtd_concat_create(cdev, info->num_subdev,
> plat->name);
> + kfree(cdev);
> if (info->mtd == NULL) {
> ret = -ENXIO;
> goto err;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mtd: sa1100: avoid VLA in sa1100_setup_mtd
2018-11-05 7:58 [PATCH v2] mtd: sa1100: avoid VLA in sa1100_setup_mtd Boris Brezillon
2018-11-05 8:11 ` Boris Brezillon
@ 2018-11-06 13:12 ` Boris Brezillon
1 sibling, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2018-11-06 13:12 UTC (permalink / raw)
To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
Richard Weinberger, linux-mtd
Cc: linux-kernel, Kees Cook, Olof Johansson
On Mon, 5 Nov 2018 08:58:35 +0100
Boris Brezillon <boris.brezillon@bootlin.com> wrote:
> Enabling -Wvla found another variable-length array with randconfig
> testing:
>
> drivers/mtd/maps/sa1100-flash.c: In function 'sa1100_setup_mtd':
> drivers/mtd/maps/sa1100-flash.c:224:10: error: ISO C90 forbids variable length array 'cdev' [-Werror=vla]
>
> Dynamically allocate the cdev array passed to mtd_concat_create()
> instead of using a VLA.
>
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Olof Johansson <olof@lixom.net>
Queued to the mtd fixes branch.
> ---
> Changes in v2:
> - Allocate cdev dynamically instead of having a fixed-size array
>
> Hello,
>
> I'm planning to queue this patch to the mtd/fixes PR. Arnd, Kees, feel
> free to add your R-b.
>
> Regards,
>
> Boris
> ---
> drivers/mtd/maps/sa1100-flash.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
> index 784c6e1a0391..fd5fe12d7461 100644
> --- a/drivers/mtd/maps/sa1100-flash.c
> +++ b/drivers/mtd/maps/sa1100-flash.c
> @@ -221,7 +221,14 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
> info->mtd = info->subdev[0].mtd;
> ret = 0;
> } else if (info->num_subdev > 1) {
> - struct mtd_info *cdev[nr];
> + struct mtd_info **cdev;
> +
> + cdev = kmalloc_array(nr, sizeof(*cdev), GFP_KERNEL);
> + if (!cdev) {
> + ret = -ENOMEM;
> + goto err;
> + }
> +
> /*
> * We detected multiple devices. Concatenate them together.
> */
> @@ -230,6 +237,7 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
>
> info->mtd = mtd_concat_create(cdev, info->num_subdev,
> plat->name);
> + kfree(cdev);
> if (info->mtd == NULL) {
> ret = -ENXIO;
> goto err;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-11-06 13:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-05 7:58 [PATCH v2] mtd: sa1100: avoid VLA in sa1100_setup_mtd Boris Brezillon
2018-11-05 8:11 ` Boris Brezillon
2018-11-06 13:12 ` Boris Brezillon
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).