From nobody Mon Apr 29 14:05:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521819075934104.95734212533591; Fri, 23 Mar 2018 08:31:15 -0700 (PDT) Received: from localhost ([::1]:38600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezOep-00073f-9P for importer@patchew.org; Fri, 23 Mar 2018 11:31:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezOdi-0006Yi-Pv for qemu-devel@nongnu.org; Fri, 23 Mar 2018 11:29:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezOdh-00054L-UI for qemu-devel@nongnu.org; Fri, 23 Mar 2018 11:29:58 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:40498) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ezOdh-00050K-MY for qemu-devel@nongnu.org; Fri, 23 Mar 2018 11:29:57 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1ezOdZ-0007U8-Ao; Fri, 23 Mar 2018 15:29:49 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 23 Mar 2018 15:29:48 +0000 Message-Id: <20180323152948.27048-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-2.12] chardev/char-fe: Allow NULL chardev in qemu_chr_fe_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Thomas Huth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" All the functions in char-fe.c handle the CharBackend having a NULL Chardev pointer, which means that the backend exists but is not connected to anything. The exception is qemu_chr_fe_init(), which will crash if passed a NULL Chardev pointer argument. This can happen for various boards if they're started with 'nodefaults': arm-softmmu/qemu-system-arm -S -nodefaults -M cubieboard riscv32-softmmu/qemu-system-riscv32 -nodefaults -M sifive_e Make qemu_chr_fe_init() accept a NULL chardev. This allows UART models to handle NULL chardev properties without generally needing to special case them or to manually create a NullChardev. Reported-by: Thomas Huth Signed-off-by: Peter Maydell Reviewed-by: Thomas Huth --- This is my proposal for fixing the crashes with -nodefaults. I think we should also change hw/char/serial.c to accept a NULL Chardev rather than treating it as an error ( "Can't create serial device, empty char device"), and similarly for any other devices that currently error out on NULL chardevs. I'd rather postpone that part til 2.13, though. chardev/char-fe.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index 392db78b13..b1f228e8b5 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -198,19 +198,21 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Err= or **errp) { int tag =3D 0; =20 - if (CHARDEV_IS_MUX(s)) { - MuxChardev *d =3D MUX_CHARDEV(s); + if (s) { + if (CHARDEV_IS_MUX(s)) { + MuxChardev *d =3D MUX_CHARDEV(s); =20 - if (d->mux_cnt >=3D MAX_MUX) { + if (d->mux_cnt >=3D MAX_MUX) { + goto unavailable; + } + + d->backends[d->mux_cnt] =3D b; + tag =3D d->mux_cnt++; + } else if (s->be) { goto unavailable; + } else { + s->be =3D b; } - - d->backends[d->mux_cnt] =3D b; - tag =3D d->mux_cnt++; - } else if (s->be) { - goto unavailable; - } else { - s->be =3D b; } =20 b->fe_open =3D false; --=20 2.16.2