U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drivers: serial: Make sure we really return a serial device
@ 2022-02-21 21:17 Mark Kettenis
  2022-03-06  3:07 ` Simon Glass
  2022-03-09 20:00 ` Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Mark Kettenis @ 2022-02-21 21:17 UTC (permalink / raw)
  To: u-boot; +Cc: sjg, Mark Kettenis

The stdout-path property in the device tree does not necessarily
point at a serial device. On machines such as the Apple M1 laptops
where the serial port isn't easy to access and users expect to see
console output on the integrated display stdout-path may point at
the device tree node for the framebuffer for example.

If stdout-path does not point at a node for a serial device, the
serial_check_stdout() will not find a bound device and will drop
down into code that attempts to use lists_bind_fdt() to bind a
device anyway. However, that fallback code does not check that
the uclass of the device is UCLASS_SERIAL. So if stdout-path points
at the framebuffer instead of the serial device it will return a
UCLASS_VIDEO device. Since the code that calls this function
expects the returned device to be a UCLASS_SERIAL device, U-Boot
will crash as soon as it attempts to send output to the console.

Add a check here to verify that the uclass of the bound device
really is UCLASS_SERIAL. If it isn't, serial_check_stdout() will
return an error and serial_find_console_or_panic() will use the
serial device with sequence number 0 as the console and all is fine.

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
---

ChangeLog:

v2: - Expand commit message


 drivers/serial/serial-uclass.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 362cedd955..f30f352bd7 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -66,7 +66,8 @@ static int serial_check_stdout(const void *blob, struct udevice **devp)
 	 */
 	if (node > 0 && !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node),
 					devp, NULL, false)) {
-		if (!device_probe(*devp))
+		if (device_get_uclass_id(*devp) == UCLASS_SERIAL &&
+		    !device_probe(*devp))
 			return 0;
 	}
 
-- 
2.35.1


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

* Re: [PATCH v2] drivers: serial: Make sure we really return a serial device
  2022-02-21 21:17 [PATCH v2] drivers: serial: Make sure we really return a serial device Mark Kettenis
@ 2022-03-06  3:07 ` Simon Glass
  2022-03-09 20:00 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2022-03-06  3:07 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: U-Boot Mailing List

On Mon, 21 Feb 2022 at 14:17, Mark Kettenis <kettenis@openbsd.org> wrote:
>
> The stdout-path property in the device tree does not necessarily
> point at a serial device. On machines such as the Apple M1 laptops
> where the serial port isn't easy to access and users expect to see
> console output on the integrated display stdout-path may point at
> the device tree node for the framebuffer for example.
>
> If stdout-path does not point at a node for a serial device, the
> serial_check_stdout() will not find a bound device and will drop
> down into code that attempts to use lists_bind_fdt() to bind a
> device anyway. However, that fallback code does not check that
> the uclass of the device is UCLASS_SERIAL. So if stdout-path points
> at the framebuffer instead of the serial device it will return a
> UCLASS_VIDEO device. Since the code that calls this function
> expects the returned device to be a UCLASS_SERIAL device, U-Boot
> will crash as soon as it attempts to send output to the console.
>
> Add a check here to verify that the uclass of the bound device
> really is UCLASS_SERIAL. If it isn't, serial_check_stdout() will
> return an error and serial_find_console_or_panic() will use the
> serial device with sequence number 0 as the console and all is fine.
>
> Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
> ---
>
> ChangeLog:
>
> v2: - Expand commit message
>
>
>  drivers/serial/serial-uclass.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* Re: [PATCH v2] drivers: serial: Make sure we really return a serial device
  2022-02-21 21:17 [PATCH v2] drivers: serial: Make sure we really return a serial device Mark Kettenis
  2022-03-06  3:07 ` Simon Glass
@ 2022-03-09 20:00 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2022-03-09 20:00 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: u-boot, sjg

[-- Attachment #1: Type: text/plain, Size: 1443 bytes --]

On Mon, Feb 21, 2022 at 10:17:37PM +0100, Mark Kettenis wrote:

> The stdout-path property in the device tree does not necessarily
> point at a serial device. On machines such as the Apple M1 laptops
> where the serial port isn't easy to access and users expect to see
> console output on the integrated display stdout-path may point at
> the device tree node for the framebuffer for example.
> 
> If stdout-path does not point at a node for a serial device, the
> serial_check_stdout() will not find a bound device and will drop
> down into code that attempts to use lists_bind_fdt() to bind a
> device anyway. However, that fallback code does not check that
> the uclass of the device is UCLASS_SERIAL. So if stdout-path points
> at the framebuffer instead of the serial device it will return a
> UCLASS_VIDEO device. Since the code that calls this function
> expects the returned device to be a UCLASS_SERIAL device, U-Boot
> will crash as soon as it attempts to send output to the console.
> 
> Add a check here to verify that the uclass of the bound device
> really is UCLASS_SERIAL. If it isn't, serial_check_stdout() will
> return an error and serial_find_console_or_panic() will use the
> serial device with sequence number 0 as the console and all is fine.
> 
> Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

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

end of thread, other threads:[~2022-03-09 20:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-21 21:17 [PATCH v2] drivers: serial: Make sure we really return a serial device Mark Kettenis
2022-03-06  3:07 ` Simon Glass
2022-03-09 20:00 ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox