linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvmem: meson-mx-efuse: check the return value of devm_kstrdup()
@ 2022-01-16  5:34 xkernel.wang
  2022-01-16 23:01 ` Martin Blumenstingl
  0 siblings, 1 reply; 2+ messages in thread
From: xkernel.wang @ 2022-01-16  5:34 UTC (permalink / raw)
  To: srinivas.kandagatla, narmstrong, khilman
  Cc: jbrunet, martin.blumenstingl, linux-arm-kernel, linux-amlogic,
	linux-kernel, Xiaoke Wang

From: Xiaoke Wang <xkernel.wang@foxmail.com>

devm_kstrdup() returns pointer to allocated string on success,
NULL on failure. So it is better to check the return value of it.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 drivers/nvmem/meson-mx-efuse.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/nvmem/meson-mx-efuse.c b/drivers/nvmem/meson-mx-efuse.c
index 07c9f38..38e6a5f 100644
--- a/drivers/nvmem/meson-mx-efuse.c
+++ b/drivers/nvmem/meson-mx-efuse.c
@@ -211,6 +211,9 @@ static int meson_mx_efuse_probe(struct platform_device *pdev)
 
 	efuse->config.name = devm_kstrdup(&pdev->dev, drvdata->name,
 					  GFP_KERNEL);
+	if (!efuse->config.name)
+		return -ENOMEM;
+
 	efuse->config.owner = THIS_MODULE;
 	efuse->config.dev = &pdev->dev;
 	efuse->config.priv = efuse;
-- 

_______________________________________________
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] 2+ messages in thread

* Re: [PATCH] nvmem: meson-mx-efuse: check the return value of devm_kstrdup()
  2022-01-16  5:34 [PATCH] nvmem: meson-mx-efuse: check the return value of devm_kstrdup() xkernel.wang
@ 2022-01-16 23:01 ` Martin Blumenstingl
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Blumenstingl @ 2022-01-16 23:01 UTC (permalink / raw)
  To: xkernel.wang
  Cc: srinivas.kandagatla, Neil Armstrong, khilman, jbrunet,
	linux-arm-kernel, linux-amlogic, linux-kernel

Hello,

First of all: thank you for this patch!

On Sun, Jan 16, 2022 at 6:37 AM <xkernel.wang@foxmail.com> wrote:
[...]
> @@ -211,6 +211,9 @@ static int meson_mx_efuse_probe(struct platform_device *pdev)
>
>         efuse->config.name = devm_kstrdup(&pdev->dev, drvdata->name,
>                                           GFP_KERNEL);
> +       if (!efuse->config.name)
> +               return -ENOMEM;
Looking at other drivers and also at drivers/nvmem/core.c I believe
that the whole devm_kstrdup is unnecessary.
Instead I think the code can be simplified as:
    efuse->config.name = drvdata->name;

What do you think?


Best regards,
Martin

_______________________________________________
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] 2+ messages in thread

end of thread, other threads:[~2022-01-16 23:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-16  5:34 [PATCH] nvmem: meson-mx-efuse: check the return value of devm_kstrdup() xkernel.wang
2022-01-16 23:01 ` Martin Blumenstingl

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).