From patchwork Fri Mar 23 15:29:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 132345 Delivered-To: patches@linaro.org Received: by 10.46.84.29 with SMTP id i29csp736833ljb; Fri, 23 Mar 2018 08:29:50 -0700 (PDT) X-Google-Smtp-Source: AG47ELsmAQZxprHMdZagwJpwYruCZNjVgyUBItyYWk2iYw2k12SCxIGmg4t7vdMXIYcXwwI0k08N X-Received: by 10.28.192.8 with SMTP id q8mr6761609wmf.103.1521818990816; Fri, 23 Mar 2018 08:29:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521818990; cv=none; d=google.com; s=arc-20160816; b=Gw3YE7AigLjWNTSQtfLciAAY7LDwnS0qqEmC6mNkcDBpIUyJHQ7MpJQv9YN/IOxz/U aErf4R89Rumlnc3AXXax5NFpAAE+FaqU5RxkUzwjRaopEwcI+TZkpUxmSewYRjj4UMwd eroHp5CXkBj2sdHVsL2Fw4wkXqBFH+q5FLVIFVu3w8leVp/0146l/LYegRBwNtQst0fr PX+eONJE/oJXndoB6Qj6rPFoQqPd+RtSjaeEl0KtxJdlOHxtFRmkcTpObbJ7hvmoArKB H5xs3YNPalusq/tv17cVcK1Oh/CGaZuRN3d/tBaiUwPs+g/UBo90WeC5Xn0BI2HCCC8+ OtGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=Gj5OY89EScywJKgJ/KiUkFd7XryYXV6nlCzTQbzs+ho=; b=b8L96slPZTqFHpItcU3inZV1yumc3t5bBuROFYDPura2sXFyA0Au7EhQWoh9JaQFnb ornB2GoGmfMqXG6WSCn0C4FXUr1jR0lg9HouDZ0mvqRJszgcCyMLxV4xYEtLkWHhPoW9 0vkhtE5cEcY5jlAxBlgudcZCPRJFQSM4Y50jMhg4y8QNVSyhzyaNOR6RTiPp9CE1Q/Vx Hkehkaoo7yvML1AW53U4lOA1ez420rG6ThdyCOexYZmK7QFbKfO6hkHR5ZfwYuQkcy/V MivckreEM2o3Jp6qio5yNYHG7ZrIQvIFs1n1KyMZJMsWvwn4a/7U8CUppZmjxn0XikXJ 6Q0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id b42si7237948wrd.365.2018.03.23.08.29.50 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Mar 2018 08:29:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 Cc: patches@linaro.org, Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Thomas Huth Subject: [PATCH for-2.12] chardev/char-fe: Allow NULL chardev in qemu_chr_fe_init() 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 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 --- 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(-) -- 2.16.2 Reviewed-by: Thomas Huth 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, Error **errp) { int tag = 0; - if (CHARDEV_IS_MUX(s)) { - MuxChardev *d = MUX_CHARDEV(s); + if (s) { + if (CHARDEV_IS_MUX(s)) { + MuxChardev *d = MUX_CHARDEV(s); - if (d->mux_cnt >= MAX_MUX) { + if (d->mux_cnt >= MAX_MUX) { + goto unavailable; + } + + d->backends[d->mux_cnt] = b; + tag = d->mux_cnt++; + } else if (s->be) { goto unavailable; + } else { + s->be = b; } - - d->backends[d->mux_cnt] = b; - tag = d->mux_cnt++; - } else if (s->be) { - goto unavailable; - } else { - s->be = b; } b->fe_open = false;