Skip to contentSkip to conversation

tty: serial: Add a NULL check for of_node

PATCH In review Ma Ke 2 participants 2 messages Aug 14, 2024

Subsystems (2)
lore
Share & tools
lore

Ma Ke

author
#0 lore raw

PATCH 1/1 tty: serial: Add a NULL check for of_node

The pdev->dev.of_node can be NULL if the "serial" node is absent. Add a NULL check for np to return an error in such cases.

Found by code review. Compile tested only.

Fixes 09864c1cdf5c ("tty: serial: Add linflexuart driver for S32V234")
---
 drivers/tty/serial/fsl_linflexuart.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/tty/serial/fsl_linflexuart.c +3 -0
index e972df4b188d..f46f3c21ee1b 100644
@@ -811,6 +811,9 @@ static int linflex_probe(struct platform_device *pdev)
 	struct resource *res;
 	int ret;
 
+	if (!np)
+		return -ENODEV;
+
 	sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL);
 	if (!sport)
 		return -ENOMEM;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 1 line · Ma Ke

The pdev->dev.of_node can be NULL if the "serial" node is absent.

When will that happen?

Quoted 3 lines

Add a NULL check for np to return an error in such cases.

Found by code review. Compile tested only.

So this never can happen?

Quoted 13 lines
Fixes 09864c1cdf5c ("tty: serial: Add linflexuart driver for S32V234")
---
 drivers/tty/serial/fsl_linflexuart.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/tty/serial/fsl_linflexuart.c +0 -0
index e972df4b188d..f46f3c21ee1b 100644

drivers/tty/serial/fsl_linflexuart.c static int linflex_probe(struct platform_device *pdev) · line 815

Quoted 5 lines
drivers/tty/serial/fsl_linflexuart.c +2 -0
@@ -811,6 +811,9 @@ static int linflex_probe(struct platform_device *pdev)
 	struct resource *res;
 	int ret;
 
+	if (!np)
+		return -ENODEV;

Again, how can this happen? Probe is only called if the platform device is found, so why wouldn't the of_node pointer be set?

Don't check for impossible things.

thanks,

greg k-h