From patchwork Thu Nov 9 19:28:05 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: 742600 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1017998wrw; Thu, 9 Nov 2023 11:29:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYYC/kfh2xtRAZU8iGdPyx0vNQJnP6161HXldG5WPUZp8mc8zCLbIGF8nVQE6MY1C5e913 X-Received: by 2002:ad4:5cee:0:b0:66d:253c:9a80 with SMTP id iv14-20020ad45cee000000b0066d253c9a80mr7144072qvb.54.1699558195677; Thu, 09 Nov 2023 11:29:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558195; cv=none; d=google.com; s=arc-20160816; b=nP3SWTLMXsgMibHD3RA0RmK/0eHeOyXx7s9oS7GM0m5+ekhHVGBF1dt5kvMq0PvyDB sxtIoM0mHQgDlpXQxZwu1lCC8n8XKagEbKQ7tufHTBwN0CdvkMnteRhJl1d4nrAjvUi3 RI0iBHoCouzNqil/nypo0dS+0Ii7fLy5bq2XQMNc7T2sTVsK4S5TLTKOD2qBSyngfxfp khmLUnAdanFAaPAenOhQFnVZzFAfkbua6Fsy6pyq5UvBxpfGvrV1GqbK2OWrgEWtYt/2 yav9i0map4bEDemK3UkvTKkIszj9G8r0vg4n0LcbynE6TQUa05D7kFnwSHan9FISAHd2 C6yA== 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=tAZvf0/lxzzRafQirPbdSKogeoxVhHxgjxTZIWfzoxQ=; fh=GQxR5x0bbpeaxpQRj0Ss2iF9lxOTaG+uCQYEI2XZ3x0=; b=dtTCH3jxzi2t2a8+EgZhYtalB5a2NQY82oex6OsDJNx2/bbJs7ug43F7MmJpZz4imq l1sM+Lah+6jGq172rkElSX4Feg0h07i24cypA05ZXN4B4xp6OWEa3skQ6B9zN2pwohPi jnSk2U26e1ik7xwQBxQfMvDDa3AvIX/SwT1sWKEzmqZMd62OkLsrfB/FXZCze6QarfFo Sm/TdKaLUN1cS19JEByNXY7HILLCoMLR1J17f9LUMy2wcf0zaaf7meINtNr7+1m1Qc00 jp3t9zq+VpXPT7m5Hv/GIDbrCrM9AhGLlCLCNkaoB8Q4AbVEvbq2y8uWFwkNqy/QCtOA 00jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NqaF7rDg; 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 b9-20020a0cfb49000000b0065b081ea06bsi3254395qvq.22.2023.11.09.11.29.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:29:55 -0800 (PST) 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=NqaF7rDg; 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 1r1AhY-000515-5q; Thu, 09 Nov 2023 14:28:28 -0500 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 1r1AhW-0004uf-L1 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:26 -0500 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1AhU-0005G0-W3 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:26 -0500 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5440f25dcc7so2027472a12.0 for ; Thu, 09 Nov 2023 11:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558103; x=1700162903; 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=tAZvf0/lxzzRafQirPbdSKogeoxVhHxgjxTZIWfzoxQ=; b=NqaF7rDg+cNy598mq7WXsKuET9YrMQV/LJ+ncqMhJIQKLSGfQzymsTq6CqTB4SX5bb CmmVJzVDaU4PP3Tmi8Qwq/HzoLLLxk5pomwuswp5KFanblWn6M2F/6rrAh00MzcwKvGj I6DQU4lti/xy7ZGYLoWxT30dx+2a7PmIqLdphYaNut2XAJFNqGikyMoxbKAmvj7MS4az tVSBX+IcUMQffeqF6pBXOACheGA5dY/2XJAoHiegylbyFdufs76UT9kO1yQCPBYjFFwx yMCct2a2xvaadTvFzFOncHlMys5MzmBFvJn8pvA38CHtjYvGIIDxmtKjdmXeeaLcxNAP 8eLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558103; x=1700162903; 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=tAZvf0/lxzzRafQirPbdSKogeoxVhHxgjxTZIWfzoxQ=; b=BblOfxbZr9cyPnFaZfUszuczkLf/ZFNQXPscuNyPJ8jkDwD9VbEJR+yo2i1ZNm6Jri Bw3oJjQlIEy3dqNUamjjr0iel7Y9q1dYNaoefeCYhvVm3XR4u2/ELqLv2yrdjH+2z56I XOZ9lw7NBKnRJRuc4EBqM+AwlJOYFu/IpUt7Kv41dL5IYrvSuS6DNOSuIR85bXBwYWBX zOmNU70kZJbo9iGUqIIb41sxkB25KFNePaS0yRVTycOTuOOIdGOKBzVcxvTjnVe9a8qc 2oGT6efpP8Ns28MT542AY7dXBo9uUQR3Vk6OKSHf4kIy7ySVk9MpPYfUpo2LaD7Z4RMh H7Fg== X-Gm-Message-State: AOJu0YwpA+xLs5656TCrwVOqr0YzekgNZkzZtmzpToMNEGYoFearlF1j eyI06pg7OVoAoKj8YrapUF5+sXq/ZdFr1Us31kXssQ== X-Received: by 2002:a50:8d0b:0:b0:53e:37d1:a31f with SMTP id s11-20020a508d0b000000b0053e37d1a31fmr5226900eds.28.1699558103375; Thu, 09 Nov 2023 11:28:23 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id z3-20020a5096c3000000b00544f8271b5fsm189937eda.8.2023.11.09.11.28.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:23 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Francisco Iglesias Subject: [PATCH-for-8.2 v4 01/10] util/fifo8: Allow fifo8_pop_buf() to not populate popped length Date: Thu, 9 Nov 2023 20:28:05 +0100 Message-ID: <20231109192814.95977-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=philmd@linaro.org; helo=mail-ed1-x52f.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=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+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 Reviewed-by: Richard Henderson --- 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; }