* [PATCH] net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe
@ 2023-12-11 2:45 Kunwu Chan
2023-12-12 21:27 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Kunwu Chan @ 2023-12-11 2:45 UTC (permalink / raw)
To: andrew, f.fainelli, olteanv, davem, edumazet, kuba, pabeni
Cc: netdev, linux-kernel, Kunwu Chan, Kunwu Chan
devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.
Cc: Kunwu Chan <kunwu.chan@hotmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
drivers/net/dsa/vitesse-vsc73xx-core.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
index e6f29e4e508c..f136eb5aea69 100644
--- a/drivers/net/dsa/vitesse-vsc73xx-core.c
+++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
@@ -1135,6 +1135,10 @@ static int vsc73xx_gpio_probe(struct vsc73xx *vsc)
vsc->gc.label = devm_kasprintf(vsc->dev, GFP_KERNEL, "VSC%04x",
vsc->chipid);
+ if (!vsc->gc.label) {
+ dev_err(vsc->dev, "Fail to allocate memory\n");
+ return -ENOMEM;
+ }
vsc->gc.ngpio = 4;
vsc->gc.owner = THIS_MODULE;
vsc->gc.parent = vsc->dev;
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe
2023-12-11 2:45 [PATCH] net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe Kunwu Chan
@ 2023-12-12 21:27 ` Jakub Kicinski
2023-12-14 3:22 ` Kunwu Chan
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2023-12-12 21:27 UTC (permalink / raw)
To: Kunwu Chan
Cc: andrew, f.fainelli, olteanv, davem, edumazet, pabeni, netdev,
linux-kernel, Kunwu Chan
On Mon, 11 Dec 2023 10:45:49 +0800 Kunwu Chan wrote:
> vsc->gc.label = devm_kasprintf(vsc->dev, GFP_KERNEL, "VSC%04x",
> vsc->chipid);
> + if (!vsc->gc.label) {
> + dev_err(vsc->dev, "Fail to allocate memory\n");
> + return -ENOMEM;
> + }
Don't add error prints on memory allocations.
There will be an OOM splat in the logs.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe
2023-12-12 21:27 ` Jakub Kicinski
@ 2023-12-14 3:22 ` Kunwu Chan
0 siblings, 0 replies; 3+ messages in thread
From: Kunwu Chan @ 2023-12-14 3:22 UTC (permalink / raw)
To: Jakub Kicinski
Cc: andrew, f.fainelli, olteanv, davem, edumazet, pabeni, netdev,
linux-kernel, Kunwu Chan
Thanks for your reply.
I'll remove 'dev_err' in v2 patch.
Thanks again.
On 2023/12/13 05:27, Jakub Kicinski wrote:
> On Mon, 11 Dec 2023 10:45:49 +0800 Kunwu Chan wrote:
>> vsc->gc.label = devm_kasprintf(vsc->dev, GFP_KERNEL, "VSC%04x",
>> vsc->chipid);
>> + if (!vsc->gc.label) {
>> + dev_err(vsc->dev, "Fail to allocate memory\n");
>> + return -ENOMEM;
>> + }
>
> Don't add error prints on memory allocations.
> There will be an OOM splat in the logs.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-14 3:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-11 2:45 [PATCH] net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe Kunwu Chan
2023-12-12 21:27 ` Jakub Kicinski
2023-12-14 3:22 ` Kunwu Chan
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).