From patchwork Fri Jun 5 14:56:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 281291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64D5AC433E0 for ; Fri, 5 Jun 2020 14:58:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 300E320663 for ; Fri, 5 Jun 2020 14:58:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bOkS0o9m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 300E320663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhDnM-0006fv-Ci for qemu-devel@archiver.kernel.org; Fri, 05 Jun 2020 10:58:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhDlv-00040T-6O for qemu-devel@nongnu.org; Fri, 05 Jun 2020 10:56:39 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:56734 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jhDlq-0007Ug-4q for qemu-devel@nongnu.org; Fri, 05 Jun 2020 10:56:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591368993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B01+PXwqtW2w+mgzF4lWtNnz8r08mFsj/aZkGw7yJ8o=; b=bOkS0o9mOw9dThx5BqGtk21qQFyvRrTij3z3MUz0uQitRLHzhoDzHJ79zjNOTSd2FOzz1P LxU5Y3C+mzcNNe+F9gR+GXHqiRTV2tRvSk8SSYfzXj/Gl454eEYa33IRKq7OlhY2vIZs85 4DAngB+gEN12FElMqp2+YXTdMPaqVeY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-388-OWDkMchuPquNDLxA8YCAYQ-1; Fri, 05 Jun 2020 10:56:31 -0400 X-MC-Unique: OWDkMchuPquNDLxA8YCAYQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58C7E107ACF6; Fri, 5 Jun 2020 14:56:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-121.ams2.redhat.com [10.36.112.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23F8D579A3; Fri, 5 Jun 2020 14:56:30 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DB7461138466; Fri, 5 Jun 2020 16:56:25 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 15/16] sd/pxa2xx_mmci: Don't crash on pxa2xx_mmci_init() error Date: Fri, 5 Jun 2020 16:56:24 +0200 Message-Id: <20200605145625.2920920-16-armbru@redhat.com> In-Reply-To: <20200605145625.2920920-1-armbru@redhat.com> References: <20200605145625.2920920-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=armbru@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/05 03:27:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Maydell , berrange@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com, qemu-arm@nongnu.org, pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On error, pxa2xx_mmci_init() reports to stderr and returns NULL. Callers don't check for errors. Machines akita, borzoi, mainstone, spitz, terrier, tosa, and z2 crash shortly after, like this: $ qemu-system-aarch64 -M akita -drive if=sd,readonly=on qemu-system-aarch64: failed to init SD card: Cannot use read-only drive as SD card Segmentation fault (core dumped) Machines connex and verdex reach the check for orphaned drives first: $ aarch64-softmmu/qemu-system-aarch64 -M connex -drive if=sd,readonly=on -accel qtest qemu-system-aarch64: failed to init SD card: Cannot use read-only drive as SD card qemu-system-aarch64: -drive if=sd,readonly=on: machine type does not support if=sd,bus=0,unit=0 Make pxa2xx_mmci_init() fail cleanly right away. Cc: Andrzej Zaborowski Cc: Peter Maydell Cc: qemu-arm@nongnu.org Signed-off-by: Markus Armbruster --- hw/sd/pxa2xx_mmci.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c index 3407617afc..68bed24480 100644 --- a/hw/sd/pxa2xx_mmci.c +++ b/hw/sd/pxa2xx_mmci.c @@ -18,7 +18,6 @@ #include "hw/arm/pxa.h" #include "hw/sd/sd.h" #include "hw/qdev-properties.h" -#include "qemu/error-report.h" #include "qemu/log.h" #include "qemu/module.h" #include "trace.h" @@ -483,7 +482,6 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem, DeviceState *dev, *carddev; SysBusDevice *sbd; PXA2xxMMCIState *s; - Error *err = NULL; dev = qdev_new(TYPE_PXA2XX_MMCI); s = PXA2XX_MMCI(dev); @@ -496,16 +494,9 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem, /* Create and plug in the sd card */ carddev = qdev_new(TYPE_SD_CARD); - qdev_prop_set_drive_err(carddev, "drive", blk, &err); - if (err) { - error_reportf_err(err, "failed to init SD card: "); - return NULL; - } - qdev_realize_and_unref(carddev, qdev_get_child_bus(dev, "sd-bus"), &err); - if (err) { - error_reportf_err(err, "failed to init SD card: "); - return NULL; - } + qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal); + qdev_realize_and_unref(carddev, qdev_get_child_bus(dev, "sd-bus"), + &error_fatal); return s; }