Skip to contentSkip to conversation

misc: tps6594-pfsm: Add NULL check in tps6594_pfsm_probe()

PATCH Superseded Henry Martin 2 participants 3 messages Apr 1, 2025 – Apr 15, 2025 Char and misc drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: tps6594-pfsm: Add NULL check in tps6594_pfsm_probe()

devm_kasprintf() returns NULL when memory allocation fails. Currently, tps6594_pfsm_probe() does not check for this case, which results in a NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes a0df3ef087f8 ("misc: tps6594-pfsm: Add driver for TI TPS6594 PFSM")
---
 drivers/misc/tps6594-pfsm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/misc/tps6594-pfsm.c +2 -0
index 0a24ce44cc37..0d9dad20b6ae 100644
@@ -281,6 +281,8 @@ static int tps6594_pfsm_probe(struct platform_device *pdev)
 	pfsm->miscdev.minor = MISC_DYNAMIC_MINOR;
 	pfsm->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "pfsm-%ld-0x%02x",
 					    tps->chip_id, tps->reg);
+	if (!pfsm->miscdev.name)
+		return -ENOMEM;
 	pfsm->miscdev.fops = &tps6594_pfsm_fops;
 	pfsm->miscdev.parent = dev->parent;
 	pfsm->chip_id = tps->chip_id;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 28 lines · Henry Martin

devm_kasprintf() returns NULL when memory allocation fails. Currently, tps6594_pfsm_probe() does not check for this case, which results in a NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes a0df3ef087f8 ("misc: tps6594-pfsm: Add driver for TI TPS6594 PFSM")
---
 drivers/misc/tps6594-pfsm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/misc/tps6594-pfsm.c +2 -0
index 0a24ce44cc37..0d9dad20b6ae 100644
@@ -281,6 +281,8 @@ static int tps6594_pfsm_probe(struct platform_device *pdev)
 	pfsm->miscdev.minor = MISC_DYNAMIC_MINOR;
 	pfsm->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "pfsm-%ld-0x%02x",
 					    tps->chip_id, tps->reg);
+	if (!pfsm->miscdev.name)
+		return -ENOMEM;
 	pfsm->miscdev.fops = &tps6594_pfsm_fops;
 	pfsm->miscdev.parent = dev->parent;
 	pfsm->chip_id = tps->chip_id;
Signature · 1 line
2.34.1

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this.

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot

maintainer
#2 lore raw
In reply to Henry Martin
Quoted 11 lines · Henry Martin

devm_kasprintf() returns NULL when memory allocation fails. Currently, tps6594_pfsm_probe() does not check for this case, which results in a NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes a0df3ef087f8 ("misc: tps6594-pfsm: Add driver for TI TPS6594 PFSM")
---
 drivers/misc/tps6594-pfsm.c | 2 ++
 1 file changed, 2 insertions(+)

Someone else sent this before you did, sorry:

	https://lore.kernel.org/r/[email protected]