From patchwork Thu Jul 9 09:29:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Christophe Dubois X-Patchwork-Id: 493342 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 77186140775 for ; Thu, 9 Jul 2015 19:30:22 +1000 (AEST) Received: from localhost ([::1]:38646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZD89s-0005or-Ei for incoming@patchwork.ozlabs.org; Thu, 09 Jul 2015 05:30:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZD89X-0005SW-Mu for qemu-devel@nongnu.org; Thu, 09 Jul 2015 05:30:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZD89U-0003mX-A0 for qemu-devel@nongnu.org; Thu, 09 Jul 2015 05:29:59 -0400 Received: from zose-mta03.web4all.fr ([185.49.20.44]:35574) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZD89U-0003lg-3L for qemu-devel@nongnu.org; Thu, 09 Jul 2015 05:29:56 -0400 Received: from localhost (localhost [127.0.0.1]) by zose-mta03.web4all.fr (Postfix) with ESMTP id 2FDB740EA9 for ; Thu, 9 Jul 2015 11:29:55 +0200 (CEST) Received: from zose-mta03.web4all.fr ([127.0.0.1]) by localhost (zose-mta03.web4all.fr [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id zVl5HOhkoant; Thu, 9 Jul 2015 11:29:54 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zose-mta03.web4all.fr (Postfix) with ESMTP id CD4C8410A8; Thu, 9 Jul 2015 11:29:54 +0200 (CEST) X-Virus-Scanned: amavisd-new at zose-mta-03.w4a.fr Received: from zose-mta03.web4all.fr ([127.0.0.1]) by localhost (zose-mta03.web4all.fr [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id pLHZwYiGxgnT; Thu, 9 Jul 2015 11:29:54 +0200 (CEST) Received: from jcd-U31SG.home (LPuteaux-656-1-242-167.w82-127.abo.wanadoo.fr [82.127.95.167]) by zose-mta03.web4all.fr (Postfix) with ESMTPSA id 887D340EA9; Thu, 9 Jul 2015 11:29:54 +0200 (CEST) From: Jean-Christophe Dubois To: qemu-devel@nongnu.org Date: Thu, 9 Jul 2015 11:29:52 +0200 Message-Id: <1436434192-16930-1-git-send-email-jcd@tribudubois.net> X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.49.20.44 Cc: Jean-Christophe Dubois Subject: [Qemu-devel] [PATCH for-2.4] i.MX: Fix UART driver to work with unitialized "chardev" device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The "chardev" property initialisation might failed (for example because there is not enough chardev handled by Qemu). The serial device emulator need to be able to "work" with an uninitialized (NULL) "chardev" device pointer. This patch add some test on the "chardev" pointer value before using it. Signed-off-by: Jean-Christophe Dubois Reviewed-by: Peter Crosthwaite --- hw/char/imx_serial.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/char/imx_serial.c b/hw/char/imx_serial.c index f3fbc77..383e50c 100644 --- a/hw/char/imx_serial.c +++ b/hw/char/imx_serial.c @@ -203,7 +203,9 @@ static uint64_t imx_serial_read(void *opaque, hwaddr offset, s->usr2 &= ~USR2_RDR; s->uts1 |= UTS1_RXEMPTY; imx_update(s); - qemu_chr_accept_input(s->chr); + if (s->chr) { + qemu_chr_accept_input(s->chr); + } } return c; @@ -290,7 +292,9 @@ static void imx_serial_write(void *opaque, hwaddr offset, } if (value & UCR2_RXEN) { if (!(s->ucr2 & UCR2_RXEN)) { - qemu_chr_accept_input(s->chr); + if (s->chr) { + qemu_chr_accept_input(s->chr); + } } } s->ucr2 = value & 0xffff;