* [PATCH] mtd: rawnand: meson: check return value of devm_kasprintf()
@ 2023-10-18 9:20 Yi Yang
2023-10-18 12:19 ` Miquel Raynal
0 siblings, 1 reply; 3+ messages in thread
From: Yi Yang @ 2023-10-18 9:20 UTC (permalink / raw)
To: liang.yang, miquel.raynal, richard, vigneshr, neil.armstrong,
khilman, jbrunet, martin.blumenstingl
Cc: linux-mtd, linux-arm-kernel, linux-amlogic
The devm_kasprintf() returns a pointer to dynamically allocated memory.
that will return NULL when allocate failed.
Fix it by check return value of devm_kasprintf().
Fixes: 1e4d3ba66888 ("mtd: rawnand: meson: fix the clock")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
drivers/mtd/nand/raw/meson_nand.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
index 378f28ce6a74..2c6ae781bb0c 100644
--- a/drivers/mtd/nand/raw/meson_nand.c
+++ b/drivers/mtd/nand/raw/meson_nand.c
@@ -1134,6 +1134,11 @@ static int meson_nfc_clk_init(struct meson_nfc *nfc)
init.name = devm_kasprintf(nfc->dev,
GFP_KERNEL, "%s#div",
dev_name(nfc->dev));
+ if (init.name) {
+ dev_err(nfc->dev, "failed to allocate init.name\n");
+ return -ENOMEM;
+ }
+
init.ops = &clk_divider_ops;
nfc_divider_parent_data[0].fw_name = "device";
init.parent_data = nfc_divider_parent_data;
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd: rawnand: meson: check return value of devm_kasprintf()
2023-10-18 9:20 [PATCH] mtd: rawnand: meson: check return value of devm_kasprintf() Yi Yang
@ 2023-10-18 12:19 ` Miquel Raynal
2023-10-19 1:23 ` yiyang (D)
0 siblings, 1 reply; 3+ messages in thread
From: Miquel Raynal @ 2023-10-18 12:19 UTC (permalink / raw)
To: Yi Yang
Cc: liang.yang, richard, vigneshr, neil.armstrong, khilman, jbrunet,
martin.blumenstingl, linux-mtd, linux-arm-kernel, linux-amlogic
Hi Yi,
yiyang13@huawei.com wrote on Wed, 18 Oct 2023 09:20:47 +0000:
> The devm_kasprintf() returns a pointer to dynamically allocated memory.
> that will return NULL when allocate failed.
May I propose rewording of the commit log?
"
devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful by
checking the pointer validity.
"
> Fix it by check return value of devm_kasprintf().
>
> Fixes: 1e4d3ba66888 ("mtd: rawnand: meson: fix the clock")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
> drivers/mtd/nand/raw/meson_nand.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
> index 378f28ce6a74..2c6ae781bb0c 100644
> --- a/drivers/mtd/nand/raw/meson_nand.c
> +++ b/drivers/mtd/nand/raw/meson_nand.c
> @@ -1134,6 +1134,11 @@ static int meson_nfc_clk_init(struct meson_nfc *nfc)
> init.name = devm_kasprintf(nfc->dev,
> GFP_KERNEL, "%s#div",
> dev_name(nfc->dev));
> + if (init.name) {
> + dev_err(nfc->dev, "failed to allocate init.name\n");
No need for error messages upon memory allocation failures.
> + return -ENOMEM;
> + }
> +
> init.ops = &clk_divider_ops;
> nfc_divider_parent_data[0].fw_name = "device";
> init.parent_data = nfc_divider_parent_data;
These comments are also applicable to your two other patches.
Thanks,
Miquèl
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd: rawnand: meson: check return value of devm_kasprintf()
2023-10-18 12:19 ` Miquel Raynal
@ 2023-10-19 1:23 ` yiyang (D)
0 siblings, 0 replies; 3+ messages in thread
From: yiyang (D) @ 2023-10-19 1:23 UTC (permalink / raw)
To: Miquel Raynal
Cc: liang.yang, richard, vigneshr, neil.armstrong, khilman, jbrunet,
martin.blumenstingl, linux-mtd, linux-arm-kernel, linux-amlogic
On 2023/10/18 20:19, Miquel Raynal wrote:
> Hi Yi,
>
> yiyang13@huawei.com wrote on Wed, 18 Oct 2023 09:20:47 +0000:
>
>> The devm_kasprintf() returns a pointer to dynamically allocated memory.
>> that will return NULL when allocate failed.
>
> May I propose rewording of the commit log?
> "
> devm_kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure. Ensure the allocation was successful by
> checking the pointer validity.
> "
>
Thanks for your advice, I'll make changes in v2 patch.
>> Fix it by check return value of devm_kasprintf().
>>
>> Fixes: 1e4d3ba66888 ("mtd: rawnand: meson: fix the clock")
>> Signed-off-by: Yi Yang <yiyang13@huawei.com>
>> ---
>> drivers/mtd/nand/raw/meson_nand.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
>> index 378f28ce6a74..2c6ae781bb0c 100644
>> --- a/drivers/mtd/nand/raw/meson_nand.c
>> +++ b/drivers/mtd/nand/raw/meson_nand.c
>> @@ -1134,6 +1134,11 @@ static int meson_nfc_clk_init(struct meson_nfc *nfc)
>> init.name = devm_kasprintf(nfc->dev,
>> GFP_KERNEL, "%s#div",
>> dev_name(nfc->dev));
>> + if (init.name) {
>> + dev_err(nfc->dev, "failed to allocate init.name\n");
>
> No need for error messages upon memory allocation failures.
>
>> + return -ENOMEM;
>> + }
>> +
>> init.ops = &clk_divider_ops;
>> nfc_divider_parent_data[0].fw_name = "device";
>> init.parent_data = nfc_divider_parent_data;
>
> These comments are also applicable to your two other patches.
>
> Thanks,
> Miquèl
> .
>
Thanks,
Yi yang
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-19 1:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-18 9:20 [PATCH] mtd: rawnand: meson: check return value of devm_kasprintf() Yi Yang
2023-10-18 12:19 ` Miquel Raynal
2023-10-19 1:23 ` yiyang (D)
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).