From patchwork Fri Oct 13 14:11:22 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: 733224 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp1489420wrv; Fri, 13 Oct 2023 07:12:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgNLjDtgJwJBiU15r2nZGzHrICmJ9stcf2q1qkcEU/eOzQDceUg6VFgQX9nDR32qzdJGuW X-Received: by 2002:a1f:df43:0:b0:48f:f026:27de with SMTP id w64-20020a1fdf43000000b0048ff02627demr17709012vkg.15.1697206371016; Fri, 13 Oct 2023 07:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697206370; cv=none; d=google.com; s=arc-20160816; b=oYIP5MsTA5NL0qLkS8PJ4s18zfxGyrZ7Lr0NusCtjaaZ6kk13uJGiOmVp4JRW6Dofb IHo6poeC/LeU6o/q/3bwk30PiA26bhlfEpT10bu2kHtDXilfsA9TFoA+D4cOKNRgVo8f 3r2YxDddlJxU0dZJdYhwgD+5HdInQnv+tkOY6pUGtaCo8fZzL2fEX8P9s8Ac3kiNkoAZ J23P6dBkUWrncvcJ3nSIS5Irc8sLJgO5H/ZLUs29l+tJ/rkkBvA0gFu3KIsdyZUOr4rO A3FJe4Gl3Wxhtv0SSsEaVu3L4+NYjLvDFCZyKXDhQBPamEu3qtBks28O7Tbdkwh4lTRA COiA== 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=iNlBFRzKWcUVyIm7M2O0DMt8HyVCk33Ec3Usyd6Qlks=; b=eOs4VMO+pvxh5yk8Gy+jRffALcfHyFuXGKY7xMnfTroNT/+6aGKuXdyaVCxQWPxP2F X/Hm+5+6N63DLlXK4Sc22k7ZTG8B3/0eiFYoB9FdTzVbnR1cumH0sjVxz8RpMDnM1orb gB+KoGLhQ26cQ1vdTbTXJD9IfqUlZRJmBdb/9fEHjwSUASRN47CuaBgnCTWvpkUr7t1H 2TrCPDyRKVclAAASiYkaICfavjgzC2t99x68nGCuhubOp11F2IZTdt3gxeB1+m0HJ+ww y0BMiMZANPdROHke4nhJkDXM57F7UFx4SQjIqt7NFl0lkWl2FbXgHTSgt1+Un60vzQGC NXyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WWWC8OQf; 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 i15-20020ab0374f000000b0079d9dd2bf90si173786uat.72.2023.10.13.07.12.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Oct 2023 07:12:50 -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=WWWC8OQf; 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 1qrItK-0007Q4-US; Fri, 13 Oct 2023 10:11:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qrItH-00077g-LK for qemu-devel@nongnu.org; Fri, 13 Oct 2023 10:11:49 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qrItF-0004NF-FF for qemu-devel@nongnu.org; Fri, 13 Oct 2023 10:11:46 -0400 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-9b64b98656bso343934766b.0 for ; Fri, 13 Oct 2023 07:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697206302; x=1697811102; 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=WWWC8OQf1JeXx0TgWjohAatB7GEaI6k8JO7QzQLRoLma5lgwQhNxDBRRKNEH083XAG /YwCaCoQMmtQct7kwx1eRgJzjbBOutA0QPWEZSlzkXCXynyHUovMrEGldOXblEN3O2Jq HikSgOUaHnsHO5jav8Ey4QDtwz2hUaco3jmJzN1LQJlsyp4ySjy+d/B+E5IC3rlbwN0w mzEPyDk0e/o3MMobmtcB2sRAvNIBY++fGhV+0l3UM1BYAHc9oLK/QGspGffmsTISU1ek I82PB87uETiJzdP6rF+kq+IgSJeHfAmF66aXVVvuWZuE4vmLFfhdessL4P3zsDoBn77B ddrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697206302; x=1697811102; 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=jh/ig+NNom/h/+wEzL3zN60Yb3euFVQHgbW6Tg6X6u9CsGCqpo1CM9KYHijRt7CehF KxNhAcgzS4oupGXmJe+EBew+Nny5Mx23oEVQWs3mRqNM/dF0uBK3SWTs6caGt+SBCbEM ki61rWO5NGCUOeAINuOcp5RBZtC7C173q6xJs4e5dRMJLhMXdTRnBqYOjDUrreZSsKPL irVQ18fftmz3ohNEe7e3Gr+7SRnlMprBXrCZbbPXkAOZOaReYptSVX3ZUOLygzQGrMyx n40/iZJQfxarjcz7fvptAYlRsgdp8KvjSLsCaPQOf9Iq4r7Qqfd/IkLT9g7+2GwrowLZ XByg== X-Gm-Message-State: AOJu0YzxsLbZfL8TtAzdIj6EGnwEG8UopDSitA4kzCxDui2We/NK++wI qjqSm9K6dKRPYaAUY6PZP1nARVMM/pwgafOUDnc= X-Received: by 2002:a17:906:13:b0:9ae:1de:f4fb with SMTP id 19-20020a170906001300b009ae01def4fbmr22360044eja.46.1697206301756; Fri, 13 Oct 2023 07:11:41 -0700 (PDT) Received: from m1x-phil.lan ([176.172.118.168]) by smtp.gmail.com with ESMTPSA id 17-20020a170906059100b00992f2befcbcsm12380964ejn.180.2023.10.13.07.11.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 13 Oct 2023 07:11:41 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Gavin Shan , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Francisco Iglesias Subject: [PATCH v3 1/10] util/fifo8: Allow fifo8_pop_buf() to not populate popped length Date: Fri, 13 Oct 2023 16:11:22 +0200 Message-ID: <20231013141131.1531-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013141131.1531-1-philmd@linaro.org> References: <20231013141131.1531-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=philmd@linaro.org; helo=mail-ej1-x632.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+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; }