From nobody Sat Nov 15 10:54:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752516432; cv=none; d=zohomail.com; s=zohoarc; b=OP+OyEg4yVrQggG3zPsDaMRZ9z1FIBVUwchRGtxNnSnwkVoJaeDS/F/8rDO9Xyj8WHwzvtJE6fFftzTD5SulSXMD1bDE9O/Qg9jnkWQMAVpe5Wh2Cpsw8rM41kq5SWBji6mnQNNDtupAsPQpZHYqUCZjprezbHrv+KjUMoKG4zw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752516432; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=br77uvVKOnYwvQwak2uW9KVzgHfO7SuJ2lzjCWhl6qs=; b=loE8B1TXRWqn/GFlwV9e4FJm2TKsqndq89ebKJkG3qGdh89qxHnPQj0ioLEYSrwvDFUdsOW/A6dD+4ad6jyA2E7xMISzgvn506QEpE/6cbjmslzVhix4ajmBkjUj/sgWBluwpyrIiKSPMbmNf/B9dAnNF6E4LpfH/MZnLCBxu5k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752516432007934.2838457316011; Mon, 14 Jul 2025 11:07:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubNYc-0007km-8x; Mon, 14 Jul 2025 14:05:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubMSi-0004YG-F8 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 12:55:33 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ubMSf-0001Ig-66 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 12:55:32 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3a575a988f9so2614859f8f.0 for ; Mon, 14 Jul 2025 09:55:28 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd15bfsm13164665f8f.19.2025.07.14.09.55.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 09:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752512127; x=1753116927; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=br77uvVKOnYwvQwak2uW9KVzgHfO7SuJ2lzjCWhl6qs=; b=G3YEEvUWKJ3AOY4gEmPlS/DgnbN1H4pTa6ynFGJT7m4XdmB8SHT+ykLG3yWZP4kehH hbpCy+CPOX9urjKy+gjbWeB2vGzk+SvHaDa/FZEAL0S9e0AdJmn07nA4Kme9DgoWI8WW zt3rJmsjlxhsoghwhZf+3HATVY2CuaTNLlLxtnPZV5xkDUPBo0BcKq2zrKZ8P1kJMwWY 4I/y6MEUI/alEsF5eCgncOv17qlz8M+PgJCfCt0CJ+6NGEEJWS0owW7BQQXf4JQIdSC9 nQAn39ymVl+Zpb0AHib9WEX/bGo8sN1q9XhZrqGh4Zwm1p3RCWgt00mDAjqrk8k8hs8e 8Bcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752512127; x=1753116927; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=br77uvVKOnYwvQwak2uW9KVzgHfO7SuJ2lzjCWhl6qs=; b=I5Yl2sERn5EtrN7u1JVg5O0zqPoQB5VF8R+EcWM5+wZCLAoaUd7niJeNWIcRdnBYW/ 0DL5c5BnL9mnrhW2Yo0CEJ+iVZsMqcWIC+BmoZIbafVKvuKly/cbMAPKdCk8DAAxcBlC 8MVxSKYDdkcgsnEiqmuu8IeJ+jXpTdraroNDv30gUspIdwWMH7ZT7mb9X6jMXSIAlR6h OVHtSwRg9/V2C+CCSw5tEBHguPCfE0lV+CTN7kH30vycTI5aXiOW84/IR0tV4wKSbebu XRWrnNf4cmsJ6/wlXtf6LO5A2UVOk3YfAvKJAWR7QYGxDY6zn7pSDssOseR5+0j+s0iH ygug== X-Forwarded-Encrypted: i=1; AJvYcCUTZ9cmtARdU9dn0cJXz4HG8Xk0MtCD0Gq2zazzj/N2oJwzAVhd1AQYbON8ztwySm8vazvw5x7KxS+o@nongnu.org X-Gm-Message-State: AOJu0Yxek6HSEWIIdTOAi/d6ZurLNpD7+lxUnwPfq3d42mBRJnDXywxI /62sxpqzoNxM8PKw4ykepYsWoKAhFivURtFmCRiAS0mmyBcRwSgskeP8ZE+TfWymliA= X-Gm-Gg: ASbGnctA8sUPTwORzUh1P6SMmCm4AJ0WMvCOx2B7TYdG3c1h/qMJ9AlRYSgcSmeKEIb dr3FLYzAck46ZDaHnONKvK/81CFnonK2cDUq/aSEd8iYaF2MH/+bXqm+vTI5nVhIttnEIuwUbYM vUYyNp3iFkMVMybsvSynVfr7nSImblSBwJJW46bcMD5G6LxCQqRRptpFpEz9vWZizOU2Xl4PDJf IIZCIfW3ez8YyKMdRUUSx1R71dspOOhvHf/3Q7M3gpOLbyg2rrRsTjTqJdrmJpgdEYaGh09DlZd gTKOhgIn8+Uf7AHUso5hcR7F6afhJ3T5cqnS67rxICwXExqPOXhhI3OwqsxHJRd7fRZV6O0wOMV jwvwCHORoMZgM0BAMT7GlWi5pwCi9zuGeUtHSBRc= X-Google-Smtp-Source: AGHT+IEakqGm2fH8gUqKbCg3UjkAETP5OJy/JmVK7JIscCSCLq8PRvnDUgQx1RTkzyBLahVu/ZRzrA== X-Received: by 2002:a5d:4389:0:b0:3a5:8905:2df9 with SMTP id ffacd0b85a97d-3b5f18cebf9mr9849495f8f.37.1752512127319; Mon, 14 Jul 2025 09:55:27 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Tyrone Ting , Hao Wu , Jason Wang Subject: [PATCH 1/4] hw/net/npcm_gmac.c: Send the right data for second packet in a row Date: Mon, 14 Jul 2025 17:55:20 +0100 Message-ID: <20250714165523.1956235-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714165523.1956235-1-peter.maydell@linaro.org> References: <20250714165523.1956235-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42f.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752516432954116600 Content-Type: text/plain; charset="utf-8" The transmit loop in gmac_try_send_next_packet() is constructed in a way that means it will send incorrect data if it it sends more than one packet. The function assembles the outbound data in a dynamically allocated block of memory which is pointed to by tx_send_buffer. We track the first point in this block of memory which is not yet used with the prev_buf_size offset, initially zero. We track the size of the packet we're sending with the length variable, also initially zero. As we read chunks of data out of guest memory, we write them to tx_send_buffer[prev_buf_size], and then increment both prev_buf_size and length. (We might dynamically reallocate the buffer if needed.) When we send a packet, we checksum and send length bytes, starting at tx_send_buffer, and then we reset length to 0. This gives the right data for the first packet. But we don't reset prev_buf_size. This means that if we process more descriptors with further data for the next packet, that data will continue to accumulate at offset prev_buf_size, i.e. after the data for the first packet. But when we transmit that second packet, we send length bytes from tx_send_buffer, so we will send a packet which has the length of the second packet but the data of the first one. The fix for this is to also clear prev_buf_size after the packet has been sent -- we never need the data from packet one after we've sent it, so we can write packet two's data starting at the beginning of the buffer. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell --- Disclaimer: this bugfix is based on reading the source code; I don't have a test setup to confirm or test it. --- hw/net/npcm_gmac.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/net/npcm_gmac.c b/hw/net/npcm_gmac.c index a4341125809..921327dd8ca 100644 --- a/hw/net/npcm_gmac.c +++ b/hw/net/npcm_gmac.c @@ -615,6 +615,7 @@ static void gmac_try_send_next_packet(NPCMGMACState *gm= ac) trace_npcm_gmac_packet_sent(DEVICE(gmac)->canonical_path, leng= th); buf =3D tx_send_buffer; length =3D 0; + prev_buf_size =3D 0; } =20 /* step 6 */ --=20 2.43.0 From nobody Sat Nov 15 10:54:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752516432; cv=none; d=zohomail.com; s=zohoarc; b=V8WBs3FcSBB0KpfFjd8WT8paArNnXJVtNg0WtQPXKM4hdj8yrGybENu/c54LBPPYheNtmDO7nlZHCyDqUDoahDSZNW12H3yLFZIuCmXUQ4Xi7QKtm1PjIy5Ucuq12XdzLGbW53wCqtWBuXMAWC0AxLSugQy6B6mKs1qmEIn9+Ng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752516432; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3cGXdCXCfPmsA5Ze9Qy3GSzkEFT+6aOU7O/5fB9CynM=; b=OjSm2+WJW4fOYxLaq04XNhpJTeFfyX/ogtlLrSVxokUGOB8Oq3cGmTNmTzlja63ROJk3fc6PYlxWaHDwOrfsFrqj44yRZDodICSDl3+zsb7+Woeulx9lPFuFzJ6FDshlfyeZou6N1IlV9cOh6oyQSOkGBszWDmc9M+7vcBstm68= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752516432470621.9357881765716; Mon, 14 Jul 2025 11:07:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubNYf-0007pD-DH; Mon, 14 Jul 2025 14:05:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubMSi-0004YK-K5 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 12:55:33 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ubMSg-0001In-1D for qemu-devel@nongnu.org; Mon, 14 Jul 2025 12:55:32 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-45526dec171so32955295e9.2 for ; Mon, 14 Jul 2025 09:55:29 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd15bfsm13164665f8f.19.2025.07.14.09.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 09:55:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752512128; x=1753116928; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3cGXdCXCfPmsA5Ze9Qy3GSzkEFT+6aOU7O/5fB9CynM=; b=R9Jf0t7KZ3/UGK6NfDodcWaLoMtRvR8rvd3m5FGbyM7m9x0V9LufVAjW8/rBCQzzdi 6FwPWNSYqTZVM3K/WXQFKALWkmzZqj3XOBde14eDd7CeEtMhNboHGhBfsuQXMuz3jjjh NdJV/CaG+yCJqO8rZ2XaM35wLz2JyuIP/Dpcp+8s16f2b+ka+Q+ouAGZGruFSehuPFSF ihwDcvuLkF6dbMdtuSmtApfbuklhorzAKzGHlRvBgoH0+XRtw4B0fhfsln0C5MJrs/pL 80ySfwi+2FoU5a68yhsF/hoDH7TrA9JM11VoFH1hJN1pkfjkL0fuVquTCmox1xkkIOR4 cAPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752512128; x=1753116928; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3cGXdCXCfPmsA5Ze9Qy3GSzkEFT+6aOU7O/5fB9CynM=; b=Ka65t0Dr5v2snpj8BUymDoT92g1tIlD8lG1RLfhdo56y6K9uyhGJmMCinr2Tm9LaGx iIV8YL4ZzZA+rvPL/QrCJs69gTBCnY9+Yo8btHdzlrdFSvnIcM2lts0VLD070OzAiMoM 4lQWilzbvYjmiKn0YUk8PZWA1TVp9dm2zJiBodA1skMQ/oM6ig419nouFPCCUUQArM40 orjO740oW/OVDSYtrPi70/KDCF8BA7I2XQzpKIyRBhNp0jYYkSDB8JJRZ/oVNAAPtoqp HHe8Kj7VOT43AzZkaPi22tMMlVE2YgzHNGN4Ri7u+/qm/Lf++xegfDUo0eQ5N5yhOdvf 3x8A== X-Forwarded-Encrypted: i=1; AJvYcCV3zjiM9vs7iG+zna7O1cobV/EOb0kNsKWNNneUllAKV4DI8wvgKL/UVI5q7gJesRxPqQnXon0dwKTB@nongnu.org X-Gm-Message-State: AOJu0YygJI4A40WVPo0kl3W9y+tm9LlVv+wZXdZarpNIsRYh05oZZYLC 4OcSu6kbDgU7A+2NpkouZO5fVBUarj4mRhkdViMuqsM5Ujxcm5U08gisD/ODyLd5HuA= X-Gm-Gg: ASbGncvnnz5vU5Tv1wLK5efdWuSP9wMxDbc+hBq7Mg+cJAFzGJBAAsSSTTYTbwHFrEd 1zFh1/aabGV+s8KqEn6Fmdjl1osW3w/ZZe09TXeRPr7Ifeko2lyV2Ze+NjEXuevRU5sc5P7mGZK v1A5yP4TOmI59jGS4iulxAmSbkK+Ah+3E0hnARNgHhqFWQWwv60h3UGZTbGiIVFGqItiz/wz2jg ULF39oUezKPA/okgJ7ZQaUoUG8lYQflVWjOhJWhepFc9wnE0zQWcPYCgCa3ZSero16M1cKk8NYn UCJtKhPLwyYlS10EMSfTmN/ZtRkWE7YJvL83G1rn+f14MTb7wTCnLHbf8eqI9AfXgujmBnxuVa2 bpmqHhRep8MKCjA946ndxYA3oNyCP X-Google-Smtp-Source: AGHT+IF45BDZTCY6TXI/tXzTPRatDV+7gekhtrlLBFWCpQeaAgFgTrleOn0L6ZttQqlknoYQixgCSw== X-Received: by 2002:a05:600c:8b2a:b0:453:7b2b:ed2e with SMTP id 5b1f17b1804b1-454ec2727dcmr118670355e9.24.1752512128390; Mon, 14 Jul 2025 09:55:28 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Tyrone Ting , Hao Wu , Jason Wang Subject: [PATCH 2/4] hw/net/npcm_gmac.c: Unify length and prev_buf_size variables Date: Mon, 14 Jul 2025 17:55:21 +0100 Message-ID: <20250714165523.1956235-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714165523.1956235-1-peter.maydell@linaro.org> References: <20250714165523.1956235-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752516435033116600 Content-Type: text/plain; charset="utf-8" After the bug fix in the previous commit, the length and prev_buf_size variables are identical, except that prev_buf_size is uint32_t and length is uint16_t. We can therefore unify them. The only place where the type makes a difference is that we will truncate the packet at 64K when sending it; this commit preserves that behaviour by using a local variable when doing the packet send. Signed-off-by: Peter Maydell --- Should the behaviour really be to truncate the packet at 64K rather than flagging an error if the guest assembles descriptors that combine to give a too-large packet? --- hw/net/npcm_gmac.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/net/npcm_gmac.c b/hw/net/npcm_gmac.c index 921327dd8ca..a0050a7725f 100644 --- a/hw/net/npcm_gmac.c +++ b/hw/net/npcm_gmac.c @@ -516,7 +516,6 @@ static void gmac_try_send_next_packet(NPCMGMACState *gm= ac) uint32_t desc_addr; struct NPCMGMACTxDesc tx_desc; uint32_t tx_buf_addr, tx_buf_len; - uint16_t length =3D 0; uint8_t *buf =3D tx_send_buffer; uint32_t prev_buf_size =3D 0; int csum =3D 0; @@ -583,7 +582,6 @@ static void gmac_try_send_next_packet(NPCMGMACState *gm= ac) __func__, tx_buf_addr); return; } - length +=3D tx_buf_len; prev_buf_size +=3D tx_buf_len; =20 /* If not chained we'll have a second buffer. */ @@ -606,15 +604,18 @@ static void gmac_try_send_next_packet(NPCMGMACState *= gmac) __func__, tx_buf_addr); return; } - length +=3D tx_buf_len; prev_buf_size +=3D tx_buf_len; } if (tx_desc.tdes1 & TX_DESC_TDES1_LAST_SEG_MASK) { + /* + * This will truncate the packet at 64K. + * TODO: find out if this is the correct behaviour. + */ + uint16_t length =3D prev_buf_size; net_checksum_calculate(tx_send_buffer, length, csum); qemu_send_packet(qemu_get_queue(gmac->nic), tx_send_buffer, le= ngth); trace_npcm_gmac_packet_sent(DEVICE(gmac)->canonical_path, leng= th); buf =3D tx_send_buffer; - length =3D 0; prev_buf_size =3D 0; } =20 --=20 2.43.0 From nobody Sat Nov 15 10:54:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752516409; cv=none; d=zohomail.com; s=zohoarc; b=CxkxeMqkrh+DfIr5vRHGXKWXcF2KEsCMyeSkAEky2C9ZGKcCUK2ynD5H2vY6fvi3ho6V3hL7xB2c/KEBBu03xhcz43eNsVrSfI+a0WsQpg30X1pze9ZfXe9W5y7saxQ5LSNoegEoxm6w5BSDS9Xxj0TTZOZWpEH/CokJ+NhIHg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752516409; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/WAd9m8e33PKa1oGnuqT0APNMRjVofzTCm9BK9/hgKY=; b=n6P6rT8IjW6AEAWVrpxfgfkTofqoKW5zkaOYbPO+P0LsnXdKsc2x98Z5y1NTBvjNq1qGBzJd8mVaw7nEhNhrLBEBMsf0js4psnxNVaqq6siOhtr3T6LIYWd54AMtokvkeumKO0G6xX8ljL/ZVtYRymbcdf3ARegAEhKDLvqhEtw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752516409466441.8435208995746; Mon, 14 Jul 2025 11:06:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubNYj-0007tH-AK; Mon, 14 Jul 2025 14:05:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubMSk-0004a6-99 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 12:55:34 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ubMSh-0001J8-84 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 12:55:33 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3a4fd1ba177so2989659f8f.0 for ; Mon, 14 Jul 2025 09:55:30 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd15bfsm13164665f8f.19.2025.07.14.09.55.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 09:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752512129; x=1753116929; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/WAd9m8e33PKa1oGnuqT0APNMRjVofzTCm9BK9/hgKY=; b=E6txaNRu0ZwWrXEoWZqXLHlpl0eSGWws+13zZ5jv7MDEG6zz5zYMdcooBkLl3qQOkT 7gDEofiYeO1q8b3H2M/nnrDqFSmMjoChygV1aEVQT7IS/Vi1IyJu7d30rbcAQgOkeaQB f6kbbFXQaoAFi1ZUtgjXm48C8Kaoo2K/6KfoUJmUnmdRIoDFBQFU+WZjTG44wyulkhAh YOhvfMDQ2tyzBzfL2tkM8uoh9jF9p8yI70d1K+p5YNsKkvuJofSTC9VkyHT7afaGu0nq GTS7dytln8s4HoveUl/h2SLae9PVA13CJQSHom3TTWeniN/7HuSfPNBhurQQhzCNEgqE ECqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752512129; x=1753116929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/WAd9m8e33PKa1oGnuqT0APNMRjVofzTCm9BK9/hgKY=; b=ETHpDmTqhO8Y+9h83HGHiJoTlHAQa4Dx0xaXe+N/W74IGFRk2mUKxu+GDAsTXjLEk7 ExFIfVsVsv546KeZsiDL4ptcdxYBCWIgn2kPLFWMipaha7BMg0WAyOe96B5auWRW2B8L JQA2tAZFMzQOIikWTS14y5EADIglRX6lQTCQDTcugTfcBSdBg6q6b1SjogklsDWsegIP zFdws6qItsaf+S+hrlrJcr2u7JdPVuuoSI2iYpbPg2NCualPDK4I3tjitympuzfo+jhi djnZCqO0sfR7q3fCDbspzup9F9s8kXamV6tSlPBv5k1xtLA2rFUkb5EZ6TURomKNQa4i e6+Q== X-Forwarded-Encrypted: i=1; AJvYcCUAJTzT2cK96O13sqqUC886RzbnIlhIRUR8BGbyR3IBCQkWOhNP5akXPr2TBQ8U27LRqzyOs2va9X0D@nongnu.org X-Gm-Message-State: AOJu0YyiujY4CbCVsLdQkHjraFVi01z8qOT1RZLca+HwvweoljJhLHno Bdgnqa0rrOazwPoQoo5OFBVSbjlXgCJGDnfJMgaEH+QsRc9aw4rKoKN3WpHOwsGS6aA= X-Gm-Gg: ASbGncsgmwuuZKdhwLV7eNZIWXbpNNg5Iuuvg38ceCFkzPYoK3FYU/p51c+jSOieuY5 phUOf2dnBCJ+n1sAqJG0LsPa+4ZnZgac4uiS4ffla7ccA7XiWE/k/3lopPyp+Iaxw/n6S8BDIKm EsdHBoNPQgJantSca4mK4pIzWSmkSNypveHizrI+nHZpOCmMzDoVpv9Oi3Rv5Y9HDWG4asQWEOT UmoAZyVtfOIIkogOmzxxRBOgIBz4/amSzVhHurLDa2ffRUhYw4B8w+R91kDBuemfI+e2s2xKRFd 4mlRc8aFhje0oTJ9ctfXrHzPJ6r2kwsd2o01xduiEt1fxC/BYyxMnkXNoNTWS9qLElxP/DMw+YL weVCHnxw1M85Av6il/m4Z/FaYxC/g X-Google-Smtp-Source: AGHT+IF+w0jSj/V7Z7QVWt/OlBIfPTwpI8k28WpIjSbSUuDO/4L33AITtFyF7HxsIxbe/DQsoeDQew== X-Received: by 2002:a05:6000:4813:b0:3a5:6860:f47f with SMTP id ffacd0b85a97d-3b609522266mr325287f8f.6.1752512129388; Mon, 14 Jul 2025 09:55:29 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Tyrone Ting , Hao Wu , Jason Wang Subject: [PATCH 3/4] hw/net/npcm_gmac.c: Correct test for when to reallocate packet buffer Date: Mon, 14 Jul 2025 17:55:22 +0100 Message-ID: <20250714165523.1956235-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714165523.1956235-1-peter.maydell@linaro.org> References: <20250714165523.1956235-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42f.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752516410955116600 Content-Type: text/plain; charset="utf-8" In gmac_try_send_next_packet() we have code that does "if this block of data won't fit in the buffer, reallocate it". However, the condition it uses is if ((prev_buf_size + tx_buf_len) > sizeof(buf)) where buf is a uint8_t *. This means that sizeof(buf) is always 8 bytes, and the condition will almost always be true, so we will reallocate the buffer more often than we need to. Correct the condition to test against tx_buffer_size, which is where we track how big the allocated buffer is. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/npcm_gmac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/net/npcm_gmac.c b/hw/net/npcm_gmac.c index a0050a7725f..0c17ae9b2a9 100644 --- a/hw/net/npcm_gmac.c +++ b/hw/net/npcm_gmac.c @@ -569,7 +569,7 @@ static void gmac_try_send_next_packet(NPCMGMACState *gm= ac) tx_buf_len =3D TX_DESC_TDES1_BFFR1_SZ_MASK(tx_desc.tdes1); buf =3D &tx_send_buffer[prev_buf_size]; =20 - if ((prev_buf_size + tx_buf_len) > sizeof(buf)) { + if ((prev_buf_size + tx_buf_len) > tx_buffer_size) { tx_buffer_size =3D prev_buf_size + tx_buf_len; tx_send_buffer =3D g_realloc(tx_send_buffer, tx_buffer_size); buf =3D &tx_send_buffer[prev_buf_size]; @@ -591,7 +591,7 @@ static void gmac_try_send_next_packet(NPCMGMACState *gm= ac) tx_buf_len =3D TX_DESC_TDES1_BFFR2_SZ_MASK(tx_desc.tdes1); buf =3D &tx_send_buffer[prev_buf_size]; =20 - if ((prev_buf_size + tx_buf_len) > sizeof(buf)) { + if ((prev_buf_size + tx_buf_len) > tx_buffer_size) { tx_buffer_size =3D prev_buf_size + tx_buf_len; tx_send_buffer =3D g_realloc(tx_send_buffer, tx_buffer_siz= e); buf =3D &tx_send_buffer[prev_buf_size]; --=20 2.43.0 From nobody Sat Nov 15 10:54:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752516068; cv=none; d=zohomail.com; s=zohoarc; b=FSmO1LLBz3e5aIN0SsYOGShOH9LWVfx7I32j/0Z/63TdFEiCR/YKqSP2hTC7iuX0YIuvinwfaULYjqlTPC7Hyn5CT/3rCgNqqsRfU9iqu0tM5RONq8I6RG0b1RQBYkti9z5+cn0IJBGGvt0tsRNbi6U44RHdOHlB3tpZobnpvEc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752516068; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XB8LV3wRsOBPp4JPpXFjqFOjZLlAFG+bPFbYCEIwFxs=; b=JU87j/v5OBvtCcTrlQ79P4YfjB6pwt9sqR88MqrxyA2wO2eunAzldygntGZ1Kx5j9h9jRJe3aiL++6nBR36GMm5vfcw/IYgE8yg2z6IolXF61rM1usGuyOPTesbDh2J0jm3h/1SatviyYGihivzmFWCO1WOV4mmU9o9iIzv4XbI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752516068347231.89053164907375; Mon, 14 Jul 2025 11:01:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubNTj-0004DP-A1; Mon, 14 Jul 2025 14:00:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubMSk-0004a5-8R for qemu-devel@nongnu.org; Mon, 14 Jul 2025 12:55:34 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ubMSi-0001JP-6U for qemu-devel@nongnu.org; Mon, 14 Jul 2025 12:55:33 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-455e6fb8057so32482895e9.3 for ; Mon, 14 Jul 2025 09:55:31 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8bd15bfsm13164665f8f.19.2025.07.14.09.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 09:55:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752512130; x=1753116930; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XB8LV3wRsOBPp4JPpXFjqFOjZLlAFG+bPFbYCEIwFxs=; b=Owg0guTatUlOe0bdf2ohgOheEFnIRITumbe3LrFvhDV3I+J/osTnc7UPuM+d0LygaA +w0UtvQEcBHLKytPT6jBOaLTMWnNFvF5CrvSK3GBDvBMTDJr4ACRfnDDbbAg/D5XyUcd G6B6k6IuWTho7S/lQO38gill8lNxmIT/W1rLe6rmMqRiBwPYFxo//FtPMSm0xFZkl2T3 Ajm9xIjXDqNsq6IdYHhK/UQsIOhthKBs2I5H12P+FWDxMaGbI0Tzr9a0Z5FacKDxM6QG BSrv7MQf3m+1V0tDVXvlp5QsgKiYI/58Sl5d6xQSiav/XYmc1pbGYoQvEgND5A2AG0Gn T3tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752512130; x=1753116930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XB8LV3wRsOBPp4JPpXFjqFOjZLlAFG+bPFbYCEIwFxs=; b=YcsN6FU5xKP5imgGSPPjoz3Yu/V/e1qtCsRPE3O7htGcxE6dYMmdFaHk98uaXky85S P8kX87AHZcdEU+ABYKmGofsYTv6CmKxxIn7eczvznWXwoEWvSW3pej4Kquxayk+7ZptH NUXBknRotZkKxGPoT93oi197N9f1xSNxrmQv3IIRkLKetDpiPd2W59MrBzVj02oAL/Nt ZqqujV9BPfvouRmWfMDT5k3kkhXz43QEVtkQ7iQlQEAL0aTtvnMPZhPPzL+OJISi1/OO 5VKJMxBAPi6101eG5HFrFbVPvjpVm/50Geqr1un7Q9PEAOB6CnDzxJae1skcUnZ7ItO5 uLjw== X-Forwarded-Encrypted: i=1; AJvYcCXW3qHxJLtrtuv08buaHV3S91rqbx1iq/Z88dPFtprg2Yzzf+6MTQyn6u95NbGuTloD7WmHLTdqdFC1@nongnu.org X-Gm-Message-State: AOJu0YyRpgeac2Jy2INkOVOJOgmYoDgUJEykomHuNYRFzfSjdUauLw7E hHLN7mTzgBU/l229rpgbNL8a05aeP4xsR+5rphRwnS4nu28wYxmVNtS4Bp81Ve2/hapIp+2BWOj dJ18N X-Gm-Gg: ASbGnctlwRyE6yJ8yz+Gwj4FA6v1v8uNHkb7QUr7OnwNOj+xq3YYadr437O2QQhENng qIgyhoV3FZAhkrcm72yE65nNAPVjXSE0XjAkxSHlSNnwvfn6vwZ6kcA7hI27ogIjvooDNa8qKTw vbJ9QyrofmzFRsY5H8S4f+3EBI9eX1iftYR6yw664q1Kg4uxyyvOtzuw94DAz03+BNtxMSeCi4P 8/ntM1DlgsD+j6ws1DEj8e4zgUMU2s7WdCfiRHVldLVenR9yFsCqdTDh9lLi3nKSuXH58P5QgDE //JwzVc9tD9Su/w9TsRWT2lXX1az1RfgGLRDRVy5VfdOR0Par7Pkh+nyXXa8+F0Hi+F/Uyy4Etn XKRYlqgDKzqpcBwEFpgn6/VUhxDyT X-Google-Smtp-Source: AGHT+IH+/REJ7B+DItU8aASH5jnaoFcfOBxm3LgKHunU9aheiEThUjx2kOxgBM45dgVhV+9NQZKjCg== X-Received: by 2002:a05:6000:1882:b0:3a3:6595:9209 with SMTP id ffacd0b85a97d-3b5f2dfdfdfmr11245919f8f.36.1752512130542; Mon, 14 Jul 2025 09:55:30 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Tyrone Ting , Hao Wu , Jason Wang Subject: [PATCH 4/4] hw/net/npcm_gmac.c: Drop 'buf' local variable Date: Mon, 14 Jul 2025 17:55:23 +0100 Message-ID: <20250714165523.1956235-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714165523.1956235-1-peter.maydell@linaro.org> References: <20250714165523.1956235-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32b.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752516070784116600 Content-Type: text/plain; charset="utf-8" We use the local variable 'buf' only when we call dma_memory_read(), and it is always set to &tx_send_buffer[prev_buf_size] immediately before both of those calls. So remove the variable and pass tx_send_buffer + prev_buf_size to dma_memory_read(). This fixes in passing a place where we set buf =3D tx_send_buffer but never used that value because we always updated buf to something else later before using it. Coverity: CID 1534027 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/npcm_gmac.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/hw/net/npcm_gmac.c b/hw/net/npcm_gmac.c index 0c17ae9b2a9..5e32cd3edf3 100644 --- a/hw/net/npcm_gmac.c +++ b/hw/net/npcm_gmac.c @@ -516,7 +516,6 @@ static void gmac_try_send_next_packet(NPCMGMACState *gm= ac) uint32_t desc_addr; struct NPCMGMACTxDesc tx_desc; uint32_t tx_buf_addr, tx_buf_len; - uint8_t *buf =3D tx_send_buffer; uint32_t prev_buf_size =3D 0; int csum =3D 0; =20 @@ -567,16 +566,15 @@ static void gmac_try_send_next_packet(NPCMGMACState *= gmac) tx_buf_addr =3D tx_desc.tdes2; gmac->regs[R_NPCM_DMA_CUR_TX_BUF_ADDR] =3D tx_buf_addr; tx_buf_len =3D TX_DESC_TDES1_BFFR1_SZ_MASK(tx_desc.tdes1); - buf =3D &tx_send_buffer[prev_buf_size]; =20 if ((prev_buf_size + tx_buf_len) > tx_buffer_size) { tx_buffer_size =3D prev_buf_size + tx_buf_len; tx_send_buffer =3D g_realloc(tx_send_buffer, tx_buffer_size); - buf =3D &tx_send_buffer[prev_buf_size]; } =20 /* step 5 */ - if (dma_memory_read(&address_space_memory, tx_buf_addr, buf, + if (dma_memory_read(&address_space_memory, tx_buf_addr, + tx_send_buffer + prev_buf_size, tx_buf_len, MEMTXATTRS_UNSPECIFIED)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read packet @ 0x= %x\n", __func__, tx_buf_addr); @@ -589,15 +587,14 @@ static void gmac_try_send_next_packet(NPCMGMACState *= gmac) tx_buf_addr =3D tx_desc.tdes3; gmac->regs[R_NPCM_DMA_CUR_TX_BUF_ADDR] =3D tx_buf_addr; tx_buf_len =3D TX_DESC_TDES1_BFFR2_SZ_MASK(tx_desc.tdes1); - buf =3D &tx_send_buffer[prev_buf_size]; =20 if ((prev_buf_size + tx_buf_len) > tx_buffer_size) { tx_buffer_size =3D prev_buf_size + tx_buf_len; tx_send_buffer =3D g_realloc(tx_send_buffer, tx_buffer_siz= e); - buf =3D &tx_send_buffer[prev_buf_size]; } =20 - if (dma_memory_read(&address_space_memory, tx_buf_addr, buf, + if (dma_memory_read(&address_space_memory, tx_buf_addr, + tx_send_buffer + prev_buf_size, tx_buf_len, MEMTXATTRS_UNSPECIFIED)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read packet @ 0x%x\n", @@ -615,7 +612,6 @@ static void gmac_try_send_next_packet(NPCMGMACState *gm= ac) net_checksum_calculate(tx_send_buffer, length, csum); qemu_send_packet(qemu_get_queue(gmac->nic), tx_send_buffer, le= ngth); trace_npcm_gmac_packet_sent(DEVICE(gmac)->canonical_path, leng= th); - buf =3D tx_send_buffer; prev_buf_size =3D 0; } =20 --=20 2.43.0