From patchwork Mon Mar 26 13:36:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 132403 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp3860324ljb; Mon, 26 Mar 2018 06:43:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELvCuEfCVSNMpyKEQxrzcuzJLeiAWxtiRvSw4vjfCQJa0S/J3X/S4D1F1l0tSR6BQ0Ukwdvj X-Received: by 10.55.166.215 with SMTP id p206mr56830279qke.312.1522071836965; Mon, 26 Mar 2018 06:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522071836; cv=none; d=google.com; s=arc-20160816; b=B9B92Ss5lotjpz9s1MGuuiqo11UiEs9UR1TmMWuZFECBL430EEqIAkgE4GuN6/X2hH YSt+wFRbnG8UfYu5Lnzz0j/a8xqfsqOnFL0R9eC6Bdg3dlglCTNhU0/LlS3eKyOOJuil 0pb8SxYUphXcsiWE5AubKsAGtp/3ek0h2tUNcZhs/+1kno+whI9nE+RtWrkSPc+8wKIA X1tP+24JgdcdxvPXb8jaKJClfAmLB99YM0uSE77Jk9CjP2KwTEhlrd9HO217bE3bVNke IYmA/4zVvKJj6gqXvQKpbKBKjwav7WX7mObKGgDhruKInGcGq6JVHY4wAQCRqcdaYmJN VeVw== 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=qL2bgJJbnk3TW1qAwN/FJhCE59hJkf/wNPD7z2Wp0EU=; b=d1woe4Dqzb15nFYy8vUalc7jRBSE63BM0rHWd2sEOdq4DrizvGtUoFhtzc21lEgfO8 1syKfgD6sVl+uAQRmsDozUZd5gToH9HV8o/HzZlAP8c5zSzbiwEGcb6vLjxQ/7T/quoW 04zmG4lFmT4LwyKztuYbanO7uPmU8PBMikjDduApRk5VAtOEOTl6mx0ugvgBMdUm1EIc uyurgq+g54VdIiFKwL4tAObeekuINR4/9WYjQCLopuacfgV/HwkFIGBO6j/kTue0oQul DuAzL8qilVbMzDm4ayDFxTzgikj6/4teoU1IATSYrqwfPCC9+3uSkRm1Q+vmuiapxa3M MPYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=n6ls8pmd; 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 o3si304433qto.302.2018.03.26.06.43.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 26 Mar 2018 06:43:56 -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=n6ls8pmd; 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]:56833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0SPk-0004Kq-B3 for patch@linaro.org; Mon, 26 Mar 2018 09:43:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0SJ6-0006eF-3G for qemu-devel@nongnu.org; Mon, 26 Mar 2018 09:37:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0SJ3-00070R-Ce for qemu-devel@nongnu.org; Mon, 26 Mar 2018 09:37:04 -0400 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:42063) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f0SJ3-0006zw-5g for qemu-devel@nongnu.org; Mon, 26 Mar 2018 09:37:01 -0400 Received: by mail-wr0-x22f.google.com with SMTP id s18so18939419wrg.9 for ; Mon, 26 Mar 2018 06:37:01 -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=qL2bgJJbnk3TW1qAwN/FJhCE59hJkf/wNPD7z2Wp0EU=; b=n6ls8pmdrBe8qB78YLccMLzD/C8abC8XUNIR7783RoQRH6+Lk2/ZJttWLpQBt092Vk ifUtmuW7FrFsVkFV3UxYkDUTAcAzhGKossolRZBZ1DErkWk6x28FdGpnDmQEXDbzPF9G UW5FPrnJz6pIcg39hBkQ8A2PqcbxE/fRJR0Fc5c0juv+w0xLEhjfFJ/rLNx6nUkTTgWb wnkFkE7N9ABAkfexvw1U3l7m0Rdp7oGbOy8wj80hWlZSfaWlL1iYSECTvfoUy5kYdrfU t/bg8j366Habf/SwX/tHdBR5hw3A6fE2AHQ4U+oveTlGGcZaq6Fb/g8l4yypv4dk/vtM 7STw== 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=qL2bgJJbnk3TW1qAwN/FJhCE59hJkf/wNPD7z2Wp0EU=; b=KNzzuXw1EPRFfqi9/WmP/tzPPoEzhLj+kbMK5PrAqBYPSPSg2FB2KKaT/lTDE4/U+D N5MtyveBKEEwAVObjuHc31qjwtLZKw3jNX1Q8ZhiaykojmDpZpwQ7C4v34O61h4suCtC 8WLgKAzXU9d92icg/Ljz0Jakv0UC3Rxm1ABOEWXWR5fPPovHzhpuhTuqsNcmqFvvyE0o qWVB6v//2Y1fcqZm+c8L9Ayw7r9omYg/YNMmgf0ldPgOQV5SSyeakH8MTUOEBzpKJNXr s/ojIL9sW5NHc0d9F8vNK6D3P7xQAjhbgYy4jDIYRwdgPH6dPj2S3AB6k1r3J3HI5isX gp9g== X-Gm-Message-State: AElRT7EHOpFGeKQm8fBv/mUTQ8LZgPOOYrm8Bq4w+AOxPY3gsIux/9I7 Ee47+PIPpWwXx8w8P79eQk4xg090 X-Received: by 10.223.176.7 with SMTP id f7mr30161240wra.257.1522071419662; Mon, 26 Mar 2018 06:36:59 -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.36.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 06:36:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 26 Mar 2018 15:36:38 +0200 Message-Id: <1522071403-52486-12-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::22f Subject: [Qemu-devel] [PULL 11/16] tcg: Really fix cpu_io_recompile 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: Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson We have confused the number of instructions that have been executed in the TB with the number of instructions needed to repeat the I/O instruction. We have used cpu_restore_state_from_tb, which means that the guest pc is pointing to the I/O instruction. The only time the answer to the later question is not 1 is when MIPS or SH4 need to re-execute the branch for the delay slot as well. We must rely on cpu->cflags_next_tb to generate the next TB, as otherwise we have a race condition with other guest cpus within the TB cache. Fixes: 0790f86861079b1932679d0f011e431aaf4ee9e2 Signed-off-by: Richard Henderson Message-Id: <20180319031545.29359-1-richard.henderson@linaro.org> Tested-by: Pavel Dovgalyuk Signed-off-by: Paolo Bonzini --- accel/tcg/translate-all.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) -- 1.8.3.1 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 5ad1b91..d419060 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1728,8 +1728,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) CPUArchState *env = cpu->env_ptr; #endif TranslationBlock *tb; - uint32_t n, flags; - target_ulong pc, cs_base; + uint32_t n; tb_lock(); tb = tb_find_pc(retaddr); @@ -1737,44 +1736,33 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) cpu_abort(cpu, "cpu_io_recompile: could not find TB for pc=%p", (void *)retaddr); } - n = cpu->icount_decr.u16.low + tb->icount; cpu_restore_state_from_tb(cpu, tb, retaddr); - /* Calculate how many instructions had been executed before the fault - occurred. */ - n = n - cpu->icount_decr.u16.low; - /* Generate a new TB ending on the I/O insn. */ - n++; + /* On MIPS and SH, delay slot instructions can only be restarted if they were already the first instruction in the TB. If this is not the first instruction in a TB then re-execute the preceding branch. */ + n = 1; #if defined(TARGET_MIPS) - if ((env->hflags & MIPS_HFLAG_BMASK) != 0 && n > 1) { + if ((env->hflags & MIPS_HFLAG_BMASK) != 0 + && env->active_tc.PC != tb->pc) { env->active_tc.PC -= (env->hflags & MIPS_HFLAG_B16 ? 2 : 4); cpu->icount_decr.u16.low++; env->hflags &= ~MIPS_HFLAG_BMASK; + n = 2; } #elif defined(TARGET_SH4) if ((env->flags & ((DELAY_SLOT | DELAY_SLOT_CONDITIONAL))) != 0 - && n > 1) { + && env->pc != tb->pc) { env->pc -= 2; cpu->icount_decr.u16.low++; env->flags &= ~(DELAY_SLOT | DELAY_SLOT_CONDITIONAL); + n = 2; } #endif - /* This should never happen. */ - if (n > CF_COUNT_MASK) { - cpu_abort(cpu, "TB too big during recompile"); - } - pc = tb->pc; - cs_base = tb->cs_base; - flags = tb->flags; - tb_phys_invalidate(tb, -1); - - /* Execute one IO instruction without caching - instead of creating large TB. */ - cpu->cflags_next_tb = curr_cflags() | CF_LAST_IO | CF_NOCACHE | 1; + /* Generate a new TB executing the I/O insn. */ + cpu->cflags_next_tb = curr_cflags() | CF_LAST_IO | n; if (tb->cflags & CF_NOCACHE) { if (tb->orig_tb) { @@ -1785,11 +1773,6 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) tb_remove(tb); } - /* Generate new TB instead of the current one. */ - /* FIXME: In theory this could raise an exception. In practice - we have already translated the block once so it's probably ok. */ - tb_gen_code(cpu, pc, cs_base, flags, curr_cflags() | CF_LAST_IO | n); - /* TODO: If env->pc != tb->pc (i.e. the faulting instruction was not * the first in the TB) then we end up generating a whole new TB and * repeating the fault, which is horribly inefficient. 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;