From patchwork Thu Feb 20 13:05:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1241409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=M6pP8130; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48NZmJ60bZz9sP7 for ; Fri, 21 Feb 2020 00:13:52 +1100 (AEDT) Received: from localhost ([::1]:41732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4leI-00015B-7V for incoming@patchwork.ozlabs.org; Thu, 20 Feb 2020 08:13:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55875) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4lX7-0004sM-Er for qemu-devel@nongnu.org; Thu, 20 Feb 2020 08:06:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4lX6-00053A-5E for qemu-devel@nongnu.org; Thu, 20 Feb 2020 08:06:25 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:41871 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4lX6-00052c-0G for qemu-devel@nongnu.org; Thu, 20 Feb 2020 08:06:24 -0500 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= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-_IsJbITLORy3SMuZ_tY9Vg-1; Thu, 20 Feb 2020 08:06:21 -0500 X-MC-Unique: _IsJbITLORy3SMuZ_tY9Vg-1 Received: by mail-wm1-f69.google.com with SMTP id y7so578873wmd.4 for ; Thu, 20 Feb 2020 05:06:21 -0800 (PST) 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=BBE8bw9yxRb1pHTbcelyXHYX7Vt5M72h3Jj+5fdr+hUE+NnqTL6eXh0m9lIt/7Fj8l vwUmVzD/3hfgrsi30kudUKOiKvG21eZSYgPkXRwsI/C8B0YsBPqve6z/jrt2PQpljLhK teRy5gWveedTcpuD9kFVH73TD2yFyF9Mq8yZ5TMHl+nA+Kq9qRx58Go0w+RTg3WCaNeS 65hTxN+FJTbA7Y7/1dZggoWC7Sk89xPeyWXUth8uiFIUgeaLWlC3fuocJGxl0laLrdgk x8MSSDboP5w9AZyIpgjjflsUkFl3z7y8Sw47W4BX+tHDFRoBgK/lPfmI3bpi3J5kjibH 3C4Q== X-Gm-Message-State: APjAAAUiRMdRflJrMdXJMVJ7OtPkHEzZGJL3AyUcwoW+LgMhY4avEOh/ wPrpFknxCgGgsgAfM2xD3/LwUzLOELwrUZeRqGx4tSFU3H3jaKTXCelYdoJ1X1zFjD6Ca3hQ6R3 rXFsxnzz/fBXIG/k= X-Received: by 2002:a5d:4687:: with SMTP id u7mr40881742wrq.176.1582203980253; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Peter Maydell , qemu-devel@nongnu.org Subject: [PATCH v3 07/20] hw/net: Avoid casting non-const pointer, use address_space_write() 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: 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_Poussineau?= , Anthony Perard , xen-devel@lists.xenproject.org, Aleksandar Rikalo , Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , 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_Le_Goater?= , John Snow , David Gibson , Igor Mitsyanko , Cornelia Huck , Michael Walle , qemu-ppc@nongnu.org, Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 ‘i82596_receive’: hw/net/i82596.c:644:54: error: passing argument 4 of ‘address_space_rw’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers] This commit was produced with the included Coccinelle script scripts/coccinelle/exec_rw_const. Signed-off-by: Philippe Mathieu-Daudé --- 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/exec_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-place +// 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, const uint8_t * buf, /* Put packet into RBA */ DPRINTF("Receive packet at %08x\n", dp8393x_crba(s)); address = 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_len); address += 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 = 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 += num; buf += num; len -= num;