tty: serial: Add a NULL check for of_node
Subsystems (2)
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")
Signed-off-by Ma Ke <[email protected]>
--- drivers/tty/serial/fsl_linflexuart.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/tty/serial/fsl_linflexuart.c +3 -0
@@ -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
Greg KH
maintainerQuoted 1 line · Ma Ke
The
pdev->dev.of_nodecan 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")Signed-off-by Ma Ke <[email protected]>--- drivers/tty/serial/fsl_linflexuart.c | 3 +++ 1 file changed, 3 insertions(+)drivers/tty/serial/fsl_linflexuart.c +0
-0
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