From nobody Wed May 15 05:08:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556866966; cv=none; d=zoho.com; s=zohoarc; b=PVNyqSK8o4wMrF9IDFCQMf7zmapHqVOk1hbE1V8T/ZJwqYaLT5WzsoFi+2OL11X7rrnsiauoyhfjZhufwaFzANsJC/b2d2UpcCd/5dTCuy4zec/87J/1kCGPPeubPbOf3ntz/yFuh/8mZJh7uPYGsBNMT3Y0Ey04YJ/OUO/0Fdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556866966; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=1mmsY6AvBgNPfREd35t94zsPLPYDZzlNj60UyghtFVQ=; b=GoWuTRh6dRYHkijKuWfOksFrWf/gQPSUc0hDmYkPisAcei1n8pylUKDWjAbItyPaEgDkhMHKMKfk96lX0kIzc+xQg+mPgrIwgKkx06zxnGx5REmFACoyoQWJIRJ140hRTYRj6UwUrCOld31SnKgmCeURQrtidL3tdEVVlRQAc9E= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556866966293893.6467849359934; Fri, 3 May 2019 00:02:46 -0700 (PDT) Received: from localhost ([127.0.0.1]:35643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSDI-0005sg-5B for importer@patchew.org; Fri, 03 May 2019 03:02:32 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSAq-0003n0-LC for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMSAp-0006EM-L3 for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44610) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMSAp-0006Dk-Ez for qemu-devel@nongnu.org; Fri, 03 May 2019 02:59:59 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 902A030A769E; Fri, 3 May 2019 06:59:57 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0206C5D70A; Fri, 3 May 2019 06:59:54 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1D5601751C; Fri, 3 May 2019 08:59:54 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 08:59:48 +0200 Message-Id: <20190503065954.17069-2-kraxel@redhat.com> In-Reply-To: <20190503065954.17069-1-kraxel@redhat.com> References: <20190503065954.17069-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 03 May 2019 06:59:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/7] usb-mtp: fix string length for filename when writing metadata 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: Gerd Hoffmann , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Daniel P. Berrang=C3=A9 The ObjectInfo 'length' field provides the length of the wide character string filename. This is then converted to a multi-byte character string. This may have a different byte count to the wide character string. We should use the C string length of the multi-byte string instead. Signed-off-by: Daniel P. Berrang=C3=A9 Message-id: 20190415154503.6758-2-berrange@redhat.com Signed-off-by: Gerd Hoffmann --- hw/usb/dev-mtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 99548b012d1f..6b7d1296e430 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -1721,7 +1721,7 @@ static void usb_mtp_write_metadata(MTPState *s, uint6= 4_t dlen) return; } =20 - o =3D usb_mtp_object_lookup_name(p, filename, dataset->length); + o =3D usb_mtp_object_lookup_name(p, filename, -1); if (o !=3D NULL) { next_handle =3D o->handle; } --=20 2.18.1 From nobody Wed May 15 05:08:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556867082; cv=none; d=zoho.com; s=zohoarc; b=QzGS/Ct3gkx1I2KmmrVJmxXfwFKLobGTl1iE2Jk6ijzCL6pmeTR5a63M4SdI0iS0C/s8FPGZncOoUlSGobyJ0MAzN50l8k1cpibbuZF/xjimARNCywUbXgBGKIyN+GSmN1rBaxiOGkdv/kytS9Xcmee2r6MQhIzWiT1qw8FE9kE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556867082; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=B+mB4qHg5CxSXpLpKWt1yMTZITPSQ00XR3NtUpUjxHM=; b=HV4JidK35ionIARbw+Rrys3bHMran4eUF2Tj/Qqq3sVS2HTOMjrUTqFbqQ2+D7SUtrz2zidvDZDw6uqkGTGZ0R2FiDf4C/02LeuccNhuDbSmswHSFA8+I0UiJruAEq9b6ZZLcjwjU2AKZPcG2zZ9kQ0rAb0jq5CuB8bzIq+CLi0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556867082760684.5468853556658; Fri, 3 May 2019 00:04:42 -0700 (PDT) Received: from localhost ([127.0.0.1]:35659 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSFL-0007al-Nq for importer@patchew.org; Fri, 03 May 2019 03:04:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38133) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSAq-0003n1-S9 for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMSAp-0006Ee-Nw for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMSAp-0006Dt-Ex for qemu-devel@nongnu.org; Fri, 03 May 2019 02:59:59 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF27430BC73A; Fri, 3 May 2019 06:59:57 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 027671001E91; Fri, 3 May 2019 06:59:54 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 2B0B61752B; Fri, 3 May 2019 08:59:54 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 08:59:49 +0200 Message-Id: <20190503065954.17069-3-kraxel@redhat.com> In-Reply-To: <20190503065954.17069-1-kraxel@redhat.com> References: <20190503065954.17069-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 03 May 2019 06:59:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/7] usb-mtp: fix alignment of access of ObjectInfo filename field 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: Gerd Hoffmann , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Daniel P. Berrang=C3=A9 The ObjectInfo struct's "filename" field is following a uint8_t field in a packed struct and thus has bad alignment for a 16-bit field. Switch the field to to uint8_t and use the helper function for accessing unaligned 16-bit data. Note that although the MTP spec specifies big endian, when transported over the USB protocol, data is little endian. Signed-off-by: Daniel P. Berrang=C3=A9 Message-id: 20190415154503.6758-4-berrange@redhat.com Signed-off-by: Gerd Hoffmann --- hw/usb/dev-mtp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 6b7d1296e430..963449ec7de8 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -226,7 +226,7 @@ typedef struct { uint32_t assoc_desc; uint32_t seq_no; /*unused*/ uint8_t length; /*part of filename field*/ - uint16_t filename[0]; + uint8_t filename[0]; /* UTF-16 encoded */ char date_created[0]; /*unused*/ char date_modified[0]; /*unused*/ char keywords[0]; /*unused*/ @@ -1551,7 +1551,7 @@ static void usb_mtp_cancel_packet(USBDevice *dev, USB= Packet *p) fprintf(stderr, "%s\n", __func__); } =20 -static char *utf16_to_str(uint8_t len, uint16_t *arr) +static char *utf16_to_str(uint8_t len, uint8_t *str16) { wchar_t *wstr =3D g_new0(wchar_t, len + 1); int count, dlen; @@ -1559,7 +1559,7 @@ static char *utf16_to_str(uint8_t len, uint16_t *arr) =20 for (count =3D 0; count < len; count++) { /* FIXME: not working for surrogate pairs */ - wstr[count] =3D (wchar_t)arr[count]; + wstr[count] =3D lduw_le_p(str16 + (count * 2)); } wstr[count] =3D 0; =20 --=20 2.18.1 From nobody Wed May 15 05:08:11 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556867307; cv=none; d=zoho.com; s=zohoarc; b=BsED+dtMv+2+9hqwcBQuJ4qFb9SKeZ+9brvEU24ZV2/xsAYHgmW/zJeLtj3whCZEwnrFPDtJy95I49AdCli5gNd8LamyN9lAlhv7WEyLJ7qQFB4UpzYFXoA6+P9fv6j+ygo+QSkKJMxz6H8Bn7L1OCWGKrivXxR4jVF7he135k0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556867307; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=V5o5m8O5n769YkTgmSgA69ECVqSjdswFCVUb/2HOfe0=; b=fEDxyaipHQOEMus+N1mWsYt+XzwstLSP7CAakFGcCF8IZvt51gYmbiO+FzWPwBPJkHJ7aTc0X02FP3I3XmFPQ3y3/KysnGTfU1DH3iJsN+MRuOqm5XsISz4yFd3t6TWRcmGjIaxv2gufZrwkXXVpeiCpHvCn9KGbtrIOYXNWTcI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556867307955785.209510363231; Fri, 3 May 2019 00:08:27 -0700 (PDT) Received: from localhost ([127.0.0.1]:35723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSIo-0001jN-Df for importer@patchew.org; Fri, 03 May 2019 03:08:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSAt-0003nw-Bn for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMSAs-0006Gp-DQ for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMSAs-0006GU-8M for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:02 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B92C30C021A; Fri, 3 May 2019 07:00:00 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0203179B5; Fri, 3 May 2019 06:59:54 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 332A717535; Fri, 3 May 2019 08:59:54 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 08:59:50 +0200 Message-Id: <20190503065954.17069-4-kraxel@redhat.com> In-Reply-To: <20190503065954.17069-1-kraxel@redhat.com> References: <20190503065954.17069-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 03 May 2019 07:00:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/7] usb-mtp: change default to success for usb_mtp_update_object 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: Bandan Das , Gerd Hoffmann , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Bandan Das Commit c5ead51f90cf (usb-mtp: return incomplete transfer on a lstat failure) checks if lstat succeeded when updating attributes of a file. However, it also changed behavior to return an error by default. This is incorrect because for smaller file sizes, Qemu will attempt to write the file in one go and there won't be an object for it. Fixes: c5ead51f90cf Signed-off-by: Bandan Das Message-id: jpgwojv9pwv.fsf@linux.bootlegged.copy Signed-off-by: Gerd Hoffmann --- hw/usb/dev-mtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 963449ec7de8..d90b336d53f4 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -1587,7 +1587,7 @@ done: =20 static int usb_mtp_update_object(MTPObject *parent, char *name) { - int ret =3D -1; + int ret =3D 0; =20 MTPObject *o =3D usb_mtp_object_lookup_name(parent, name, strlen(name)); --=20 2.18.1 From nobody Wed May 15 05:08:11 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556866990; cv=none; d=zoho.com; s=zohoarc; b=eh9yKvAdvp3b+8dV/JymR8ZZZetw5atFtBj2NgboRzmYOOMd+BGNlS8Jvoukick6Bbn+rOM/82/AoQ8WWzcdRiw0myVXMNiFiU08H406obfvbnXsqAQG2dwvg3D8BIji+RoC+mGN0kTp7fFKMXFk4LmQ8wDJNPOC2LnIdxfgniI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556866990; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=YIAg5X/9u3wV1gqxWnOPUSwttAaXL836nUBjWehp1tg=; b=iGStFkVQqRwEP9L64tMxjxoSZgHFc4GwlTLOc1hdW082o2iP1p25VKI2F0QrWwOvbrdqEqahHhW2cOk/ytf6t3YGh+puG6xb74XEUuYzHLr3pkawUacmCjQ4ZjbjmCpbN2uyLwp1Ctnirj8+cks4eCw4+psAoc7bx5PWOyvq0tg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556866990062627.7247299713512; Fri, 3 May 2019 00:03:10 -0700 (PDT) Received: from localhost ([127.0.0.1]:35641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSD8-0005mM-Kh for importer@patchew.org; Fri, 03 May 2019 03:02:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSAr-0003nL-7Z for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMSAp-0006EZ-Mb for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMSAp-0006E6-FB for qemu-devel@nongnu.org; Fri, 03 May 2019 02:59:59 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C232A30BC118; Fri, 3 May 2019 06:59:57 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 027131001E79; Fri, 3 May 2019 06:59:54 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 3B72417536; Fri, 3 May 2019 08:59:54 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 08:59:51 +0200 Message-Id: <20190503065954.17069-5-kraxel@redhat.com> In-Reply-To: <20190503065954.17069-1-kraxel@redhat.com> References: <20190503065954.17069-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 03 May 2019 06:59:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/7] usb/xhci: avoid trigger assertion if guest write wrong epid 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: Longpeng , Gonglei , Gerd Hoffmann , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Longpeng we found the following core in our environment: 0 0x00007fc6b06c2237 in raise () 1 0x00007fc6b06c3928 in abort () 2 0x00007fc6b06bb056 in __assert_fail_base () 3 0x00007fc6b06bb102 in __assert_fail () 4 0x0000000000702e36 in xhci_kick_ep (...) 5 0x000000000047897a in memory_region_write_accessor (...) 6 0x000000000047767f in access_with_adjusted_size (...) 7 0x000000000047944d in memory_region_dispatch_write (...) (mr=3Dmr@entry=3D0x7fc6a0138df0, addr=3Daddr@entry=3D156, data=3D1648892416, size=3Dsize@entry=3D4, attrs=3Dattrs@entry=3D...) 8 0x000000000042df17 in address_space_write_continue (...) 10 0x000000000043084d in address_space_rw (...) 11 0x000000000047451b in kvm_cpu_exec (cpu=3Dcpu@entry=3D0x1ab11b0) 12 0x000000000045dcf5 in qemu_kvm_cpu_thread_fn (arg=3D0x1ab11b0) 13 0x0000000000870631 in qemu_thread_start (args=3Dargs@entry=3D0x1acfb50) 14 0x00000000008959a7 in thread_entry_for_hotfix (pthread_cb=3D) 15 0x00007fc6b0a60dd5 in start_thread () 16 0x00007fc6b078a59d in clone () (gdb) f 5 5 0x000000000047897a in memory_region_write_accessor (...) 529 mr->ops->write(mr->opaque, addr, tmp, size); (gdb) p /x tmp $9 =3D 0x62481a00 <-- last byte 0x00 is @epid xhci_doorbell_write() already check the upper bound of @slotid an @epid, it also need to check the lower bound. Cc: Gonglei Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Longpeng Tested-by: Philippe Mathieu-Daud=C3=A9 Message-id: 1556605301-44112-1-git-send-email-longpeng2@huawei.com [ kraxel: fixed typo in subject line ] Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index ec28bee31963..d8472b4fea7f 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -3137,7 +3137,7 @@ static void xhci_doorbell_write(void *ptr, hwaddr reg, streamid =3D (val >> 16) & 0xffff; if (reg > xhci->numslots) { DPRINTF("xhci: bad doorbell %d\n", (int)reg); - } else if (epid > 31) { + } else if (epid =3D=3D 0 || epid > 31) { DPRINTF("xhci: bad doorbell %d write: 0x%x\n", (int)reg, (uint32_t)val); } else { --=20 2.18.1 From nobody Wed May 15 05:08:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556867223; cv=none; d=zoho.com; s=zohoarc; b=RZ9kcOTU3OwSji9n/yrQWdOQAwAOsXslNdnC3Ir/EPqzaTGndYdre8CASHSznuhiBQiz/5KVaxJJCK0S3tRibg9RUpwGT8pnS4wzhgqjCSEtzQlGXvB62kbgx+X3GBgmDtP19UtXnzHcSSjq5NYCVkOn0V7l0RlhOxRXS0R7KdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556867223; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+8OxB4wEDs5gDWNY6qOhQI0qLbohMOPAiM5IZVPLLoI=; b=nSgIOTB4KPzOZbwICDcGDHt+mFUZGiBPsUAFKMHTJGrfXdncn+dcbjwBtuXD7JdaWcgaq54wWvv4tGXdFblgBx1H1O3qR7XUucc628Kteo+q8b6rgYrE73z8MMzu0QCPDx5mS6mtkYj9iM72kyQ6uuhSIZOLwaYxWCm/b3MAiIo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556867223880924.0728592510068; Fri, 3 May 2019 00:07:03 -0700 (PDT) Received: from localhost ([127.0.0.1]:35712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSHa-0000vg-Pc for importer@patchew.org; Fri, 03 May 2019 03:06:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSAr-0003nO-MC for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMSAq-0006Ep-7g for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54280) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMSAp-0006EF-Vj for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:00 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E48B630C0210; Fri, 3 May 2019 06:59:58 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66CF4629DC; Fri, 3 May 2019 06:59:58 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 43DAA17538; Fri, 3 May 2019 08:59:54 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 08:59:52 +0200 Message-Id: <20190503065954.17069-6-kraxel@redhat.com> In-Reply-To: <20190503065954.17069-1-kraxel@redhat.com> References: <20190503065954.17069-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 03 May 2019 06:59:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/7] hw/usb/hcd-ohci: Do not use PCI functions with sysbus devices in ohci_die() 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: Thomas Huth , Gerd Hoffmann , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Thomas Huth The ohci_die() function always assumes to be running with a PCI OHCI controller and calls the PCI-specific functions pci_set_word(). However, this function might also get called for the sysbus OHCI devices, so it likely fails in that case. To fix this issue, change the code now, so that there are two implementations now, one for sysbus and one for PCI, and use the right function via a function pointer in the OHCIState structure. Signed-off-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20190419075625.24251-2-thuth@redhat.com Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ohci.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 81cf5ab7a5a7..6d3f556989fb 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -52,7 +52,7 @@ typedef struct OHCIPort { uint32_t ctrl; } OHCIPort; =20 -typedef struct { +typedef struct OHCIState { USBBus bus; qemu_irq irq; MemoryRegion mem; @@ -108,6 +108,7 @@ typedef struct { uint32_t async_td; bool async_complete; =20 + void (*ohci_die)(struct OHCIState *ohci); } OHCIState; =20 /* Host Controller Communications Area */ @@ -302,7 +303,10 @@ struct ohci_iso_td { =20 #define OHCI_HRESET_FSBIR (1 << 0) =20 -static void ohci_die(OHCIState *ohci); +static void ohci_die(OHCIState *ohci) +{ + ohci->ohci_die(ohci); +} =20 /* Update IRQ levels */ static inline void ohci_intr_update(OHCIState *ohci) @@ -1854,13 +1858,14 @@ static USBBusOps ohci_bus_ops =3D { =20 static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, uint32_t num_ports, dma_addr_t localmem_base, - char *masterbus, uint32_t firstport, - AddressSpace *as, Error **errp) + char *masterbus, uint32_t firstport, AddressSpac= e *as, + void (*ohci_die_fn)(struct OHCIState *), Error *= *errp) { Error *err =3D NULL; int i; =20 ohci->as =3D as; + ohci->ohci_die =3D ohci_die_fn; =20 if (num_ports > OHCI_MAX_PORTS) { error_setg(errp, "OHCI num-ports=3D%u is too big (limit is %u port= s)", @@ -1933,18 +1938,28 @@ typedef struct { uint32_t firstport; } OHCIPCIState; =20 -/** A typical O/EHCI will stop operating, set itself into error state - * (which can be queried by MMIO) and will set PERR in its config - * space to signal that it got an error +/** + * A typical OHCI will stop operating and set itself into error state + * (which can be queried by MMIO) to signal that it got an error. */ -static void ohci_die(OHCIState *ohci) +static void ohci_sysbus_die(struct OHCIState *ohci) { - OHCIPCIState *dev =3D container_of(ohci, OHCIPCIState, state); - trace_usb_ohci_die(); =20 ohci_set_interrupt(ohci, OHCI_INTR_UE); ohci_bus_stop(ohci); +} + +/** + * A typical PCI OHCI will additionally set PERR in its configspace to + * signal that it got an error. + */ +static void ohci_pci_die(struct OHCIState *ohci) +{ + OHCIPCIState *dev =3D container_of(ohci, OHCIPCIState, state); + + ohci_sysbus_die(ohci); + pci_set_word(dev->parent_obj.config + PCI_STATUS, PCI_STATUS_DETECTED_PARITY); } @@ -1959,7 +1974,7 @@ static void usb_ohci_realize_pci(PCIDevice *dev, Erro= r **errp) =20 usb_ohci_init(&ohci->state, DEVICE(dev), ohci->num_ports, 0, ohci->masterbus, ohci->firstport, - pci_get_address_space(dev), &err); + pci_get_address_space(dev), ohci_pci_die, &err); if (err) { error_propagate(errp, err); return; @@ -2023,7 +2038,7 @@ static void ohci_realize_pxa(DeviceState *dev, Error = **errp) =20 usb_ohci_init(&s->ohci, dev, s->num_ports, s->dma_offset, s->masterbus, s->firstport, - &address_space_memory, &err); + &address_space_memory, ohci_sysbus_die, &err); if (err) { error_propagate(errp, err); return; --=20 2.18.1 From nobody Wed May 15 05:08:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556867085; cv=none; d=zoho.com; s=zohoarc; b=dT4xQ+ufFZaOmPMpSAx9pxl6d7W3eS0avLjSAyJmZ8BB8ORY2N9r6AsiG2kA+SqciqoWFRNcthdYpng8fOdFJdSUzkEOQYaqWE9M4aWhxzDy+mcDkW8qen2qpB5OS3dNnYDdXTdUVU8M4VgJz1v1R/aiTw98Fogi0vaSO0ritIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556867085; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=lFEI/goSp53HFNGPoju75g+MKL2bqNf/gSdn37PGiKA=; b=R5Gg94TyNDHuYZ+WtwaC+zQFWTo0vkcBrHVKRYp7BCw5MSyuM2TnwMwccP1aIJDmPiBgTGqYn9Ismz8Pk+d+VUAbovS++4w1RKM8b1t71NgXJsX2DHKvXljhO0qlO0578+/Fi+7u1FCDVAwlQK6qWe5I1gOAVlBkx+Mvh/1FAxk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556867085545801.4680067063756; Fri, 3 May 2019 00:04:45 -0700 (PDT) Received: from localhost ([127.0.0.1]:35657 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSFJ-0007YX-8H for importer@patchew.org; Fri, 03 May 2019 03:04:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSAx-0003oO-4r for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMSAu-0006IU-BU for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54294) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMSAu-0006II-1o for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:04 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8046A30C021B; Fri, 3 May 2019 07:00:01 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 687C75C642; Fri, 3 May 2019 06:59:58 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 53EAE1753A; Fri, 3 May 2019 08:59:54 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 08:59:53 +0200 Message-Id: <20190503065954.17069-7-kraxel@redhat.com> In-Reply-To: <20190503065954.17069-1-kraxel@redhat.com> References: <20190503065954.17069-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 03 May 2019 07:00:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/7] hw/usb/hcd-ohci: Move PCI-related code into a separate file 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: Thomas Huth , Gerd Hoffmann , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Thomas Huth Some machines (like the pxa2xx-based ARM machines) only have a sysbus OHCI controller, but no PCI. With the new Kconfig-style build system, it will soon be possible to create QEMU binaries that only contain such PCI-less machines. However, the two OHCI controllers, for sysbus and for PCI, are currently both located in one file, so the PCI code is still required for linking here. Move the OHCI-PCI device code into a separate file, so that it is possible to use the sysbus OHCI device also without the PCI dependency. Signed-off-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20190419075625.24251-3-thuth@redhat.com Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ohci.h | 104 ++++++++++++++++++++ hw/usb/hcd-ohci-pci.c | 163 +++++++++++++++++++++++++++++++ hw/usb/hcd-ohci.c | 216 ++---------------------------------------- hw/sh4/Kconfig | 2 +- hw/usb/Kconfig | 6 +- hw/usb/Makefile.objs | 1 + 6 files changed, 284 insertions(+), 208 deletions(-) create mode 100644 hw/usb/hcd-ohci.h create mode 100644 hw/usb/hcd-ohci-pci.c diff --git a/hw/usb/hcd-ohci.h b/hw/usb/hcd-ohci.h new file mode 100644 index 000000000000..16e3f1e13a31 --- /dev/null +++ b/hw/usb/hcd-ohci.h @@ -0,0 +1,104 @@ +/* + * QEMU USB OHCI Emulation + * Copyright (c) 2004 Gianni Tedesco + * Copyright (c) 2006 CodeSourcery + * Copyright (c) 2006 Openedhand Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef HCD_OHCI_H +#define HCD_OHCI_H + +#include "sysemu/dma.h" + +/* Number of Downstream Ports on the root hub: */ +#define OHCI_MAX_PORTS 15 + +typedef struct OHCIPort { + USBPort port; + uint32_t ctrl; +} OHCIPort; + +typedef struct OHCIState { + USBBus bus; + qemu_irq irq; + MemoryRegion mem; + AddressSpace *as; + uint32_t num_ports; + const char *name; + + QEMUTimer *eof_timer; + int64_t sof_time; + + /* OHCI state */ + /* Control partition */ + uint32_t ctl, status; + uint32_t intr_status; + uint32_t intr; + + /* memory pointer partition */ + uint32_t hcca; + uint32_t ctrl_head, ctrl_cur; + uint32_t bulk_head, bulk_cur; + uint32_t per_cur; + uint32_t done; + int32_t done_count; + + /* Frame counter partition */ + uint16_t fsmps; + uint8_t fit; + uint16_t fi; + uint8_t frt; + uint16_t frame_number; + uint16_t padding; + uint32_t pstart; + uint32_t lst; + + /* Root Hub partition */ + uint32_t rhdesc_a, rhdesc_b; + uint32_t rhstatus; + OHCIPort rhport[OHCI_MAX_PORTS]; + + /* PXA27x Non-OHCI events */ + uint32_t hstatus; + uint32_t hmask; + uint32_t hreset; + uint32_t htest; + + /* SM501 local memory offset */ + dma_addr_t localmem_base; + + /* Active packets. */ + uint32_t old_ctl; + USBPacket usb_packet; + uint8_t usb_buf[8192]; + uint32_t async_td; + bool async_complete; + + void (*ohci_die)(struct OHCIState *ohci); +} OHCIState; + +extern const VMStateDescription vmstate_ohci_state; + +void usb_ohci_init(OHCIState *ohci, DeviceState *dev, uint32_t num_ports, + dma_addr_t localmem_base, char *masterbus, + uint32_t firstport, AddressSpace *as, + void (*ohci_die_fn)(struct OHCIState *), Error **errp); +void ohci_bus_stop(OHCIState *ohci); +void ohci_stop_endpoints(OHCIState *ohci); +void ohci_hard_reset(OHCIState *ohci); +void ohci_sysbus_die(struct OHCIState *ohci); + +#endif diff --git a/hw/usb/hcd-ohci-pci.c b/hw/usb/hcd-ohci-pci.c new file mode 100644 index 000000000000..e8f372c6ad30 --- /dev/null +++ b/hw/usb/hcd-ohci-pci.c @@ -0,0 +1,163 @@ +/* + * QEMU USB OHCI Emulation + * Copyright (c) 2004 Gianni Tedesco + * Copyright (c) 2006 CodeSourcery + * Copyright (c) 2006 Openedhand Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/hw.h" +#include "qapi/error.h" +#include "qemu/timer.h" +#include "hw/usb.h" +#include "hw/pci/pci.h" +#include "hw/sysbus.h" +#include "hw/qdev-dma.h" +#include "trace.h" +#include "hcd-ohci.h" + +#define TYPE_PCI_OHCI "pci-ohci" +#define PCI_OHCI(obj) OBJECT_CHECK(OHCIPCIState, (obj), TYPE_PCI_OHCI) + +typedef struct { + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + + OHCIState state; + char *masterbus; + uint32_t num_ports; + uint32_t firstport; +} OHCIPCIState; + +/** + * A typical PCI OHCI will additionally set PERR in its configspace to + * signal that it got an error. + */ +static void ohci_pci_die(struct OHCIState *ohci) +{ + OHCIPCIState *dev =3D container_of(ohci, OHCIPCIState, state); + + ohci_sysbus_die(ohci); + + pci_set_word(dev->parent_obj.config + PCI_STATUS, + PCI_STATUS_DETECTED_PARITY); +} + +static void usb_ohci_realize_pci(PCIDevice *dev, Error **errp) +{ + Error *err =3D NULL; + OHCIPCIState *ohci =3D PCI_OHCI(dev); + + dev->config[PCI_CLASS_PROG] =3D 0x10; /* OHCI */ + dev->config[PCI_INTERRUPT_PIN] =3D 0x01; /* interrupt pin A */ + + usb_ohci_init(&ohci->state, DEVICE(dev), ohci->num_ports, 0, + ohci->masterbus, ohci->firstport, + pci_get_address_space(dev), ohci_pci_die, &err); + if (err) { + error_propagate(errp, err); + return; + } + + ohci->state.irq =3D pci_allocate_irq(dev); + pci_register_bar(dev, 0, 0, &ohci->state.mem); +} + +static void usb_ohci_exit(PCIDevice *dev) +{ + OHCIPCIState *ohci =3D PCI_OHCI(dev); + OHCIState *s =3D &ohci->state; + + trace_usb_ohci_exit(s->name); + ohci_bus_stop(s); + + if (s->async_td) { + usb_cancel_packet(&s->usb_packet); + s->async_td =3D 0; + } + ohci_stop_endpoints(s); + + if (!ohci->masterbus) { + usb_bus_release(&s->bus); + } + + timer_del(s->eof_timer); + timer_free(s->eof_timer); +} + +static void usb_ohci_reset_pci(DeviceState *d) +{ + PCIDevice *dev =3D PCI_DEVICE(d); + OHCIPCIState *ohci =3D PCI_OHCI(dev); + OHCIState *s =3D &ohci->state; + + ohci_hard_reset(s); +} + +static Property ohci_pci_properties[] =3D { + DEFINE_PROP_STRING("masterbus", OHCIPCIState, masterbus), + DEFINE_PROP_UINT32("num-ports", OHCIPCIState, num_ports, 3), + DEFINE_PROP_UINT32("firstport", OHCIPCIState, firstport, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static const VMStateDescription vmstate_ohci =3D { + .name =3D "ohci", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_PCI_DEVICE(parent_obj, OHCIPCIState), + VMSTATE_STRUCT(state, OHCIPCIState, 1, vmstate_ohci_state, OHCISta= te), + VMSTATE_END_OF_LIST() + } +}; + +static void ohci_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + + k->realize =3D usb_ohci_realize_pci; + k->exit =3D usb_ohci_exit; + k->vendor_id =3D PCI_VENDOR_ID_APPLE; + k->device_id =3D PCI_DEVICE_ID_APPLE_IPID_USB; + k->class_id =3D PCI_CLASS_SERIAL_USB; + set_bit(DEVICE_CATEGORY_USB, dc->categories); + dc->desc =3D "Apple USB Controller"; + dc->props =3D ohci_pci_properties; + dc->hotpluggable =3D false; + dc->vmsd =3D &vmstate_ohci; + dc->reset =3D usb_ohci_reset_pci; +} + +static const TypeInfo ohci_pci_info =3D { + .name =3D TYPE_PCI_OHCI, + .parent =3D TYPE_PCI_DEVICE, + .instance_size =3D sizeof(OHCIPCIState), + .class_init =3D ohci_pci_class_init, + .interfaces =3D (InterfaceInfo[]) { + { INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, +}; + +static void ohci_pci_register_types(void) +{ + type_register_static(&ohci_pci_info); +} + +type_init(ohci_pci_register_types) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 6d3f556989fb..aaba09058896 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -30,87 +30,19 @@ #include "qapi/error.h" #include "qemu/timer.h" #include "hw/usb.h" -#include "hw/pci/pci.h" #include "hw/sysbus.h" #include "hw/qdev-dma.h" #include "trace.h" +#include "hcd-ohci.h" =20 /* This causes frames to occur 1000x slower */ //#define OHCI_TIME_WARP 1 =20 -/* Number of Downstream Ports on the root hub. */ - -#define OHCI_MAX_PORTS 15 - #define ED_LINK_LIMIT 32 =20 static int64_t usb_frame_time; static int64_t usb_bit_time; =20 -typedef struct OHCIPort { - USBPort port; - uint32_t ctrl; -} OHCIPort; - -typedef struct OHCIState { - USBBus bus; - qemu_irq irq; - MemoryRegion mem; - AddressSpace *as; - uint32_t num_ports; - const char *name; - - QEMUTimer *eof_timer; - int64_t sof_time; - - /* OHCI state */ - /* Control partition */ - uint32_t ctl, status; - uint32_t intr_status; - uint32_t intr; - - /* memory pointer partition */ - uint32_t hcca; - uint32_t ctrl_head, ctrl_cur; - uint32_t bulk_head, bulk_cur; - uint32_t per_cur; - uint32_t done; - int32_t done_count; - - /* Frame counter partition */ - uint16_t fsmps; - uint8_t fit; - uint16_t fi; - uint8_t frt; - uint16_t frame_number; - uint16_t padding; - uint32_t pstart; - uint32_t lst; - - /* Root Hub partition */ - uint32_t rhdesc_a, rhdesc_b; - uint32_t rhstatus; - OHCIPort rhport[OHCI_MAX_PORTS]; - - /* PXA27x Non-OHCI events */ - uint32_t hstatus; - uint32_t hmask; - uint32_t hreset; - uint32_t htest; - - /* SM501 local memory offset */ - dma_addr_t localmem_base; - - /* Active packets. */ - uint32_t old_ctl; - USBPacket usb_packet; - uint8_t usb_buf[8192]; - uint32_t async_td; - bool async_complete; - - void (*ohci_die)(struct OHCIState *ohci); -} OHCIState; - /* Host Controller Communications Area */ struct ohci_hcca { uint32_t intr[32]; @@ -123,7 +55,6 @@ struct ohci_hcca { #define ED_WBACK_OFFSET offsetof(struct ohci_ed, head) #define ED_WBACK_SIZE 4 =20 -static void ohci_bus_stop(OHCIState *ohci); static void ohci_async_cancel_device(OHCIState *ohci, USBDevice *dev); =20 /* Bitfields for the first word of an Endpoint Desciptor. */ @@ -430,7 +361,7 @@ static USBDevice *ohci_find_device(OHCIState *ohci, uin= t8_t addr) return NULL; } =20 -static void ohci_stop_endpoints(OHCIState *ohci) +void ohci_stop_endpoints(OHCIState *ohci) { USBDevice *dev; int i, j; @@ -502,7 +433,7 @@ static void ohci_soft_reset(OHCIState *ohci) ohci->lst =3D OHCI_LS_THRESH; } =20 -static void ohci_hard_reset(OHCIState *ohci) +void ohci_hard_reset(OHCIState *ohci) { ohci_soft_reset(ohci); ohci->ctl =3D 0; @@ -1376,7 +1307,7 @@ static int ohci_bus_start(OHCIState *ohci) } =20 /* Stop sending SOF tokens on the bus */ -static void ohci_bus_stop(OHCIState *ohci) +void ohci_bus_stop(OHCIState *ohci) { trace_usb_ohci_stop(ohci->name); timer_del(ohci->eof_timer); @@ -1856,10 +1787,10 @@ static USBPortOps ohci_port_ops =3D { static USBBusOps ohci_bus_ops =3D { }; =20 -static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, - uint32_t num_ports, dma_addr_t localmem_base, - char *masterbus, uint32_t firstport, AddressSpac= e *as, - void (*ohci_die_fn)(struct OHCIState *), Error *= *errp) +void usb_ohci_init(OHCIState *ohci, DeviceState *dev, uint32_t num_ports, + dma_addr_t localmem_base, char *masterbus, + uint32_t firstport, AddressSpace *as, + void (*ohci_die_fn)(struct OHCIState *), Error **errp) { Error *err =3D NULL; int i; @@ -1924,25 +1855,11 @@ static void usb_ohci_init(OHCIState *ohci, DeviceSt= ate *dev, ohci_frame_boundary, ohci); } =20 -#define TYPE_PCI_OHCI "pci-ohci" -#define PCI_OHCI(obj) OBJECT_CHECK(OHCIPCIState, (obj), TYPE_PCI_OHCI) - -typedef struct { - /*< private >*/ - PCIDevice parent_obj; - /*< public >*/ - - OHCIState state; - char *masterbus; - uint32_t num_ports; - uint32_t firstport; -} OHCIPCIState; - /** * A typical OHCI will stop operating and set itself into error state * (which can be queried by MMIO) to signal that it got an error. */ -static void ohci_sysbus_die(struct OHCIState *ohci) +void ohci_sysbus_die(struct OHCIState *ohci) { trace_usb_ohci_die(); =20 @@ -1950,71 +1867,6 @@ static void ohci_sysbus_die(struct OHCIState *ohci) ohci_bus_stop(ohci); } =20 -/** - * A typical PCI OHCI will additionally set PERR in its configspace to - * signal that it got an error. - */ -static void ohci_pci_die(struct OHCIState *ohci) -{ - OHCIPCIState *dev =3D container_of(ohci, OHCIPCIState, state); - - ohci_sysbus_die(ohci); - - pci_set_word(dev->parent_obj.config + PCI_STATUS, - PCI_STATUS_DETECTED_PARITY); -} - -static void usb_ohci_realize_pci(PCIDevice *dev, Error **errp) -{ - Error *err =3D NULL; - OHCIPCIState *ohci =3D PCI_OHCI(dev); - - dev->config[PCI_CLASS_PROG] =3D 0x10; /* OHCI */ - dev->config[PCI_INTERRUPT_PIN] =3D 0x01; /* interrupt pin A */ - - usb_ohci_init(&ohci->state, DEVICE(dev), ohci->num_ports, 0, - ohci->masterbus, ohci->firstport, - pci_get_address_space(dev), ohci_pci_die, &err); - if (err) { - error_propagate(errp, err); - return; - } - - ohci->state.irq =3D pci_allocate_irq(dev); - pci_register_bar(dev, 0, 0, &ohci->state.mem); -} - -static void usb_ohci_exit(PCIDevice *dev) -{ - OHCIPCIState *ohci =3D PCI_OHCI(dev); - OHCIState *s =3D &ohci->state; - - trace_usb_ohci_exit(s->name); - ohci_bus_stop(s); - - if (s->async_td) { - usb_cancel_packet(&s->usb_packet); - s->async_td =3D 0; - } - ohci_stop_endpoints(s); - - if (!ohci->masterbus) { - usb_bus_release(&s->bus); - } - - timer_del(s->eof_timer); - timer_free(s->eof_timer); -} - -static void usb_ohci_reset_pci(DeviceState *d) -{ - PCIDevice *dev =3D PCI_DEVICE(d); - OHCIPCIState *ohci =3D PCI_OHCI(dev); - OHCIState *s =3D &ohci->state; - - ohci_hard_reset(s); -} - #define TYPE_SYSBUS_OHCI "sysbus-ohci" #define SYSBUS_OHCI(obj) OBJECT_CHECK(OHCISysBusState, (obj), TYPE_SYSBUS_= OHCI) =20 @@ -2055,13 +1907,6 @@ static void usb_ohci_reset_sysbus(DeviceState *dev) ohci_hard_reset(ohci); } =20 -static Property ohci_pci_properties[] =3D { - DEFINE_PROP_STRING("masterbus", OHCIPCIState, masterbus), - DEFINE_PROP_UINT32("num-ports", OHCIPCIState, num_ports, 3), - DEFINE_PROP_UINT32("firstport", OHCIPCIState, firstport, 0), - DEFINE_PROP_END_OF_LIST(), -}; - static const VMStateDescription vmstate_ohci_state_port =3D { .name =3D "ohci-core/port", .version_id =3D 1, @@ -2090,7 +1935,7 @@ static const VMStateDescription vmstate_ohci_eof_time= r =3D { }, }; =20 -static const VMStateDescription vmstate_ohci_state =3D { +const VMStateDescription vmstate_ohci_state =3D { .name =3D "ohci-core", .version_id =3D 1, .minimum_version_id =3D 1, @@ -2137,46 +1982,6 @@ static const VMStateDescription vmstate_ohci_state = =3D { } }; =20 -static const VMStateDescription vmstate_ohci =3D { - .name =3D "ohci", - .version_id =3D 1, - .minimum_version_id =3D 1, - .fields =3D (VMStateField[]) { - VMSTATE_PCI_DEVICE(parent_obj, OHCIPCIState), - VMSTATE_STRUCT(state, OHCIPCIState, 1, vmstate_ohci_state, OHCISta= te), - VMSTATE_END_OF_LIST() - } -}; - -static void ohci_pci_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc =3D DEVICE_CLASS(klass); - PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); - - k->realize =3D usb_ohci_realize_pci; - k->exit =3D usb_ohci_exit; - k->vendor_id =3D PCI_VENDOR_ID_APPLE; - k->device_id =3D PCI_DEVICE_ID_APPLE_IPID_USB; - k->class_id =3D PCI_CLASS_SERIAL_USB; - set_bit(DEVICE_CATEGORY_USB, dc->categories); - dc->desc =3D "Apple USB Controller"; - dc->props =3D ohci_pci_properties; - dc->hotpluggable =3D false; - dc->vmsd =3D &vmstate_ohci; - dc->reset =3D usb_ohci_reset_pci; -} - -static const TypeInfo ohci_pci_info =3D { - .name =3D TYPE_PCI_OHCI, - .parent =3D TYPE_PCI_DEVICE, - .instance_size =3D sizeof(OHCIPCIState), - .class_init =3D ohci_pci_class_init, - .interfaces =3D (InterfaceInfo[]) { - { INTERFACE_CONVENTIONAL_PCI_DEVICE }, - { }, - }, -}; - static Property ohci_sysbus_properties[] =3D { DEFINE_PROP_STRING("masterbus", OHCISysBusState, masterbus), DEFINE_PROP_UINT32("num-ports", OHCISysBusState, num_ports, 3), @@ -2205,7 +2010,6 @@ static const TypeInfo ohci_sysbus_info =3D { =20 static void ohci_register_types(void) { - type_register_static(&ohci_pci_info); type_register_static(&ohci_sysbus_info); } =20 diff --git a/hw/sh4/Kconfig b/hw/sh4/Kconfig index 593662d28ade..4cbce3a0ed5e 100644 --- a/hw/sh4/Kconfig +++ b/hw/sh4/Kconfig @@ -6,7 +6,7 @@ config R2D select I82378 if TEST_DEVICES select IDE_MMIO select PFLASH_CFI02 - select USB_OHCI + select USB_OHCI_PCI select PCI select SM501 select SH4 diff --git a/hw/usb/Kconfig b/hw/usb/Kconfig index a1b7acb12a37..564305e28339 100644 --- a/hw/usb/Kconfig +++ b/hw/usb/Kconfig @@ -8,10 +8,14 @@ config USB_UHCI select USB =20 config USB_OHCI + bool + select USB + +config USB_OHCI_PCI bool default y if PCI_DEVICES depends on PCI - select USB + select USB_OHCI =20 config USB_EHCI bool diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs index 2b929649acd0..81688f6e7062 100644 --- a/hw/usb/Makefile.objs +++ b/hw/usb/Makefile.objs @@ -5,6 +5,7 @@ common-obj-$(CONFIG_USB) +=3D desc.o desc-msos.o # usb host adapters common-obj-$(CONFIG_USB_UHCI) +=3D hcd-uhci.o common-obj-$(CONFIG_USB_OHCI) +=3D hcd-ohci.o +common-obj-$(CONFIG_USB_OHCI_PCI) +=3D hcd-ohci-pci.o common-obj-$(CONFIG_USB_EHCI) +=3D hcd-ehci.o hcd-ehci-pci.o common-obj-$(CONFIG_USB_EHCI_SYSBUS) +=3D hcd-ehci.o hcd-ehci-sysbus.o common-obj-$(CONFIG_USB_XHCI) +=3D hcd-xhci.o --=20 2.18.1 From nobody Wed May 15 05:08:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556867022; cv=none; d=zoho.com; s=zohoarc; b=nCTa5gJuSLYtlVqXMbW5vxVUFlobaBCrg/5XxDwMLG9sjrJIjzT9mjSil1LpD4+tiYlbHvpA+9zZVegwHsBnzJgxauIMcsnH+RDWQwdjlYH5YllfwtNmcL3AyKcWgnf+zITaDQEMh5bOvf2N60jSgJMSB/YoQy1OuZ7pqZDF8Bs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556867022; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=y3SlAyaoF0QNyAo+FCQgSzqXl3SlQRU6MfwWT3rfIOQ=; b=jR2gcWpkQ8HrUxeD4FaaebFa8RxeJV2NEkNlhZUo7JVQc+TDqH22lbTaaRg/J1DpwRyQVFjQLxvMFAA2OC45eCL5YshoNnv3nyQI3rBz8VcsggrOYVK7YRh9xnMUuvpvia/SWWhuWppxGVxt6+FyoRo2JHS4Wyi5awUUlRemf24= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556867022017959.7531750648594; Fri, 3 May 2019 00:03:42 -0700 (PDT) Received: from localhost ([127.0.0.1]:35639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSD7-0005la-IP for importer@patchew.org; Fri, 03 May 2019 03:02:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMSAt-0003nt-2H for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMSAs-0006Gb-0C for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56154) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMSAr-0006FL-Qh for qemu-devel@nongnu.org; Fri, 03 May 2019 03:00:01 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21D0F30B4874; Fri, 3 May 2019 07:00:01 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FB8B60BF7; Fri, 3 May 2019 06:59:58 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 5C25C1753B; Fri, 3 May 2019 08:59:54 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 08:59:54 +0200 Message-Id: <20190503065954.17069-8-kraxel@redhat.com> In-Reply-To: <20190503065954.17069-1-kraxel@redhat.com> References: <20190503065954.17069-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 03 May 2019 07:00:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/7] hw/usb: avoid format truncation warning when formatting port name 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: Gerd Hoffmann , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Daniel P. Berrang=C3=A9 hw/usb/hcd-xhci.c: In function =E2=80=98usb_xhci_realize=E2=80=99: hw/usb/hcd-xhci.c:3339:66: warning: =E2=80=98%d=E2=80=99 directive output m= ay be truncated writing between 1 and 10 bytes into a region of size 5 [-Wf= ormat-trunca\ tion=3D] 3339 | snprintf(port->name, sizeof(port->name), "usb2 port #%d= ", i+1); | ^~ hw/usb/hcd-xhci.c:3339:54: note: directive argument in the range [1, 214748= 3647] 3339 | snprintf(port->name, sizeof(port->name), "usb2 port #%d= ", i+1); | ^~~~~~~~~~~~~~~ The xhci code formats the port name into a fixed length buffer which is only large enough to hold port numbers upto 5 digits in decimal representation. We're never going to have a port number that large, so aserting the port number is sensible is sufficient to tell GCC the formatted string won't be truncated. Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20190412121626.19829-5-berrange@redhat.com> [ kraxel: also s/int/unsigned int/ to tell gcc they can't go negative. ] Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index d8472b4fea7f..2e9a839f2bf9 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -3306,7 +3306,7 @@ static void usb_xhci_init(XHCIState *xhci) { DeviceState *dev =3D DEVICE(xhci); XHCIPort *port; - int i, usbports, speedmask; + unsigned int i, usbports, speedmask; =20 xhci->usbsts =3D USBSTS_HCH; =20 @@ -3336,6 +3336,7 @@ static void usb_xhci_init(XHCIState *xhci) USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL | USB_SPEED_MASK_HIGH; + assert(i < MAXPORTS); snprintf(port->name, sizeof(port->name), "usb2 port #%d", i+1); speedmask |=3D port->speedmask; } @@ -3349,6 +3350,7 @@ static void usb_xhci_init(XHCIState *xhci) } port->uport =3D &xhci->uports[i]; port->speedmask =3D USB_SPEED_MASK_SUPER; + assert(i < MAXPORTS); snprintf(port->name, sizeof(port->name), "usb3 port #%d", i+1); speedmask |=3D port->speedmask; } --=20 2.18.1