From patchwork Mon Jul 22 16:07:39 2024 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: 13738926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1F438C3DA7F for ; Mon, 22 Jul 2024 16:08:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVvZx-0005Z3-Rl; Mon, 22 Jul 2024 12:08:02 -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 1sVvZu-0005NJ-N3 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:07:59 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sVvZs-0007gS-P9 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:07:58 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-367990aaef3so2359060f8f.0 for ; Mon, 22 Jul 2024 09:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721664474; x=1722269274; 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=Qcm1dWrebznI1t8ebTrFn2d5NidY82tKkmYUS0FD2gQ=; b=NLV8eCeEiYdnLs8qvOnojSPbb3yEkQyxJY7ossDISd215Lb+4C4m9MnbsOvrR/OEkF njJw9aazeaFsET3BcQqW3VQ965dXapeQQzT4U6rdV7lnxdhOG3amI7IIqfqsox4OKCcK Po/E0iJkai2HDfh/NZJvDCFQH4ZjdfINvy/KHf2KQuCQeC5MUG08Vre37g0OxvmZfUI0 eEjyEUGrsmqskI+bRH+JSNfY/Lk/gbzO6/EdR/FqguNRdKBLzBCJKUFl9ZNW65u1NmPm k2hNKG51CztPX4+lc2S4VDF/kFArQEofD84bssQP2JlQz6hltol73gZwAvAJOM8HhWZJ f9yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721664474; x=1722269274; 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=Qcm1dWrebznI1t8ebTrFn2d5NidY82tKkmYUS0FD2gQ=; b=ecRYQKlRq1764sy8VWQ5PGnQw8tvdCto7or0v7cok5kXrcplOoWo/oJ+8XTQNEK3D5 AR7ecRzPjg0YNtuBWcCmgxdxk1KiNvyzrgO3JG2vIgGUWKBUCq7C29bpR+LsjZ2V0ejP k9KVWgKQpMuEaKJcQZXixpLLFoNl3NAnhsViNzoD2ogO0zf7/EczkF3tQ2xSw73pr7HG pp0TN9UKjcCK9Kh7tEa2rE2k6YllGQ2YHienbzJn0eVmLLAU7QHVJjlAAis4Q+xxjmXY FLmU92WI5hCbrc3crpgxRJxAjMOc4d72cGMycW6skeT5ovdAPCMs72Ur0hEsvPVCxirl vyZw== X-Gm-Message-State: AOJu0YyANUqmKnX6EqIoh3FGG15GxRd3Eb1ALquC1GxWIiGhweDUWzxW Bx1wA/0vhP0czcDtwD8k8PH8sc5BfnWE6M0ti6x4gupQfzRyZN5Ljoa47gcMcVDxdcFmHZj2WD8 w X-Google-Smtp-Source: AGHT+IHUiOdd5zhKEM8wd0wDnkyHCYq8h5McOhCLMzlh0XaA3hJKKozIc1odihHXY0dc7Ih77ZpZEQ== X-Received: by 2002:a5d:6b02:0:b0:368:420e:b790 with SMTP id ffacd0b85a97d-369debf8ba2mr218506f8f.14.1721664474403; Mon, 22 Jul 2024 09:07:54 -0700 (PDT) Received: from localhost.localdomain (gen92-h02-176-184-20-254.dsl.sta.abo.bbox.fr. [176.184.20.254]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-368787cec6bsm8920870f8f.71.2024.07.22.09.07.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 Jul 2024 09:07:54 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 1/7] chardev/char-fe: Document returned value on error Date: Mon, 22 Jul 2024 18:07:39 +0200 Message-ID: <20240722160745.67904-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722160745.67904-1-philmd@linaro.org> References: <20240722160745.67904-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philmd@linaro.org; helo=mail-wr1-x42c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org qemu_chr_fe_add_watch() and qemu_chr_fe_write[_all]() return -1 on error. Mention it in the documentation. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Mark Cave-Ayland Reviewed-by: Pierrick Bouvier --- include/chardev/char-fe.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h index ecef182835..3310449eaf 100644 --- a/include/chardev/char-fe.h +++ b/include/chardev/char-fe.h @@ -228,6 +228,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond, * is thread-safe. * * Returns: the number of bytes consumed (0 if no associated Chardev) + * or -1 on error. */ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len); @@ -242,6 +243,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len); * attempted to be written. This function is thread-safe. * * Returns: the number of bytes consumed (0 if no associated Chardev) + * or -1 on error. */ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len); @@ -253,6 +255,7 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len); * Read data to a buffer from the back end. * * Returns: the number of bytes read (0 if no associated Chardev) + * or -1 on error. */ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len); From patchwork Mon Jul 22 16:07:40 2024 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: 13738929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A8323C3DA59 for ; Mon, 22 Jul 2024 16:09:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVva4-0005ym-W7; Mon, 22 Jul 2024 12:08:09 -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 1sVva2-0005sO-62 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:06 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sVvZz-0007hE-Ej for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:05 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4266edee10cso29846205e9.2 for ; Mon, 22 Jul 2024 09:08:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721664480; x=1722269280; 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=7xJItyCJvAqsvrHU7PZNhwclTP7/Jt4LLoVoT2duvA4=; b=FVn1Wsq3Md3trySmqkfE6FomzYGZFvBMtvOHBrKyfhNr/9Ec6mhBiVQn529Bq8Ufv1 /TxSEnbyITh1B0ivq8mKT26o6wHA9I1Dhrkxv1zfWjX80+bP+hhoUSB9q3COq++BBj0x bzQ+YaxYpzwa9dHlVSgtCk94dPVjxYDf/8lJz+r5tizHlFTKw8UWdzlWVeos2rjfOmWA vz2ziZhmmIFZ+2ID9aQc6TD/JG5zxhp0JJiy2xHrcJ1m8OAFGm/Wq/kI4sjI65w7iMHs RtsM3WZKBd7VfxqaekDPnUKMF/wdLmhOOiepWpbHSPXw2ibtxyl1VSCeyDVX50pSyDhV QQLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721664480; x=1722269280; 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=7xJItyCJvAqsvrHU7PZNhwclTP7/Jt4LLoVoT2duvA4=; b=tXSCm2CwhE/UdRmeA7RJdUqkMpv3cCrS4/rVsC8mUl9t1wn/I49FVfKzEf7Qaee1JD j3oH+6mUKqvpMAf45bni/KDnrcAo9B06rM+6d7bliAbKBqfZw1IjTvauWKJnC8mQ/i9h Z6ANP+tWXk4IIC+Ukccw63rMo/W0c8KZ7l//hAUq04BbCw0DCnTgVzfvB1x9R364/CEr 9NbR94GHeVMzvJPs2m8L/yJSS9r5reN3Oy9o7Vpke8FOfVuIpbzGGjCpjQjT3bW9ANkV Du808ALcjFXx2njkhkKiUtcdWnfS477O5M2Gl6M4FfTnArHJpXMDlS2B9GrymoL5lvhH 1IUA== X-Gm-Message-State: AOJu0YyDO4SeKXLLrzZGubgV+TCRbbm63Nszv5+9PXIm9Atg5O150y9W QxHkbPQKUDwpORlQvJ1oat3nfnVthJDCwS6JzWLOh+1PY9XfItKVM+RGHl7IRyRPxwp8XCZafOX Y X-Google-Smtp-Source: AGHT+IFqArkBzzba1fN0z7xyB/r40W2L6JmFpYslhqOtrFoHGSCCadHo/zv77pYzxAPvfGOTsoCTqg== X-Received: by 2002:a05:600c:3c9d:b0:426:6099:6eaa with SMTP id 5b1f17b1804b1-427daa61cddmr54009415e9.26.1721664480241; Mon, 22 Jul 2024 09:08:00 -0700 (PDT) Received: from localhost.localdomain (gen92-h02-176-184-20-254.dsl.sta.abo.bbox.fr. [176.184.20.254]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d68fa394sm132786425e9.3.2024.07.22.09.07.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 Jul 2024 09:07:59 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 2/7] util/fifo8: Fix style Date: Mon, 22 Jul 2024 18:07:40 +0200 Message-ID: <20240722160745.67904-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722160745.67904-1-philmd@linaro.org> References: <20240722160745.67904-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=philmd@linaro.org; helo=mail-wm1-x334.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Pierrick Bouvier Reviewed-by: Mark Cave-Ayland --- include/qemu/fifo8.h | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index c6295c6ff0..2692d6bfda 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -15,10 +15,9 @@ typedef struct { * @fifo: struct Fifo8 to initialise with new FIFO * @capacity: capacity of the newly created FIFO * - * Create a FIFO of the specified size. Clients should call fifo8_destroy() + * Create a FIFO of the specified capacity. Clients should call fifo8_destroy() * when finished using the fifo. The FIFO is initially empty. */ - void fifo8_create(Fifo8 *fifo, uint32_t capacity); /** @@ -26,9 +25,8 @@ void fifo8_create(Fifo8 *fifo, uint32_t capacity); * @fifo: FIFO to cleanup * * Cleanup a FIFO created with fifo8_create(). Frees memory created for FIFO - *storage. The FIFO is no longer usable after this has been called. + * storage. The FIFO is no longer usable after this has been called. */ - void fifo8_destroy(Fifo8 *fifo); /** @@ -39,7 +37,6 @@ void fifo8_destroy(Fifo8 *fifo); * Push a data byte to the FIFO. Behaviour is undefined if the FIFO is full. * Clients are responsible for checking for fullness using fifo8_is_full(). */ - void fifo8_push(Fifo8 *fifo, uint8_t data); /** @@ -52,7 +49,6 @@ void fifo8_push(Fifo8 *fifo, uint8_t data); * Clients are responsible for checking the space left in the FIFO using * fifo8_num_free(). */ - void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num); /** @@ -64,7 +60,6 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num); * * Returns: The popped data byte. */ - uint8_t fifo8_pop(Fifo8 *fifo); /** @@ -73,7 +68,7 @@ uint8_t fifo8_pop(Fifo8 *fifo); * @max: maximum number of bytes to pop * @numptr: pointer filled with number of bytes returned (can be NULL) * - * Pop a number of elements from the FIFO up to a maximum of max. The buffer + * Pop a number of elements from the FIFO up to a maximum of @max. The buffer * containing the popped data is returned. This buffer points directly into * the FIFO backing store and data is invalidated once any of the fifo8_* APIs * are called on the FIFO. @@ -82,7 +77,7 @@ uint8_t fifo8_pop(Fifo8 *fifo); * around in the ring buffer; in this case only a contiguous part of the data * is returned. * - * The number of valid bytes returned is populated in *numptr; will always + * The number of valid bytes returned is populated in *@numptr; will always * return at least 1 byte. max must not be 0 or greater than the number of * bytes in the FIFO. * @@ -99,7 +94,7 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); * @max: maximum number of bytes to peek * @numptr: pointer filled with number of bytes returned (can be NULL) * - * Peek into a number of elements from the FIFO up to a maximum of max. + * Peek into a number of elements from the FIFO up to a maximum of @max. * The buffer containing the data peeked into is returned. This buffer points * directly into the FIFO backing store. Since data is invalidated once any * of the fifo8_* APIs are called on the FIFO, it is the caller responsibility @@ -109,7 +104,7 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); * around in the ring buffer; in this case only a contiguous part of the data * is returned. * - * The number of valid bytes returned is populated in *numptr; will always + * The number of valid bytes returned is populated in *@numptr; will always * return at least 1 byte. max must not be 0 or greater than the number of * bytes in the FIFO. * @@ -126,7 +121,6 @@ const uint8_t *fifo8_peek_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); * * Reset a FIFO. All data is discarded and the FIFO is emptied. */ - void fifo8_reset(Fifo8 *fifo); /** @@ -137,7 +131,6 @@ void fifo8_reset(Fifo8 *fifo); * * Returns: True if the fifo is empty, false otherwise. */ - bool fifo8_is_empty(Fifo8 *fifo); /** @@ -148,7 +141,6 @@ bool fifo8_is_empty(Fifo8 *fifo); * * Returns: True if the fifo is full, false otherwise. */ - bool fifo8_is_full(Fifo8 *fifo); /** @@ -159,7 +151,6 @@ bool fifo8_is_full(Fifo8 *fifo); * * Returns: Number of free bytes. */ - uint32_t fifo8_num_free(Fifo8 *fifo); /** @@ -170,7 +161,6 @@ uint32_t fifo8_num_free(Fifo8 *fifo); * * Returns: Number of used bytes. */ - uint32_t fifo8_num_used(Fifo8 *fifo); extern const VMStateDescription vmstate_fifo8; From patchwork Mon Jul 22 16:07:41 2024 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: 13738930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D0E7DC3DA5D for ; Mon, 22 Jul 2024 16:09:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVvaH-0006cX-AB; Mon, 22 Jul 2024 12:08:21 -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 1sVvaE-0006RF-ED for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:18 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sVva4-0007iF-RD for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:16 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-42797bcfc77so33679895e9.2 for ; Mon, 22 Jul 2024 09:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721664486; x=1722269286; 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=dS9AnThSzSBrSy+tonVpTP7pqJETnOM97XqDCYC+F+8=; b=d+aJKlWVVfxjDQ5KwyJPd2PqXzzi9o68EsqdlYlFnYcC/vR9M6V11ZWj0XEBODaWYB Wyy3dZW2C4k2Dc9grwxBQqIlu2w4glu5oBn1YwwyuLxM+e6zQQ9UmEbUFq8XakAwXQd6 LWWG018vaeFuuWJk/deOfkv/rz4eJp+ddJu99yG4PT386bq9W9hYSzfSK1aDIhlXMF06 dLyLgIjk8IZqA6/Nsq6/wtlP/kYF3AVz337DpARbXhxih4lItk+DGEqNCt9r3ourLFSr gmM4YfZ3yHIKlJWsTt+k72Zqu+2LIm3VXbfGK5bOyuRQHGlrj8msbPmChAkTB6cBeEFK +byA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721664486; x=1722269286; 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=dS9AnThSzSBrSy+tonVpTP7pqJETnOM97XqDCYC+F+8=; b=VztEMmNgUpI0hJqBhorOt9jZhSi8TnhFncTfDdCpW8L2TGdhreP7gY1N6e1XaiR3e0 I+Zaxx0uGnbbILZ43oh9md3Ld9W+PNuf6WIaPkiaXDkqwUKqnrp0deudF6BAVwHVvzoc kOj0sFRWLzLQlU29XbZ0fwhPRfwPps2KJc9rPEApfc4YF3xiVL9D+ODLj9WxKlVEU7jD s++kCd5YN2hcNd4oQWiWRbv3S6DSiuWlf18HWwfdJSvlvTYUDlhfUpxNlCaLEuHtl4Zw YgP2P/LyTUCF69pM282h6qYKUYGqQtzrCsESSGECdCkCHwD4BG6dnh58i0/+1qUTRrk3 QkMA== X-Gm-Message-State: AOJu0YzEfNG2c8r8rkXBAllwR1kR7l3YDJgNfA3rgJ867buIBxUChtWW pUK2TI+MHYn0IDdsFsKzsyVfHSKTLol+QLTKFb9MFDcMz4WOdUCrYED4Hg81CHE0GaEOxz8PLlq T X-Google-Smtp-Source: AGHT+IF//xZooh6F8wrQlhQGx3PPEaFSRd5iEOX4H6OK6eNunLO3B/Y4GiT1cQNAmy+3XU07ENp6ww== X-Received: by 2002:a05:600c:45d3:b0:425:649b:60e8 with SMTP id 5b1f17b1804b1-427df7b6d07mr45973825e9.18.1721664485987; Mon, 22 Jul 2024 09:08:05 -0700 (PDT) Received: from localhost.localdomain (gen92-h02-176-184-20-254.dsl.sta.abo.bbox.fr. [176.184.20.254]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e2a1sm159685935e9.31.2024.07.22.09.08.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 Jul 2024 09:08:05 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 3/7] util/fifo8: Use fifo8_reset() in fifo8_create() Date: Mon, 22 Jul 2024 18:07:41 +0200 Message-ID: <20240722160745.67904-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722160745.67904-1-philmd@linaro.org> References: <20240722160745.67904-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=philmd@linaro.org; helo=mail-wm1-x32a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Avoid open-coding fifo8_reset() in fifo8_create(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Mark Cave-Ayland Reviewed-by: Pierrick Bouvier --- util/fifo8.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/util/fifo8.c b/util/fifo8.c index 4e01b532d9..2925fe5611 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -16,12 +16,17 @@ #include "migration/vmstate.h" #include "qemu/fifo8.h" +void fifo8_reset(Fifo8 *fifo) +{ + fifo->num = 0; + fifo->head = 0; +} + void fifo8_create(Fifo8 *fifo, uint32_t capacity) { fifo->data = g_new(uint8_t, capacity); fifo->capacity = capacity; - fifo->head = 0; - fifo->num = 0; + fifo8_reset(fifo); } void fifo8_destroy(Fifo8 *fifo) @@ -97,12 +102,6 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) return fifo8_peekpop_buf(fifo, max, numptr, true); } -void fifo8_reset(Fifo8 *fifo) -{ - fifo->num = 0; - fifo->head = 0; -} - bool fifo8_is_empty(Fifo8 *fifo) { return (fifo->num == 0); From patchwork Mon Jul 22 16:07:42 2024 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: 13738931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4D9ECC3DA59 for ; Mon, 22 Jul 2024 16:09:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVvaU-0007UU-4r; Mon, 22 Jul 2024 12:08:35 -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 1sVvaP-0007F6-Tv for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:30 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sVvaL-0007nl-Hy for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:29 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4266fcb311cso33735985e9.1 for ; Mon, 22 Jul 2024 09:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721664502; x=1722269302; 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=g5IVJQKs0mRewT92ekkS2OE3V+7eufImd7ZnhLfAtiw=; b=QTXgPtLCanqqaoj8ztYfRyGNp7OdOHfMN/jCgmGlh8F5WfxrzZHMdxhcyqRj9/qGRC PV4P0mxJV6denC5cTxQxOmEGyfYfTs59+D5eYtZVIgGzBvd9ebC++m5E8Im8/CLeM7Uz Khc1zZpKpAgXW66naP07dKbcywx2tW8f4VR0YAaKxuXBSQSZC0kCeAMgZ1pK4S1q/O95 wn5yH8xxoKbjg30FSRVZUcylZIxwgYLzLw+IGLS4WnUOZZDm7eoLdXU4NDLbSupV9mHf oz7Q36Bx8lwOJjmxOYa15PrGJzasUkbZQG0v5IjW6INr7+RCg96XxC38BQSJ7VWpNmE9 yD/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721664502; x=1722269302; 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=g5IVJQKs0mRewT92ekkS2OE3V+7eufImd7ZnhLfAtiw=; b=cuTkbo/TfEtYrxoLgdMkHxJsNg7m+b3go3SvGJxJ8lWXV/5hdI5e/MtVyvkiuczSS/ S6uCPXp4lUKCwx9est7u6PaeOVTrK+RmnYzVYPcoeJmoo/3xIXpmzX3BOXleMg7noBzA 7+n9jNybsG9ecPloiDZc1cx0DnsevtZX1yL72AdhVXQsRhE9Fifkuaz6R1R5kpThSs7t X5T3GmxcTnfwYtPAIXzOxETUD0jBMVDokbZ/oyYt+wpnAFUYUiRR8sBMyx0PFEPeOw2t oRIYWpCiqv516XIlO5y2QNEBAy6Hgjgj8vpOvjIjOVLRG+2j48kBVV72osKa7fQMRpkZ Uz7Q== X-Gm-Message-State: AOJu0YyK1nmjKEl8MBJ3D9FDaoAzY4NhSX+CvNoeEKq60Z2SaLbYVeKO wXZyGbPmpo4xljW7V8mrpxkSPK6ziCbHxJ24ugk36TlZBY0HGLdYfGWedibIndXXLc+D8m/NiR9 8 X-Google-Smtp-Source: AGHT+IES0/0Gp6R84KpnzozIZodYH7Kb9siP7ixWABhurMCjoRnsqoUxlHz7lH8/H+pAi3dKtB6eWg== X-Received: by 2002:a05:600c:1c9e:b0:423:791:f446 with SMTP id 5b1f17b1804b1-427dc51a01emr45867695e9.7.1721664491827; Mon, 22 Jul 2024 09:08:11 -0700 (PDT) Received: from localhost.localdomain (gen92-h02-176-184-20-254.dsl.sta.abo.bbox.fr. [176.184.20.254]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a7257esm158849065e9.28.2024.07.22.09.08.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 Jul 2024 09:08:11 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 4/7] util/fifo8: Rename fifo8_peek_buf() -> fifo8_peek_constbuf() Date: Mon, 22 Jul 2024 18:07:42 +0200 Message-ID: <20240722160745.67904-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722160745.67904-1-philmd@linaro.org> References: <20240722160745.67904-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Since fifo8_peek_buf() return a const buffer (which points directly into the FIFO backing store), rename it using the 'constbuf' suffix. This will help differentiate with methods *copying* the FIFO data. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Pierrick Bouvier Reviewed-by: Mark Cave-Ayland --- include/qemu/fifo8.h | 4 ++-- hw/scsi/esp.c | 2 +- util/fifo8.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index 2692d6bfda..79450f4583 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -89,7 +89,7 @@ uint8_t fifo8_pop(Fifo8 *fifo); const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); /** - * fifo8_peek_buf: read upto max bytes from the fifo + * fifo8_peek_constbuf: read upto max bytes from the fifo * @fifo: FIFO to read from * @max: maximum number of bytes to peek * @numptr: pointer filled with number of bytes returned (can be NULL) @@ -113,7 +113,7 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); * * Returns: A pointer to peekable data. */ -const uint8_t *fifo8_peek_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); +const uint8_t *fifo8_peek_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); /** * fifo8_reset: diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 8504dd30a0..526ed91bef 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -486,7 +486,7 @@ static bool esp_cdb_ready(ESPState *s) return false; } - pbuf = fifo8_peek_buf(&s->cmdfifo, len, &n); + pbuf = fifo8_peek_constbuf(&s->cmdfifo, len, &n); if (n < len) { /* * In normal use the cmdfifo should never wrap, but include this check diff --git a/util/fifo8.c b/util/fifo8.c index 2925fe5611..21943c6032 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -92,7 +92,7 @@ static const uint8_t *fifo8_peekpop_buf(Fifo8 *fifo, uint32_t max, return ret; } -const uint8_t *fifo8_peek_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) +const uint8_t *fifo8_peek_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) { return fifo8_peekpop_buf(fifo, max, numptr, false); } From patchwork Mon Jul 22 16:07:43 2024 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: 13738935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 87377C3DA5D for ; Mon, 22 Jul 2024 16:11:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVvaX-0007xL-NN; Mon, 22 Jul 2024 12:08:37 -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 1sVvaV-0007ly-P0 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:35 -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 1sVvaR-0007oY-NQ for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:35 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4279c924ca7so32747795e9.2 for ; Mon, 22 Jul 2024 09:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721664508; x=1722269308; 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=D13SsLbTdb+rPn3f2Roi8BU4ul1b5GgWpSQvaH/PkW0=; b=HTc7vL43soHt7J6N36/gUO0tC/QXqOJoRM/m2NjFiZwn0Ji5lF3DYub8vZ3RCM0ozp H0M7ASpBR5eNIWXKy+WDre3635XoGouBHqiE0rJc8DitqFXKyaYzvSIcdTTKOfsAme0H jH3bXTae42i61HHa+4kJFayaJBgU7DMU/Tud7M7J+I8aDuurmnpcq6bma0NQFjmgrJwv g31NKensoH7tS59Ec/QTC0aXySN22Wh4mflcDPwa4JZMs42N7YOAeJGSSzALtss6KTjE DNz6+f+Gnwm8xuCFYRaIAOvPEhyZCvd4wfH8Cd5i25PcBBVZYByZPsLG3/dEfXwqs51s EHxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721664508; x=1722269308; 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=D13SsLbTdb+rPn3f2Roi8BU4ul1b5GgWpSQvaH/PkW0=; b=eqGEyGmuQJAkq+FgUvhhkzksHTSF+YD44L8UHpxMuxe4yFcuPwTiPmHUxp0gd0ctC/ hbxMdZYBQEFe2SfXjyTk0Ps/wNbL1f9egIj4SmeV+6qrMf4cSOCZbMK80q3TDYTxUfZN EpjVCKCmNkdhOMJsWzkrbsZx+0CsP8Msssaj+X1LnuKJpNjPAk8L0lzejmzz6wtUU5rW 59Ib1ngx6I7JDQ9PFRh58QkA8Pj9K2CIu7Yk2SXia0NT/JYoAqb/5WlpF0bOp8Ec94IP aY7synxlj+v7FlG50ZVEdztf0mMmP+VtvTDjx1XJuF+lGkw3OULoYRyFirFo0XrOv5lS WoGw== X-Gm-Message-State: AOJu0YxiTOdfelTRJT+bGZmVO3yQnPD9dkCCiT5G/PJCxN26OyG0oeGb gm6B1O6w8zluiBJPLOMzgQ2WkRwA5LchYoqGaXRrg4+zOxZfnv7OrY00FbywfbbXkYQiN4caN94 S X-Google-Smtp-Source: AGHT+IHRr2Hse5CaEmOALI6VDv3D1w/NDKzUvtjoPzuh1A/PDTLZOczZbBtc36qmY7CP1Trc0EdJ8g== X-Received: by 2002:a05:600c:1d8f:b0:426:51dc:f6cd with SMTP id 5b1f17b1804b1-427dc529057mr55262845e9.18.1721664508179; Mon, 22 Jul 2024 09:08:28 -0700 (PDT) Received: from localhost.localdomain (gen92-h02-176-184-20-254.dsl.sta.abo.bbox.fr. [176.184.20.254]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-368787ced33sm8964748f8f.86.2024.07.22.09.08.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 Jul 2024 09:08:27 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 5/7] util/fifo8: Rename fifo8_pop_buf() -> fifo8_pop_constbuf() Date: Mon, 22 Jul 2024 18:07:43 +0200 Message-ID: <20240722160745.67904-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722160745.67904-1-philmd@linaro.org> References: <20240722160745.67904-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Since fifo8_pop_buf() return a const buffer (which points directly into the FIFO backing store), rename it using the 'constbuf' suffix. This will help differentiate with methods *copying* the FIFO data. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Pierrick Bouvier Reviewed-by: Mark Cave-Ayland --- include/qemu/fifo8.h | 4 ++-- chardev/msmouse.c | 2 +- hw/char/goldfish_tty.c | 4 ++-- hw/net/allwinner_emac.c | 2 +- hw/scsi/esp.c | 4 ++-- ui/console-vc.c | 2 +- ui/gtk.c | 2 +- util/fifo8.c | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index 79450f4583..686918a3a4 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -63,7 +63,7 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num); uint8_t fifo8_pop(Fifo8 *fifo); /** - * fifo8_pop_buf: + * fifo8_pop_constbuf: * @fifo: FIFO to pop from * @max: maximum number of bytes to pop * @numptr: pointer filled with number of bytes returned (can be NULL) @@ -86,7 +86,7 @@ uint8_t fifo8_pop(Fifo8 *fifo); * * Returns: A pointer to popped data. */ -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); +const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); /** * fifo8_peek_constbuf: read upto max bytes from the fifo diff --git a/chardev/msmouse.c b/chardev/msmouse.c index a774c397b4..08836d92e8 100644 --- a/chardev/msmouse.c +++ b/chardev/msmouse.c @@ -81,7 +81,7 @@ static void msmouse_chr_accept_input(Chardev *chr) const uint8_t *buf; uint32_t size; - buf = fifo8_pop_buf(&mouse->outbuf, MIN(len, avail), &size); + buf = fifo8_pop_constbuf(&mouse->outbuf, MIN(len, avail), &size); qemu_chr_be_write(chr, buf, size); len = qemu_chr_be_can_write(chr); avail -= size; diff --git a/hw/char/goldfish_tty.c b/hw/char/goldfish_tty.c index f8ff043c39..2c5004851d 100644 --- a/hw/char/goldfish_tty.c +++ b/hw/char/goldfish_tty.c @@ -69,7 +69,7 @@ static uint64_t goldfish_tty_read(void *opaque, hwaddr addr, static void goldfish_tty_cmd(GoldfishTTYState *s, uint32_t cmd) { uint32_t to_copy; - uint8_t *buf; + const uint8_t *buf; uint8_t data_out[GOLFISH_TTY_BUFFER_SIZE]; int len; uint64_t ptr; @@ -109,7 +109,7 @@ static void goldfish_tty_cmd(GoldfishTTYState *s, uint32_t cmd) len = s->data_len; ptr = s->data_ptr; while (len && !fifo8_is_empty(&s->rx_fifo)) { - buf = (uint8_t *)fifo8_pop_buf(&s->rx_fifo, len, &to_copy); + buf = fifo8_pop_constbuf(&s->rx_fifo, len, &to_copy); address_space_rw(&address_space_memory, ptr, MEMTXATTRS_UNSPECIFIED, buf, to_copy, 1); diff --git a/hw/net/allwinner_emac.c b/hw/net/allwinner_emac.c index 989839784a..3b0a2ee07e 100644 --- a/hw/net/allwinner_emac.c +++ b/hw/net/allwinner_emac.c @@ -349,7 +349,7 @@ static void aw_emac_write(void *opaque, hwaddr offset, uint64_t value, "allwinner_emac: TX length > fifo data length\n"); } if (len > 0) { - data = fifo8_pop_buf(fifo, len, &ret); + data = fifo8_pop_constbuf(fifo, len, &ret); qemu_send_packet(nc, data, ret); aw_emac_tx_reset(s, chan); /* Raise TX interrupt */ diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 526ed91bef..64384f9b0e 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -208,7 +208,7 @@ static uint32_t esp_fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, int maxlen) } len = maxlen; - buf = fifo8_pop_buf(fifo, len, &n); + buf = fifo8_pop_constbuf(fifo, len, &n); if (dest) { memcpy(dest, buf, n); } @@ -217,7 +217,7 @@ static uint32_t esp_fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, int maxlen) len -= n; len = MIN(len, fifo8_num_used(fifo)); if (len) { - buf = fifo8_pop_buf(fifo, len, &n2); + buf = fifo8_pop_constbuf(fifo, len, &n2); if (dest) { memcpy(&dest[n], buf, n2); } diff --git a/ui/console-vc.c b/ui/console-vc.c index 899fa11c94..e9906aae59 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -287,7 +287,7 @@ static void kbd_send_chars(QemuTextConsole *s) const uint8_t *buf; uint32_t size; - buf = fifo8_pop_buf(&s->out_fifo, MIN(len, avail), &size); + buf = fifo8_pop_constbuf(&s->out_fifo, MIN(len, avail), &size); qemu_chr_be_write(s->chr, buf, size); len = qemu_chr_be_can_write(s->chr); avail -= size; diff --git a/ui/gtk.c b/ui/gtk.c index bc29f7a1b4..a4db90e8cb 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1820,7 +1820,7 @@ static void gd_vc_send_chars(VirtualConsole *vc) const uint8_t *buf; uint32_t size; - buf = fifo8_pop_buf(&vc->vte.out_fifo, MIN(len, avail), &size); + buf = fifo8_pop_constbuf(&vc->vte.out_fifo, MIN(len, avail), &size); qemu_chr_be_write(vc->vte.chr, buf, size); len = qemu_chr_be_can_write(vc->vte.chr); avail -= size; diff --git a/util/fifo8.c b/util/fifo8.c index 21943c6032..31f0d34c0c 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -97,7 +97,7 @@ const uint8_t *fifo8_peek_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) return fifo8_peekpop_buf(fifo, max, numptr, false); } -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) +const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) { return fifo8_peekpop_buf(fifo, max, numptr, true); } From patchwork Mon Jul 22 16:07:44 2024 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: 13738932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 30531C3DA5D for ; Mon, 22 Jul 2024 16:10:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVvab-0008JW-Gn; Mon, 22 Jul 2024 12:08:41 -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 1sVvaZ-000886-Hn for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:39 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sVvaW-0007pM-Q4 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:39 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3686b554cfcso2099841f8f.1 for ; Mon, 22 Jul 2024 09:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721664514; x=1722269314; 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=PGm6Mz1jj/9Q+YEDysgdokwei7I83wY7MgFeQkOcKf0=; b=JdjdY55byPLMPG+fk+Dcqbn+dH3pk0WXmxp0000EIyGSuPGvB7gr7+UK0h058/KEOp 4umhkTUjQQigTuhqIZRjMgRDAcSPLiS0XSgyE38/ap2ERbuWkD+Uj1NoODtbuFMrlWSK +2djAQi+/iAYQmiMRVzWviNEMlMSMLQEpE6siOqYsckKJf4hpCuenCfX9jFOAICkWn2d UPhhT7ViUOcL+roH1/CLy/bWGuG9S79n0HYZE7FKPtJZoPa24KTTpNi0fCes2Yochwrw INwcD8qW9s53Lla4nMeYDgV6pqiDs0UYOx2F81iPuANZw79zpFFm+MI8D13xZCBbYdtA aP1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721664514; x=1722269314; 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=PGm6Mz1jj/9Q+YEDysgdokwei7I83wY7MgFeQkOcKf0=; b=glf2uWNyz3DoMtdhJXUHxofm6oPgkumm/CQQLYL4Zli3EGyikwoh9ULheKcsFArb6A CgZurkhPT2Kl8qv0W8xx+jqAfdGmd7aLSJ11iblilwU8h//Nj1a01pBqFc7leb3FXRfi PHhJ2th1AXMwmHwJiJJteFWRtzza64cyOaOLL9HmgQNTI9qMf/PYCq9XYxDO9RoeWviJ hOMXXOFX8nNQye8MzpTatAvmPJHCaeHmV9uLCYhZkw/8VSqGpeST4Krk0JKG9fwtRAZQ 7WGMoA3aAOyWc9fCUnm3WqkrcQqPt7kuThj8tnMTBvzXUv0r3OJc9JFq0ZTSMvpFf9nD vNzA== X-Gm-Message-State: AOJu0YxULcuewzlFxyoXrrpDDOJ64DA2nzeWC9sEuZqYWsAWeYd2Csyz n0IF6I/00kFpZMxo9XiPCdZDKK0CQY3QQelOAALbmFwVguQzUUHMGpjsEF+4Pqjdlids+JDQ4fO p X-Google-Smtp-Source: AGHT+IHcH+R92EgVUUK7+rC/5DXJUPRBaCYhT4ZqdHKasDuq1aj6JEc4vlAP87+dMEui+yHCllfbhw== X-Received: by 2002:a05:6000:4e6:b0:368:5a32:f5bc with SMTP id ffacd0b85a97d-369dee4fa8dmr206590f8f.38.1721664513985; Mon, 22 Jul 2024 09:08:33 -0700 (PDT) Received: from localhost.localdomain (gen92-h02-176-184-20-254.dsl.sta.abo.bbox.fr. [176.184.20.254]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3687868b5fdsm8860554f8f.38.2024.07.22.09.08.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 Jul 2024 09:08:33 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 6/7] util/fifo8: Expose fifo8_pop_buf() Date: Mon, 22 Jul 2024 18:07:44 +0200 Message-ID: <20240722160745.67904-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722160745.67904-1-philmd@linaro.org> References: <20240722160745.67904-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=philmd@linaro.org; helo=mail-wr1-x432.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Extract fifo8_pop_buf() from hw/scsi/esp.c and expose it as part of the API. This function takes care of non-contiguous (wrapped) FIFO buffer (which is an implementation detail). Suggested-by: Mark Cave-Ayland Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Pierrick Bouvier Reviewed-by: Mark Cave-Ayland --- include/qemu/fifo8.h | 14 ++++++++++++++ hw/scsi/esp.c | 36 +++--------------------------------- util/fifo8.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index 686918a3a4..21c7a22937 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -62,6 +62,20 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num); */ uint8_t fifo8_pop(Fifo8 *fifo); +/** + * fifo8_pop_buf: + * @fifo: FIFO to pop from + * @dest: the buffer to write the data into (can be NULL) + * @destlen: size of @dest and maximum number of bytes to pop + * + * Pop a number of elements from the FIFO up to a maximum of @destlen. + * The popped data is copied into the @dest buffer. + * Care is taken when the data wraps around in the ring buffer. + * + * Returns: number of bytes popped. + */ +uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen); + /** * fifo8_pop_constbuf: * @fifo: FIFO to pop from diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 64384f9b0e..cec847b54a 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -197,39 +197,9 @@ static uint8_t esp_fifo_pop(ESPState *s) return val; } -static uint32_t esp_fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, int maxlen) -{ - const uint8_t *buf; - uint32_t n, n2; - int len; - - if (maxlen == 0) { - return 0; - } - - len = maxlen; - buf = fifo8_pop_constbuf(fifo, len, &n); - if (dest) { - memcpy(dest, buf, n); - } - - /* Add FIFO wraparound if needed */ - len -= n; - len = MIN(len, fifo8_num_used(fifo)); - if (len) { - buf = fifo8_pop_constbuf(fifo, len, &n2); - if (dest) { - memcpy(&dest[n], buf, n2); - } - n += n2; - } - - return n; -} - static uint32_t esp_fifo_pop_buf(ESPState *s, uint8_t *dest, int maxlen) { - uint32_t len = esp_fifo8_pop_buf(&s->fifo, dest, maxlen); + uint32_t len = fifo8_pop_buf(&s->fifo, dest, maxlen); esp_update_drq(s); return len; @@ -335,7 +305,7 @@ static void do_command_phase(ESPState *s) if (!cmdlen || !s->current_dev) { return; } - esp_fifo8_pop_buf(&s->cmdfifo, buf, cmdlen); + fifo8_pop_buf(&s->cmdfifo, buf, cmdlen); current_lun = scsi_device_find(&s->bus, 0, s->current_dev->id, s->lun); if (!current_lun) { @@ -381,7 +351,7 @@ static void do_message_phase(ESPState *s) /* Ignore extended messages for now */ if (s->cmdfifo_cdb_offset) { int len = MIN(s->cmdfifo_cdb_offset, fifo8_num_used(&s->cmdfifo)); - esp_fifo8_pop_buf(&s->cmdfifo, NULL, len); + fifo8_pop_buf(&s->cmdfifo, NULL, len); s->cmdfifo_cdb_offset = 0; } } diff --git a/util/fifo8.c b/util/fifo8.c index 31f0d34c0c..6610b79182 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -102,6 +102,35 @@ const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) return fifo8_peekpop_buf(fifo, max, numptr, true); } +uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) +{ + const uint8_t *buf; + uint32_t n1, n2 = 0; + uint32_t len; + + if (destlen == 0) { + return 0; + } + + len = destlen; + buf = fifo8_pop_constbuf(fifo, len, &n1); + if (dest) { + memcpy(dest, buf, n1); + } + + /* Add FIFO wraparound if needed */ + len -= n1; + len = MIN(len, fifo8_num_used(fifo)); + if (len) { + buf = fifo8_pop_constbuf(fifo, len, &n2); + if (dest) { + memcpy(&dest[n1], buf, n2); + } + } + + return n1 + n2; +} + bool fifo8_is_empty(Fifo8 *fifo) { return (fifo->num == 0); From patchwork Mon Jul 22 16:07:45 2024 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: 13738933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9D9EBC3DA5D for ; Mon, 22 Jul 2024 16:10:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVvai-0000eR-W6; Mon, 22 Jul 2024 12:08:49 -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 1sVvah-0000YP-8H for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:47 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sVvad-0007qV-LP for qemu-devel@nongnu.org; Mon, 22 Jul 2024 12:08:46 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4266ea6a488so38728365e9.1 for ; Mon, 22 Jul 2024 09:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721664520; x=1722269320; 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=oLrYF0/Wx1i/Oi595G8nLiFu8j75+0aJtBHlGLk36ig=; b=K9YNVqLtWWTk+hxjMwf9Eatx1nXW+GfNWMwXRDGVMbXBREsT24Sh3+Rn6vzdaHlOXC YTHN6aYKqXS8b2nlRblCPlgwiCMp9PmyHMpCkarljXx0N4pruHFRpE+scBEx9WmNdK9D pb6pOP/iopkk/1cl3yoswM6JFh1EWRUSS7mT/wJlzbrhzbKmZf10PAAivQp+7XV+zZ4C CoOAi8ISS3AuO+pKEr2Kec/k1Vjx6CBym17pqHOL6jVrBft15dqV6pNtXi62urqSfnAK 9iUoQW+rZEPgZIleJwm0CAf7QVuKmxt0SYKu61urMPEP/YDgg7yuPoUyZ/bEfQF+ieVt GVFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721664520; x=1722269320; 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=oLrYF0/Wx1i/Oi595G8nLiFu8j75+0aJtBHlGLk36ig=; b=cfJbu0wlgoWQIrB6N0ooYnZ2lp9EV0dCfcN0gmkOLIUoG+aRcSfRlhOm0pSSQaTsZv W5VnqYmfBy63yy+iq6xPdy9NVu5L+toS5QDkNqHlmzunEYKRuyrjeMzT3fVOQprN7EbI MLA9YE776VZzNUtc9PX0CBbnChlaiy7KfMELEOYEmWXXZVokM2yfJbt5JDEALfvmg9+h GXh0O4cpAo/PDOHwv8zj+HGzlAZ04qH/mZgVW86SxZ58LR8x/zvtY/FUWHKPwqRNbC8H rr3TLJ/gg/Azsc2UJfl30Piszi16Kv/zrLD+b0KydTxSBt2Em6BJGPYIAWRIRJz6PELU eT4Q== X-Gm-Message-State: AOJu0YwLDPcY5MMeLUPzKtI7/qYVTMkS1ohyCo9onEx4UKt5x/lSeLsJ Lt+kKqKWEkMwqzj/Oo68ZXWrpRvYPapxNLcZJ0Ym5yVFR6G9gVjGUt5mB20vQitI+LYnYYagF/r m X-Google-Smtp-Source: AGHT+IGmGU63KNcR5lhPUTQT673NSNTIExqPMcMydnIJUtRXt0pgBbXK6AJt59/e9lh+rA71DDL5TA== X-Received: by 2002:a05:600c:3b26:b0:426:5b44:2be7 with SMTP id 5b1f17b1804b1-427dc5204bfmr69229835e9.10.1721664520226; Mon, 22 Jul 2024 09:08:40 -0700 (PDT) Received: from localhost.localdomain (gen92-h02-176-184-20-254.dsl.sta.abo.bbox.fr. [176.184.20.254]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427e29d11d5sm66473215e9.38.2024.07.22.09.08.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 Jul 2024 09:08:39 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 7/7] util/fifo8: Introduce fifo8_discard() Date: Mon, 22 Jul 2024 18:07:45 +0200 Message-ID: <20240722160745.67904-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722160745.67904-1-philmd@linaro.org> References: <20240722160745.67904-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=philmd@linaro.org; helo=mail-wm1-x32c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add the fifo8_discard() helper for clarity. It is a simple wrapper over fifo8_pop_buf(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Pierrick Bouvier Reviewed-by: Mark Cave-Ayland --- include/qemu/fifo8.h | 8 ++++++++ hw/scsi/esp.c | 2 +- util/fifo8.c | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index 21c7a22937..53bafabd25 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -129,6 +129,14 @@ const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); */ const uint8_t *fifo8_peek_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); +/** + * fifo8_discard: + * @fifo: FIFO to consume bytes + * + * Discard (consume) bytes from a FIFO. + */ +void fifo8_discard(Fifo8 *fifo, uint32_t len); + /** * fifo8_reset: * @fifo: FIFO to reset diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index cec847b54a..c703fa7351 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -351,7 +351,7 @@ static void do_message_phase(ESPState *s) /* Ignore extended messages for now */ if (s->cmdfifo_cdb_offset) { int len = MIN(s->cmdfifo_cdb_offset, fifo8_num_used(&s->cmdfifo)); - fifo8_pop_buf(&s->cmdfifo, NULL, len); + fifo8_discard(&s->cmdfifo, len); s->cmdfifo_cdb_offset = 0; } } diff --git a/util/fifo8.c b/util/fifo8.c index 6610b79182..ea39ca2552 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -131,6 +131,12 @@ uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) return n1 + n2; } +void fifo8_consume(Fifo8 *fifo, uint32_t len) +{ + len -= fifo8_pop_buf(fifo, NULL, len); + assert(len == 0); +} + bool fifo8_is_empty(Fifo8 *fifo) { return (fifo->num == 0);