From nobody Fri May 10 13:26:49 2024 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=1688563202; cv=none; d=zohomail.com; s=zohoarc; b=RAWbEnJTEK2ZeM2SEHzZz7HZQvFjYUhj136BRjUvYrVS1ks8rafXdnC32TmiMa3CZf7fPsTo7Gt65Vr+x4Fd3KgVcIMpO2j/wVhiyD5fzGJsfi/GWf6+OGt3sejBIYhtUuuUxJqS/O3ei37rs3nm+NXdcg9RBzAqp+yk5UBAArU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688563202; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=igb0JyNsA2PhSTz0dTyRLO9tMn947tv2lHWj3R8IWaI=; b=ZrOvPfrwhMF+ErskLdt5sj+D65O9R3Kda9F3vzm93js6/ge+NIFhYRH6aceQgYisld4igxHQsqoKWPzx3TemzSPmDBNwOspMWV4pn2S/rs3SXswHM+v/4+Ni0saMinf+O4BKbTXB4gDLtcMUVIFH7mvLudxlwEVfZkrYX9Id4JU= 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 1688563202703973.6497699386844; Wed, 5 Jul 2023 06:20:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qH2Pz-0007tt-5u; Wed, 05 Jul 2023 09:19:39 -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 1qH2Po-0007hN-Hu for qemu-devel@nongnu.org; Wed, 05 Jul 2023 09:19:30 -0400 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qH2Pk-00074d-H7 for qemu-devel@nongnu.org; Wed, 05 Jul 2023 09:19:28 -0400 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-51e29964942so278139a12.2 for ; Wed, 05 Jul 2023 06:19:21 -0700 (PDT) Received: from m1x-phil.lan ([176.176.142.96]) by smtp.gmail.com with ESMTPSA id a17-20020a50ff11000000b0051a4fcf7187sm12859379edu.62.2023.07.05.06.19.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 05 Jul 2023 06:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688563160; x=1691155160; 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=igb0JyNsA2PhSTz0dTyRLO9tMn947tv2lHWj3R8IWaI=; b=bybfZR6Z/vuhtdmB02MgRLaG+6BSZOPiqsYw1U/g+EwHUyEr8Hi7ULvPRtcuXljuTP xp/fzoEfuMeShNID74HAAAWDH/54lw5ob1j41hXV2AeR8NFICp0tLOIRLTaGRmU23KiX qOJKj8nUL7vUinVA1TBikbeCPLrDXcxmADXYWihr8+lN7NTCJFTZSmPrrR5O9SvS5smO 5GSleUPmPpU0GwW47xOSWLL8bwvRuvtNxp92+UpVapaNr/FZehkdKsnpN1vrbTaSFDww TUELwkHZxGymg2B3zByPqwB4DkdUaM01sNCFJ5UWw2dV41Q7kLwmeNHLq+U+SwtyVtHY QrBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688563160; x=1691155160; 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=igb0JyNsA2PhSTz0dTyRLO9tMn947tv2lHWj3R8IWaI=; b=TGB/ZD2gmv/8HD8TpB47kg67Yr3AqSrS/454Ze8rVKbpeMysuNZZsuDPXbBb1VZ1Be w+Hq4HHmMVTe+dL1b5sbVmSgkkP9dqLnMV4g/ssZprbMkza/i7J2pHM+tbO/0modB5up XKBSwOBXDYFpahUfpmiCp2HhfQTsZOFzZwpqg/PCCs7AlTG96AqtA2EGA3pGQiy9ltHW ptFJnRJdQ9U51BFvs2zg/xqoi+nHo4H4JHH2A6TfrSgxjktbyoWvdPNjW3sYQLa2/WFA SyLHFevuJL9XleJSGBojxBXOWJRz3Nnt6aIJc/D3opBNytwSW3wMJUTwlHPZljNuiOQJ 2w0Q== X-Gm-Message-State: ABy/qLYAQCgiCYAD1xDmrqmcFGzwsday84QaZEJuEr9DtUc/Bdx3CUnE /zsuCUFiNPysPMip5svnh9zBDinV14y4JXcQ/sk= X-Google-Smtp-Source: APBJJlEmVxSKmWN5A7LoyxH08TTEihkYGwSXQdL61kObadmKOMK4v6Lp4D+GzEtKeWCDr2IdPjgkrw== X-Received: by 2002:aa7:c74c:0:b0:51e:22d8:178e with SMTP id c12-20020aa7c74c000000b0051e22d8178emr3472345eds.18.1688563159936; Wed, 05 Jul 2023 06:19:19 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Francisco Iglesias , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v2 1/3] util/fifo8: Fix typo in fifo8_push_all() description Date: Wed, 5 Jul 2023 15:18:57 +0200 Message-Id: <20230705131859.53970-2-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230705131859.53970-1-philmd@linaro.org> References: <20230705131859.53970-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::52d; envelope-from=philmd@linaro.org; helo=mail-ed1-x52d.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1688563204832100003 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Francisco Iglesias Reviewed-by: Alex Benn=C3=A9e --- include/qemu/fifo8.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index 28bf2cee57..16be02f361 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -46,7 +46,7 @@ void fifo8_push(Fifo8 *fifo, uint8_t data); * fifo8_push_all: * @fifo: FIFO to push to * @data: data to push - * @size: number of bytes to push + * @num: number of bytes to push * * Push a byte array to the FIFO. Behaviour is undefined if the FIFO is fu= ll. * Clients are responsible for checking the space left in the FIFO using --=20 2.38.1 From nobody Fri May 10 13:26:49 2024 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=1688563206; cv=none; d=zohomail.com; s=zohoarc; b=KsILmBrWnwIyODZI7Dk9fMIB+r5wrj30DSAx1Hqv+o6vUIC6O0JRz+BOzBdRg5S30EX+FlPh6vkcuClqlopw83lpF4puS9TWJHsppDn4CKVt3kzwfsHi6EvSNtqZRbh2VELdRdBKuc+DD+DORq6b5By5iBtH5UE2k5huzwWSuxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688563206; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z9kg0aNLZM4S8bjUKxesX7u6cAm6btVjZ5SYrsKBPTY=; b=ZDneYxj/RFOTtancerAs3PjtU+vzvQ/5lxfmSs15cL7uecMvxnFqYbKaT0kuD+XaTj8AeLeM36VuQHovlczAWrtt4jBJb8aPSpZqpi7sbD9dy7Q+Llz8MJadT/AFpINfYfqZyIMTQ00dTrzWnoH2wTbFJouW3OoQO0p5sKFHZZY= 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 1688563206869563.2993690801378; Wed, 5 Jul 2023 06:20:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qH2Q2-0008Io-Fv; Wed, 05 Jul 2023 09:19: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 1qH2Pt-0007lg-QK for qemu-devel@nongnu.org; Wed, 05 Jul 2023 09:19:34 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qH2Pr-00075u-Kl for qemu-devel@nongnu.org; Wed, 05 Jul 2023 09:19:33 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-9891c73e0fbso140551166b.1 for ; Wed, 05 Jul 2023 06:19:31 -0700 (PDT) Received: from m1x-phil.lan ([176.176.142.96]) by smtp.gmail.com with ESMTPSA id k24-20020aa7c398000000b0051def9be785sm7062702edq.85.2023.07.05.06.19.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 05 Jul 2023 06:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688563169; x=1691155169; 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=Z9kg0aNLZM4S8bjUKxesX7u6cAm6btVjZ5SYrsKBPTY=; b=up+tjzeYMuoRy3EgEMNfJWCw+FsnqGns77gtu4TaKHBH99V2VVUbDhYs+nvhNxISYI uKdbct4fB4cn3/oXG/NjtAFn+cnETO/eR8T9VvypMDPMy4Rti8yaPd+Omo2z/J+YZ5jV lU8ToMQ1JnjxPRlHDly5YvqaaBnnoi1A+5A83UfF1dUqwL2SZ3jLD6NuE2C/HZriGJ0Z +dovGAKEviwMOrEOAWVV871H9evk7vmqkgph++ukL+1xAMxncDCoAGE8gazsx8fx0VI7 feCq1yuYsdGzpUYo+7F3/L8XLupM6mSJTIZEIYmwPK3Qb+UQmGKXQwDr/PPPgsMEbBHD dPIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688563169; x=1691155169; 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=Z9kg0aNLZM4S8bjUKxesX7u6cAm6btVjZ5SYrsKBPTY=; b=PpbtNmOdh8TZLHJ8PnBFabsaRyYIRXtV/1L9tJPkrlBVTaWVw1nr+rEf3Aw/GnUDDa mRMlQS6VbXNjazR3tyOdk59GWy0zl8Skxs2ZFINHq+YT6dyqyvvr2tIxUNKKVFKjJMGf TN/YiwdGioD24yil36ZBGLeLzePdbclCMYpCPHFFAw+Y5/tqd3TIaMNgA7fBDn0DU2NF kFLF5wrGvhsJh/zXGur32m0I/rQmzhiax7PM5G6FKFIKR1WiI8bDj5Eep96k/NULC2bj +jv7FoeTSHy0E12ewxfriYS5Up4AaqQJBctUH8fDOfBIfg3FwwFQDKI7hFsuUhl6sf42 pjXw== X-Gm-Message-State: ABy/qLYi0QnRfZ3lvqZuLBS8RresPpQWvp+tD7DzCU6p0FXJCH8pmpTw M3w/Hpu/KqECRQSQx8EGZwo14eI9CB2Zi5aVAyg= X-Google-Smtp-Source: APBJJlEBSXv6zc868BPuu8NCih9vlqtvg1AfyBsViPSg0J8CuePCE+6ZnL7cXaAFA11RCMgPYTe0Gw== X-Received: by 2002:a17:907:6285:b0:978:2b56:d76e with SMTP id nd5-20020a170907628500b009782b56d76emr1858262ejc.12.1688563169811; Wed, 05 Jul 2023 06:19:29 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Francisco Iglesias , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v2 2/3] util/fifo8: Allow fifo8_pop_buf() to not populate popped length Date: Wed, 5 Jul 2023 15:18:58 +0200 Message-Id: <20230705131859.53970-3-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230705131859.53970-1-philmd@linaro.org> References: <20230705131859.53970-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::62f; envelope-from=philmd@linaro.org; helo=mail-ej1-x62f.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1688563208828100001 There might be cases where we know the number of bytes we can pop from the FIFO, or we simply don't care how many bytes is returned. Allow fifo8_pop_buf() to take a NULL numptr. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Francisco Iglesias Reviewed-by: Alex Benn=C3=A9e --- include/qemu/fifo8.h | 10 +++++----- util/fifo8.c | 12 ++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index 16be02f361..d0d02bc73d 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -71,7 +71,7 @@ uint8_t fifo8_pop(Fifo8 *fifo); * fifo8_pop_buf: * @fifo: FIFO to pop from * @max: maximum number of bytes to pop - * @num: actual number of returned bytes + * @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 buff= er * containing the popped data is returned. This buffer points directly into @@ -82,16 +82,16 @@ uint8_t fifo8_pop(Fifo8 *fifo); * around in the ring buffer; in this case only a contiguous part of the d= ata * is returned. * - * The number of valid bytes returned is populated in *num; will always re= turn - * at least 1 byte. max must not be 0 or greater than the number of bytes = in - * the FIFO. + * 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. * * Clients are responsible for checking the availability of requested data * using fifo8_num_used(). * * Returns: A pointer to popped data. */ -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num); +const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); =20 /** * fifo8_reset: diff --git a/util/fifo8.c b/util/fifo8.c index d4d1c135e0..032e985440 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -66,16 +66,20 @@ uint8_t fifo8_pop(Fifo8 *fifo) return ret; } =20 -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num) +const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) { uint8_t *ret; + uint32_t num; =20 assert(max > 0 && max <=3D fifo->num); - *num =3D MIN(fifo->capacity - fifo->head, max); + num =3D MIN(fifo->capacity - fifo->head, max); ret =3D &fifo->data[fifo->head]; - fifo->head +=3D *num; + fifo->head +=3D num; fifo->head %=3D fifo->capacity; - fifo->num -=3D *num; + fifo->num -=3D num; + if (numptr) { + *numptr =3D num; + } return ret; } =20 --=20 2.38.1 From nobody Fri May 10 13:26:49 2024 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=1688563224; cv=none; d=zohomail.com; s=zohoarc; b=g2fdiTuju1QDgBJo8DbCqJEkdANpbI5YpgoUxZjysE5Y8IEqpjIaObITFGDqiCBOOyJ/fKu0C5k/Hb4VqFSBC/cVUWYBLS4VzZJCkpn9WO+4QPx6BIQ7ugC/LoQ79RbPKs4LCIG0rjyMk8ymteq6cwWhqa5y+238SmnLthr2ZOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688563224; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FSxovuSb9d76pAZNtRHp6Si7EzkK1vbEMwhu48Hxi5Q=; b=iaut4CoUK99SDTSfSHmK95f088ai1g4Dpgh8C94EDEQMOFiuhN7cvzaC9u3p+pJWORZzf7IT/HiF9bphWVsfPQhtPnFbkIxdjClQpjcev+j4fUYYylfxN/459hqP43Kcc9YnpJeuyM8iJUsoATSCXEbgkEMo47munealq3AWVA4= 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 1688563224782884.9379065402787; Wed, 5 Jul 2023 06:20:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qH2QY-00011Y-Uo; Wed, 05 Jul 2023 09:20:15 -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 1qH2QM-0000oD-KX for qemu-devel@nongnu.org; Wed, 05 Jul 2023 09:20:02 -0400 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qH2QK-0007B9-MK for qemu-devel@nongnu.org; Wed, 05 Jul 2023 09:20:02 -0400 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b69dcf45faso109834851fa.0 for ; Wed, 05 Jul 2023 06:20:00 -0700 (PDT) Received: from m1x-phil.lan ([176.176.142.96]) by smtp.gmail.com with ESMTPSA id ha22-20020a170906a89600b0098e0c0cfb66sm13974548ejb.38.2023.07.05.06.19.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 05 Jul 2023 06:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688563198; x=1691155198; 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=FSxovuSb9d76pAZNtRHp6Si7EzkK1vbEMwhu48Hxi5Q=; b=DThlPy4WXVDVxtW/w3OX7s26ifvz9HJl8lSLo8Cwj4Rdw1ZxEMxRmdZZiqJX+MCtug 4Hh4r+/ksgTtKZCIbIjdPK2ggakJnAwQxVIG0VP6T9FLSllo72XcD3NKuP5yxDGqDFf3 vDvZNafTmECcXsfVrCAUPeoS4SvpUPSbiDhWX2C9YanRmJbIMKJxT5yA84UTqTPyAxop EjJyYvdpY02o8schoFLIdBuWRZI9x4HzyNcv8+sfxQBl0zeqLpQgwbBk7y7+Bj8s+tih u5gKC9pw7TBfT1dqf6t7XFtle/wZbOlDKG1I3FE8Ek6OLqDv94o4QcR7NNy6XQ1fckfi SbVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688563198; x=1691155198; 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=FSxovuSb9d76pAZNtRHp6Si7EzkK1vbEMwhu48Hxi5Q=; b=SL+aYAOZqCPqnB/PyvQK+WCpTh+auTZKfcn9xH4iIc1oHCpcOvlKXfbCOr8igbURbI 9yrNm6kAe0zP0ehLuV73q3vuT4S5jI+SE3R/RDQ5BBmEFOy0vAJQkyPFGAeLTUP02DMo 9w8JZPX+aT1JKtStIdUSP2TgFYEJNHwEZdDqGOZBNHzFB2wJr4H0xx6+maiFlFgWQdtD KEm7BI/nsZNVa3SDZH2mCSl986ohgYmBRCPmoZ7DtRCE+tZcc4ZK9vtRq4J53KuRALTB pY7DVZyDzVNUkAB95WqfeW8gDQSP4KiV2HFbaKeCQA6+hmc814JKLvVo8G3jt4Okd2Rh qy3A== X-Gm-Message-State: ABy/qLYJTKzq/Iosdk0sq9ErNAbXzIySADz1rqJ1gfduhQq8Ud2ilkFd kyRBkp48c/rHSswLOKJEDDtXTK8+x2ucJTCaMic= X-Google-Smtp-Source: APBJJlFE+HdXFUP2NDBhLI7P8Tvw2bmVX5RLddb5H6Mf4gAnFJPYzDINKte11JfBm1S83TQE0l21yw== X-Received: by 2002:a2e:7011:0:b0:2b5:8bb9:4dd6 with SMTP id l17-20020a2e7011000000b002b58bb94dd6mr10792418ljc.12.1688563198451; Wed, 05 Jul 2023 06:19:58 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Francisco Iglesias Subject: [PATCH v2 3/3] util/fifo8: Introduce fifo8_peek_buf() Date: Wed, 5 Jul 2023 15:18:59 +0200 Message-Id: <20230705131859.53970-4-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230705131859.53970-1-philmd@linaro.org> References: <20230705131859.53970-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::229; envelope-from=philmd@linaro.org; helo=mail-lj1-x229.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1688563225262100001 To be able to peek at FIFO content without popping it, introduce the fifo8_peek_buf() method by factoring common content from fifo8_pop_buf(). Reviewed-by: Francisco Iglesias Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/fifo8.h | 27 +++++++++++++++++++++++++++ util/fifo8.c | 22 ++++++++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index d0d02bc73d..c6295c6ff0 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -93,6 +93,33 @@ uint8_t fifo8_pop(Fifo8 *fifo); */ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); =20 +/** + * fifo8_peek_buf: 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) + * + * 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 poi= nts + * 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 responsibi= lity + * to access it before doing further API calls. + * + * The function may return fewer bytes than requested when the data wraps + * around in the ring buffer; in this case only a contiguous part of the d= ata + * is returned. + * + * 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. + * + * Clients are responsible for checking the availability of requested data + * using fifo8_num_used(). + * + * Returns: A pointer to peekable data. + */ +const uint8_t *fifo8_peek_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); + /** * fifo8_reset: * @fifo: FIFO to reset diff --git a/util/fifo8.c b/util/fifo8.c index 032e985440..e12477843e 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -66,7 +66,8 @@ uint8_t fifo8_pop(Fifo8 *fifo) return ret; } =20 -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) +static const uint8_t *fifo8_peekpop_buf(Fifo8 *fifo, uint32_t max, + uint32_t *numptr, bool do_pop) { uint8_t *ret; uint32_t num; @@ -74,15 +75,28 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max,= uint32_t *numptr) assert(max > 0 && max <=3D fifo->num); num =3D MIN(fifo->capacity - fifo->head, max); ret =3D &fifo->data[fifo->head]; - fifo->head +=3D num; - fifo->head %=3D fifo->capacity; - fifo->num -=3D num; + + if (do_pop) { + fifo->head +=3D num; + fifo->head %=3D fifo->capacity; + fifo->num -=3D num; + } if (numptr) { *numptr =3D num; } return ret; } =20 +const uint8_t *fifo8_peek_buf(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) +{ + return fifo8_peekpop_buf(fifo, max, numptr, true); +} + void fifo8_reset(Fifo8 *fifo) { fifo->num =3D 0; --=20 2.38.1