From nobody Sun Feb 8 17:48:04 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582204011; cv=none; d=zohomail.com; s=zohoarc; b=idAmjOubeKK2HgugA22GFuYuazoGhtg4ihHTXpxwhgDfRr7InxnytJMvQLGXSMXW3D/xsc8dlwaeJZWbAO8iKo4ba1bBW2IhYXgm0IzBtu7DY1BVi/v5ishsgXjvphsn20flzdhb0XF7hHz+V+idLi0w1KLzvmfAyX6gTeAhxF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582204011; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aOaWQi1eX/70deDK+874Nrp+LBcg9bJamtxnwe50Nr4=; b=YNuleuE+2D0MmTCynwedFAz+TqjHY+HNkMfvO39b9aemzP7bjJ+cYE0IatYg8036kEpo9mDCwaAiq5umVXL3g/U5kDyiK4LHIt3mN5X3HCI2fwH8/MrxtTl7xQL6ZyMVh3C3tYfTODZpOwV77j07/+K1y+B1RkvoHjDLDSjnmwY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1582204011044846.4753559737514; Thu, 20 Feb 2020 05:06:51 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4lX7-0001Ax-NL; Thu, 20 Feb 2020 13:06:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4lX6-00019C-AH for xen-devel@lists.xenproject.org; Thu, 20 Feb 2020 13:06:24 +0000 Received: from us-smtp-1.mimecast.com (unknown [205.139.110.120]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id cba945ba-53e1-11ea-ade5-bc764e2007e4; Thu, 20 Feb 2020 13:06:23 +0000 (UTC) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-180-wGoi-NvVOyaTGx9Og7Am4w-1; Thu, 20 Feb 2020 08:06:21 -0500 Received: by mail-wr1-f71.google.com with SMTP id z15so1725308wrw.0 for ; Thu, 20 Feb 2020 05:06:21 -0800 (PST) Received: from localhost.localdomain (78.red-88-21-202.staticip.rima-tde.net. [88.21.202.78]) by smtp.gmail.com with ESMTPSA id b67sm4594690wmc.38.2020.02.20.05.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 05:06:19 -0800 (PST) X-Inumbo-ID: cba945ba-53e1-11ea-ade5-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582203983; 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=EvIA11c99fe9jZjyk6Bhj+dUz8AZyW6zBDm4tJjkdl0=; b=M6pP8130TCNN20jOqy/yn8zC+zWl35M2q5d8128XA/WZCZNUGa7y2tEeiPi3qwlcK6sc5I MZbuAGtONIxUUxJUumaXJU1cFw+0BwNRS6WwRFl2Uhb10z4h8V8D3kK6d++/Y4/OWRgq8L mu6uFapgRXE0op2MDiyuI5a8b6mCxhk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pVKWVWwp9TVJU5qM7Beut+kG2DV5MFLYTF1Kx3cmH3A=; b=qw9yk/gU0WhQ8MwxyqFLupkFD2e3HbXbr8IBKdUrn4YXmc6jH8QGoIDm0RfcJXWrSh 173hHkqgpTd3zUs5mjNbtZDLCKKtrREzspM4AiDD9ExH1ud4aTTybT4ndcetVXk1zXFq Kakrs92UjlNnaf3moR5Yth4CjspfP0YFScfBIIucbCW1Q67+jndu6RehKGV6eJ8xUyzP 4fOo0SYNyfeppU2wbEBbCoemWhMhgM4AaUSNapHRDvC6eqqWlQWHgjwMfbh1kGtfYGUq ybPRqF92n4MiCauqP6uuj3fHSswhW07nL1gg7LH9oG0Xcx4eFcc4YSE6Fc3/zlOgWpGR 6HSQ== X-Gm-Message-State: APjAAAUIGoDqVcEZxZyvRQvx/XhIrqhqo5tUK3bxsVQXacntnNOIxltE ev0+gOn+pqybQLbezWOUq8Rw4aZfumNWDTitcxae395AT3SV+4B7I/rdUu7W9Pk91tUBHz0q/2M VRH/QNGNlS+c5M2xMJPiVw8n4alw= X-Received: by 2002:a5d:4687:: with SMTP id u7mr40881706wrq.176.1582203980202; Thu, 20 Feb 2020 05:06:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwfQdFudKu/IvbI9dQMK95qUdVs2MjCpL2sBTVu5yezv4G1pdvxpKJvTb+aMe+m36JC5h7NRg== X-Received: by 2002:a5d:4687:: with SMTP id u7mr40881691wrq.176.1582203979939; Thu, 20 Feb 2020 05:06:19 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , qemu-devel@nongnu.org Date: Thu, 20 Feb 2020 14:05:35 +0100 Message-Id: <20200220130548.29974-8-philmd@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200220130548.29974-1-philmd@redhat.com> References: <20200220130548.29974-1-philmd@redhat.com> MIME-Version: 1.0 X-MC-Unique: wGoi-NvVOyaTGx9Og7Am4w-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [Xen-devel] [PATCH v3 07/20] hw/net: Avoid casting non-const pointer, use address_space_write() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Dmitry Fleytman , kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Gerd Hoffmann , "Edgar E. Iglesias" , Stefano Stabellini , Matthew Rosato , qemu-block@nongnu.org, David Hildenbrand , Halil Pasic , Christian Borntraeger , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Marcel Apfelbaum , Anthony Perard , xen-devel@lists.xenproject.org, Aleksandar Rikalo , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , Thomas Huth , Eduardo Habkost , Stefan Weil , Alistair Francis , Richard Henderson , Paul Durrant , Eric Auger , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Snow , David Gibson , Igor Mitsyanko , Cornelia Huck , Michael Walle , qemu-ppc@nongnu.org, Paolo Bonzini Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The NetReceive prototype gets a const buffer: typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); We already have the address_space_write() method to write a const buffer to an address space. Use it to avoid: hw/net/i82596.c: In function =E2=80=98i82596_receive=E2=80=99: hw/net/i82596.c:644:54: error: passing argument 4 of =E2=80=98address_spa= ce_rw=E2=80=99 discards =E2=80=98const=E2=80=99 qualifier from pointer targ= et type [-Werror=3Ddiscarded-qualifiers] This commit was produced with the included Coccinelle script scripts/coccinelle/exec_rw_const. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- scripts/coccinelle/exec_rw_const.cocci | 14 ++++++++++++++ hw/net/dp8393x.c | 3 +-- hw/net/i82596.c | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/coccinelle/exec_rw_const.cocci b/scripts/coccinelle/ex= ec_rw_const.cocci index a0054f009d..4e459d915b 100644 --- a/scripts/coccinelle/exec_rw_const.cocci +++ b/scripts/coccinelle/exec_rw_const.cocci @@ -1,6 +1,20 @@ // Usage: // spatch --sp-file scripts/coccinelle/exec_rw_const.cocci --dir . --in-p= lace =20 +// Use address_space_write instead of casting to non-const +@@ +type T; +const T *V; +expression E1, E2, E3, E4; +@@ +( +- address_space_rw(E1, E2, E3, (T *)V, E4, 1) ++ address_space_write(E1, E2, E3, V, E4) +| +- address_space_rw(E1, E2, E3, (void *)V, E4, 1) ++ address_space_write(E1, E2, E3, V, E4) +) + // Remove useless cast @@ expression E1, E2, E3, E4; diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index a134d431ae..580ae4437e 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -787,8 +787,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, cons= t uint8_t * buf, /* Put packet into RBA */ DPRINTF("Receive packet at %08x\n", dp8393x_crba(s)); address =3D dp8393x_crba(s); - address_space_rw(&s->as, address, - MEMTXATTRS_UNSPECIFIED, (uint8_t *)buf, rx_len, 1); + address_space_write(&s->as, address, MEMTXATTRS_UNSPECIFIED, buf, rx_l= en); address +=3D rx_len; address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED, (uint8_t *)&checksum, 4, 1); diff --git a/hw/net/i82596.c b/hw/net/i82596.c index 3a0e1ec4c0..a292984e06 100644 --- a/hw/net/i82596.c +++ b/hw/net/i82596.c @@ -640,8 +640,8 @@ ssize_t i82596_receive(NetClientState *nc, const uint8_= t *buf, size_t sz) } rba =3D get_uint32(rbd + 8); /* printf("rba is 0x%x\n", rba); */ - address_space_rw(&address_space_memory, rba, - MEMTXATTRS_UNSPECIFIED, (void *)buf, num, 1); + address_space_write(&address_space_memory, rba, + MEMTXATTRS_UNSPECIFIED, buf, num); rba +=3D num; buf +=3D num; len -=3D num; --=20 2.21.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel