From patchwork Mon Mar 26 13:36:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 132404 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp3868570ljb; Mon, 26 Mar 2018 06:52:02 -0700 (PDT) X-Google-Smtp-Source: AG47ELudHn1dro/amocP/leDzklfA+K/WRZdNbRdIA9R8u9ES8Ag0ZzQX99NeCvCQfa+ySblo6ck X-Received: by 10.200.17.2 with SMTP id c2mr32328845qtj.21.1522072322206; Mon, 26 Mar 2018 06:52:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522072322; cv=none; d=google.com; s=arc-20160816; b=QdjPL6j898rkojyISXjoUdWRpXYPoIAAWe5HvFVjOOs+dK2sG2Xsu8tdymXe7kpHN1 Vi8OxpcHKcRkp96VhbueUBSrJccMQ7ZJUqs0KA69q8P9m7+FKzndOKJu+c1yy94Udgu8 sgAupVqucR2CNQAS2jCczPOnJk3NBhpuO9XUuEO9wyCZrZLBG7vWyFt32E17g3dNHH/2 HNz7QmjqFfI29lTIh+Bfphx7B7xceit/qbJgcA6f5i5RRQNZCX/Ejj/s7cXCkCB8Cvm5 NFI3L3d/MBF0F7NzxHk7IKE4mC4sBVncHns4WDJB//5qMQQCcrHTNA6wa9bUT76vH8jJ QURg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=+hgofuNV++q5u2zYKD/0sMYy6lcXdBuKp8VlhdHHqPU=; b=TT6SEqwZSpNcLhaSI6F7YAMr9lSSlm4/asWcuuEwlM7/Z0N+gk0c9l+4c9wJ9r8jKw m5mnXR2C+w8NlgBWA7T7qjI1nVlVAqvy1ZZ8sZlHhV/2jLqEfMV3av6d6OWQsHf3rgcQ zsg76PDUYJWN5Mt22rdfV41c01xZ31zW8fS2nuj1SI16oMpHVclD1DbTeRxeUoY6l/vE mKb3MuicHwcLWlaejdcyvprYx+x4NtLShd7b6+rX4W5EpoVjv1rBeyxFu3nr5UOiZrL7 VmJf0g1zNfCpXpQh0p+wTtyWwcZkzDtj26nitzn6xp7+jeaMGlXLFQmYvNwTerKlqtk2 XiqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=vU1aV6I0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t20si1336001qki.303.2018.03.26.06.52.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 26 Mar 2018 06:52:02 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=vU1aV6I0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:56894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0SXZ-0003PQ-Ol for patch@linaro.org; Mon, 26 Mar 2018 09:52:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0SJ8-0006h8-UL for qemu-devel@nongnu.org; Mon, 26 Mar 2018 09:37:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0SJ7-000734-Sc for qemu-devel@nongnu.org; Mon, 26 Mar 2018 09:37:06 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:36590) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f0SJ7-00072g-MD for qemu-devel@nongnu.org; Mon, 26 Mar 2018 09:37:05 -0400 Received: by mail-wr0-x242.google.com with SMTP id d10so18957559wrf.3 for ; Mon, 26 Mar 2018 06:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+hgofuNV++q5u2zYKD/0sMYy6lcXdBuKp8VlhdHHqPU=; b=vU1aV6I0Evpm1s/Bo+ZNoJJnNJdR/nGXA/H+xTuF/xKYPwDVRmwgRjgMDiBSULc1/K TEwltiJhYuJ8WRsPMM6vkXfXKLoAJtVLZnCr4VFz33qUPMURQq0xcYwVZDywn4+7nle8 GV1S+gO3kNPOJ+9TWAW6sUwbFFRGHj/nHmuqQgd9LPGClOBBPdIrp3vx2eowBrIUV/rV eRJW11+ZoulMXdR78AGTlcj53aaeAvd0eIyfCDG2w68Wn50IFqu+suyOZ09Pbuv8eYWY sWx+7jevdHAvi56RnjXu7EEeqnbbzHcLpDNlEWh54LfwIwe5vToHQ3oaehE5G3hP7WsE vrCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+hgofuNV++q5u2zYKD/0sMYy6lcXdBuKp8VlhdHHqPU=; b=XshJnJQLMt8TF8v78nDbUf9Dsn8/3SCa9hWRjAI/FWKAsNVt3lQ00/2ou5WRGjW59E H0RE2iPJCznVkqoNz6mnANuTdyaRP7d8fuHstCWKzfxeYIwApRvTjC2y1pBjHb6t3dnn jbZtKHN1OZzRRMQ/srH/Wnyr00VHzj/HxKDe32Ur9sz4hZACndEu4En5U2/+4ayQMvXx Vh4seMmVDbPPULV81MYMabnLSf2q9IgNc0gp3LqUxqahHHvgm7rfmZA9nO9h8R8xPF6R /iZOJWhPq5YsSdb6cyigFQymIdMHBsZINO9byY6y5+di9bAuGs3lxcFmBgJuYu5uMmpG FX0A== X-Gm-Message-State: AElRT7EcSclWdRK+7TMuLpMTuYam8fKIt12jfIa9/WCWle5/skh/428A tgJIuNC8f5MVflqFtaIzKNbQhjr2 X-Received: by 10.223.142.164 with SMTP id q33mr30172991wrb.72.1522071424338; Mon, 26 Mar 2018 06:37:04 -0700 (PDT) Received: from 640k.lan (94-36-194-48.adsl-ull.clienti.tiscali.it. [94.36.194.48]) by smtp.gmail.com with ESMTPSA id g186sm6710105wmd.41.2018.03.26.06.37.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 06:37:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 26 Mar 2018 15:36:42 +0200 Message-Id: <1522071403-52486-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1522071403-52486-1-git-send-email-pbonzini@redhat.com> References: <1522071403-52486-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PULL 15/16] 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: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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 Message-Id: <20180323152948.27048-1-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini --- chardev/char-fe.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) -- 1.8.3.1 diff --git a/chardev/char-fe.c b/chardev/char-fe.c index 392db78..b1f228e 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) { + goto unavailable; + } - if (d->mux_cnt >= MAX_MUX) { + 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;