Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EF9ADC433EF for ; Mon, 7 Feb 2022 21:20:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2592D8340A; Mon, 7 Feb 2022 22:20:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xs4all.nl Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 3839A83835; Mon, 7 Feb 2022 22:20:46 +0100 (CET) Received: from sibelius.xs4all.nl (sibelius.xs4all.nl [83.163.83.176]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 133C983264 for ; Mon, 7 Feb 2022 22:20:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xs4all.nl Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=mark.kettenis@xs4all.nl Received: from localhost (bloch.sibelius.xs4all.nl [local]) by bloch.sibelius.xs4all.nl (OpenSMTPD) with ESMTPA id ff830f13; Mon, 7 Feb 2022 22:20:41 +0100 (CET) Date: Mon, 7 Feb 2022 22:20:41 +0100 (CET) From: Mark Kettenis To: Simon Glass Cc: kettenis@openbsd.org, u-boot@lists.denx.de In-Reply-To: (message from Simon Glass on Mon, 7 Feb 2022 13:22:22 -0700) Subject: Re: [PATCH] drivers: serial: Make sure we really return a serial device References: <20220205231018.3050-1-kettenis@openbsd.org> Message-ID: X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean > From: Simon Glass > Date: Mon, 7 Feb 2022 13:22:22 -0700 > > Hi Mark, > > On Sat, 5 Feb 2022 at 16:10, Mark Kettenis wrote: > > > > The stdout-path property in the device tree does not necessarily > > point at a serial device. The code that binds the device if it > > isn't marked to be bound before relocation does not check whether > > the device really is a serial device. So check that its uclass is > > UCLASS_SERIAL before probing it. > > > > Signed-off-by: Mark Kettenis > > --- > > drivers/serial/serial-uclass.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > This would be better as an assert() to avoid code bloat. Under what > circumstances was this wrong? I'm passing a debive tree to U-Boot that has stdout-path set to "/chosen/framebuffer" to indicate that output should go to the framebuffer instead of the serial port. This is a node with a "simple-framebuffer" compatible, which means the list_bind_fdt() call binds the simple_video (simplefb.c) driver and stores a pointer to its struct udevice into devp. I've verified that the uclass is indeed UCLASS_VIDEO at that point with my device tree. Since the function returns 0, the caller of this function thinks we returned a valid UCLASS_SERIAL device and when u-boot starts using it as such it crashes (without printing anything since there is no console output device yet). So an assert won't work. We should simply return an error an run the fallback code below that looks for the serial port with the specified index. That way U-Boot continues to work as expected (with output on both the serial port and the framebuffer). But once my OS is running, it knows to pick the framebuffer console and all's fine. I haven't looked at the binary growth, but it can't be much. But if you think it is a problem, maybe we should make this code that binds the console driver optional? Thanks, Mark > > diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c > > index 96a1cb65ba..931a90bdbd 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.34.1 > > > > Regards, > Simon >