From nobody Sat Oct 25 11:06:49 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521471697523683.9978581183996; Mon, 19 Mar 2018 08:01:37 -0700 (PDT) Received: from localhost ([::1]:42424 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exwI4-0000vy-OM for importer@patchew.org; Mon, 19 Mar 2018 11:01:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exwGt-0000U4-Lt for qemu-devel@nongnu.org; Mon, 19 Mar 2018 11:00:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exwGp-0006Ft-J1 for qemu-devel@nongnu.org; Mon, 19 Mar 2018 11:00:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57412 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1exwGp-0006FH-Ai for qemu-devel@nongnu.org; Mon, 19 Mar 2018 11:00:19 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B2A89EBFE2; Mon, 19 Mar 2018 15:00:18 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 749F6202322C; Mon, 19 Mar 2018 15:00:17 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org Date: Mon, 19 Mar 2018 16:00:16 +0100 Message-Id: <1521471616-24157-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 19 Mar 2018 15:00:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 19 Mar 2018 15:00:18 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH for-2.12] hw/char/serial: Fix crash when serial_mm_init() is used with -nodefaults 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: Peter Maydell , Paolo Bonzini , "Michael S. Tsirkin" 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" Quite a lot of boards call serial_mm_init() directly with a value from the serial_hds[] table. However, this table is only containing NULL if QEMU has been started with "-nodefaults": $ gdb --args arm-softmmu/qemu-system-arm -S -nodefaults -M cubieboard (gdb) r Program received signal SIGSEGV, Segmentation fault. qemu_chr_fe_init (b=3Db@entry=3D0x555556cc4260, s=3Ds@entry=3D0x0, errp=3D0= x55555697eb40 ) at chardev/char-fe.c:210 210 } else if (s->be) { Since calling serial_mm_init with a NULL pointer seems to be a common pattern between many boards, let's simply fix this by creating a "null" chardev on the fly in this case. Signed-off-by: Thomas Huth --- hw/char/serial.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/char/serial.c b/hw/char/serial.c index eb72191..c1f7ff7 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -1040,6 +1040,10 @@ SerialState *serial_mm_init(MemoryRegion *address_sp= ace, { SerialState *s; =20 + if (!chr) { + chr =3D qemu_chardev_new(NULL, TYPE_CHARDEV_NULL, NULL, &error_abo= rt); + } + s =3D g_malloc0(sizeof(SerialState)); =20 s->it_shift =3D it_shift; --=20 1.8.3.1