linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: serial: samsung_tty: Check null pointer after calling of_match_node
@ 2022-01-11  8:16 Jiasheng Jiang
  2022-01-11  8:24 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2022-01-11  8:16 UTC (permalink / raw)
  To: krzysztof.kozlowski, gregkh, jirislaby
  Cc: linux-arm-kernel, linux-samsung-soc, linux-serial, linux-kernel,
	Jiasheng Jiang

If there is no suitable node, of_match_node() will return NULL pointer.
Therefore it should be better to check it in order to avoid the
dereference of NULL pointer.
And the only caller s3c24xx_serial_probe() has already checked the
return value of the s3c24xx_get_driver_data().
So the new check can be dealed with.

Fixes: 55ed51fff224 ("{tty: serial, nand: onenand}: samsung: rename to fix build warning")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/tty/serial/samsung_tty.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index e2f49863e9c2..efbf9a7d5e92 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -2185,6 +2185,9 @@ s3c24xx_get_driver_data(struct platform_device *pdev)
 		const struct of_device_id *match;
 
 		match = of_match_node(s3c24xx_uart_dt_match, pdev->dev.of_node);
+		if (!match)
+			return NULL;
+
 		return (struct s3c24xx_serial_drv_data *)match->data;
 	}
 #endif
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tty: serial: samsung_tty: Check null pointer after calling of_match_node
  2022-01-11  8:16 [PATCH] tty: serial: samsung_tty: Check null pointer after calling of_match_node Jiasheng Jiang
@ 2022-01-11  8:24 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 2+ messages in thread
From: Krzysztof Kozlowski @ 2022-01-11  8:24 UTC (permalink / raw)
  To: Jiasheng Jiang, gregkh, jirislaby
  Cc: linux-arm-kernel, linux-samsung-soc, linux-serial, linux-kernel

On 11/01/2022 09:16, Jiasheng Jiang wrote:
> If there is no suitable node, of_match_node() will return NULL pointer.

NAK.

This is not possible. All drivers have such pattern and it was
discouraged to add empty/dead NULL checks.

If you think returning NULL is possible, please explain/document it.

> Therefore it should be better to check it in order to avoid the
> dereference of NULL pointer.
> And the only caller s3c24xx_serial_probe() has already checked the
> return value of the s3c24xx_get_driver_data().
> So the new check can be dealed with.
> 



Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-11  8:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11  8:16 [PATCH] tty: serial: samsung_tty: Check null pointer after calling of_match_node Jiasheng Jiang
2022-01-11  8:24 ` Krzysztof Kozlowski

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