From patchwork Wed Jul 5 13:18:57 2023 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: 699233 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp2774811wrs; Wed, 5 Jul 2023 06:20:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlGVUFB4Or2xk2tCKx1h+acTmyA7uO07/OlAVLeemmciKLXJDjARPchyESN6cd/PH7N1Q9cX X-Received: by 2002:a05:6214:da4:b0:636:10e2:22a7 with SMTP id h4-20020a0562140da400b0063610e222a7mr21767015qvh.25.1688563201599; Wed, 05 Jul 2023 06:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688563201; cv=none; d=google.com; s=arc-20160816; b=y5/UkoIfVPJ2AU+1yDMUTQ+68mZ4mvurL2pWTzpCfXFjUoGaqzxUTx62Df02vimtmd 4+WeFyqDatZ4BF5EcDjviiC9OhY3tr8mFLMws/TmmT2gfQI1jlBnsFGbKjs58u4KKAyQ SJfLsJYw3ccX6wQ29v7vsXmpP+eYdBHY1peUcrAexDwhI1OyIDaYKYmhpkllassenfSP rsKFaPOkBbuJFPanBe56sIUpHtKtCLUjhg3LvpKcbssR7J8VURTKe80TdfEFNF3tvSDF 5fKXu7cSpPC06igC8oXENO76MEXkX/hS4rTvxr4l5UgpCzFG2ODxt/7t40mwdbrH5mRZ yixg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=igb0JyNsA2PhSTz0dTyRLO9tMn947tv2lHWj3R8IWaI=; fh=jFETSPWxjbFheN0Kzyv9hCW9dGAwQxtwxywFZ1hQu6c=; b=fzjkLujTWsWHtuvbYkpqMox2g2wunQkrVRLhZYp0tN4If5B2jPZfK2+ftPX9IusJUV TD7V2UuhLVRO0ARnD0t0sth2nU6ybg+SziJpLokH4ZYcMFColSqzmlt+i3h4jgpI7yQi Hi+8jxNrO7RCtFTxy2sjhlNFERR/oUhZTLHriKT/TBHWYny3Ln5SjA5O3YfNOHFz2vA7 aUKv2za4sdCpp+RXtgg0m8L5qDan+p5y9KXIvqga83INRbUuvWBGU+Qg0tlnSDuN7Y6h wTsAd8RH0jO26rphWDzom6TpNt2ATbPYsPRHknxkfaI0VmHec/gIIjp5EECwoznXqtIO 8kIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bybfZR6Z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c6-20020a0ceb46000000b005ef8094003dsi10088290qvq.17.2023.07.05.06.20.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jul 2023 06:20:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bybfZR6Z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Francisco Iglesias , =?utf-8?q?Alex_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Francisco Iglesias Reviewed-by: Alex Bennée --- 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 full. * Clients are responsible for checking the space left in the FIFO using From patchwork Wed Jul 5 13:18:58 2023 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: 699234 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp2774868wrs; Wed, 5 Jul 2023 06:20:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlGy4I5OH1sr/mX06JxE8PDk4X6zWBEH/mjJMl0tzqHQ+7w7dY0vLlVbuQ5PXpvC+kTE0BG5 X-Received: by 2002:a05:6359:63a9:b0:134:d336:a1e7 with SMTP id sg41-20020a05635963a900b00134d336a1e7mr11382985rwb.4.1688563206503; Wed, 05 Jul 2023 06:20:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688563206; cv=none; d=google.com; s=arc-20160816; b=ZIK1TSwY8ygdM7C5boSgvQZ71pfiRkwgasF21anqAjbHsuc199n7EHBR7kaR3LnM1R tIAQGboPY9MprIe/QlsvQuTrEuzDfy4K3O6VU4I9wMvyAdgY0F7/kCHoMOgScnP1r/1V hBJ2Aq2FyLR4TvCW/PHglpJCBf3YJh4cmwjiHZ7WtAAd2F6homSfcF9EgYv9kVAC2xTg A7aWKUReU51qP7p5OyuL6vFaxTJxgC/PFenUQMmzWaab9ZkuZoKddx83o2/NnfnYa7kF I+D0YoUNkf+vwe8JVXW97R7gRVkH5DSNfW9mKfL1NSG7GS6wk3ZC9SSXCMOw6wLkkY2i 9GEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z9kg0aNLZM4S8bjUKxesX7u6cAm6btVjZ5SYrsKBPTY=; fh=jFETSPWxjbFheN0Kzyv9hCW9dGAwQxtwxywFZ1hQu6c=; b=aUUkvjIGLMOBAe+9cuNmD1eWUy6Md00tI/zSx63LEGTwC1mhL2q/QtrsPh14Monwl5 fTQuTEgVUbx28zhj/CcrbMHIAST7wZo1+uDj9gsvFf+tLgWtzNE1FDKrVbyXEE+qImha 4GdRc0kYQd0ALk/yoDkcso52N6F70o4rjY9fPKILwM8hL2KV5ShWF6WcApx/8EwcXF5H VrJp4VFWVXfsyD+1bl1ZkwEKUa4DRYiXi/2VCJtbi5vJB3HNHj2mkojLyPtFW5sveN2f hHzHr8QkuELA82PaRpTA1DZ1XXHC102VFuNeKkPuxJsTQFL/b5yPHsudQmqDifoMA2qb lljQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=up+tjzeY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id gv11-20020a056214262b00b006359bbae0d8si14965355qvb.596.2023.07.05.06.20.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jul 2023 06:20:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=up+tjzeY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Francisco Iglesias , =?utf-8?q?Alex_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é Reviewed-by: Francisco Iglesias Reviewed-by: Alex Bennée --- 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 buffer * 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 data * is returned. * - * The number of valid bytes returned is populated in *num; will always return - * 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); /** * 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; } -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; assert(max > 0 && max <= fifo->num); - *num = MIN(fifo->capacity - fifo->head, max); + num = MIN(fifo->capacity - fifo->head, max); ret = &fifo->data[fifo->head]; - fifo->head += *num; + fifo->head += num; fifo->head %= fifo->capacity; - fifo->num -= *num; + fifo->num -= num; + if (numptr) { + *numptr = num; + } return ret; } From patchwork Wed Jul 5 13:18:59 2023 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: 699235 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp2775039wrs; Wed, 5 Jul 2023 06:20:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5hijFHvQOZZS1mfcwjKMxwbAJIMTwN/+MZoD8Z+6FE/qYz5VTNiCWxc2CoO/rw/RuOCuck X-Received: by 2002:a05:622a:12:b0:3f8:58d:713 with SMTP id x18-20020a05622a001200b003f8058d0713mr20492498qtw.55.1688563224371; Wed, 05 Jul 2023 06:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688563224; cv=none; d=google.com; s=arc-20160816; b=ZbQ8++rULw4mx4hoo5alptFJTnk80/agYEn84OWSxDbvbIrfbaH3NTNxOw5r23L+qk JSaCZV3khZJ7PFFwNHtxNnecKNfRo0Q0xhiYQ98tJMJL37xJ2bhh4umMGYUK9dc3JUYN Y3giBOgsj+MV6JBBSSVSNTTj0EqNHgM0MDdx1EOFs6SHyF52YuXPoQarqU5DD0tM9bQs VFJnbGYw0NVSilF/F/5mKPGjoqQY5vS26QADIceUFCpAMCTD62FoL7jh1YpS0JBhsXxo iIDC6O7qO505QBr6vArbPCbiyEhsQPgNo7RR9F1rLDTkmbcpD7NrnZQkcTsryR8umBck S+0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FSxovuSb9d76pAZNtRHp6Si7EzkK1vbEMwhu48Hxi5Q=; fh=HjN6hDUdvUWJPrKQzupoRHC6xM5OGqZSX7+zl32Sito=; b=I5fgv3LLEfHnnVnBKJPXNcKKJfLxjgpIiHeB7aX3PMyzTd9UCue8JtILoBmM7+iUdO r1paErswoajAi4xmfD7ThemVQ2qkx41FST4TsNSAjRiXBaIUy5pF4m7cOEhsIxy1Wn5g 6Tx6QiXacYeyY68mcf20FINPPNyzMdb8ruMoZOZt/FV7pvwx3pdxqKEeipi4g4V1TJbA Ta3RKUK+7zCh7E9rUgPSwanKDZPC4Xh1n4OnNRBDuYYtrr+ATP4mOi1Avvrst5srze9J lWQazOnCeHdWrjTNY0dhyFRxD7foxLm7S3BtzhRm5RHr9nTZK4PG33MhnJZ+zJd1BSV4 taHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DThlPy4W; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y4-20020a05622a004400b003e4ecec2cb5si13445252qtw.137.2023.07.05.06.20.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jul 2023 06:20:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DThlPy4W; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é --- 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); +/** + * 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 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 + * 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 data + * 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; } -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 <= fifo->num); num = MIN(fifo->capacity - fifo->head, max); ret = &fifo->data[fifo->head]; - fifo->head += num; - fifo->head %= fifo->capacity; - fifo->num -= num; + + if (do_pop) { + fifo->head += num; + fifo->head %= fifo->capacity; + fifo->num -= num; + } if (numptr) { *numptr = num; } return ret; } +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 = 0;