From nobody Tue Feb 10 19:23:14 2026 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=1697206371; cv=none; d=zohomail.com; s=zohoarc; b=DYvUlyS4TwRYxfiTiuLkLtNq8GejuLqXgw6I82dInfdnWFb4lUnrVX3gy3Ro5vEZMow7K+cTEEPUJ2RB4J+SKsHbrUvYqFfkNREJOy3gGBRgbv3OQUtFzdf+rQFJ6aOUphtkkhnrM88Tn7oxgKPgIXq0PImNkC/19NOdz8KRXJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697206371; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tAZvf0/lxzzRafQirPbdSKogeoxVhHxgjxTZIWfzoxQ=; b=Lv6/7INvM6QBWhq4QRyVHT9O+fn6i+e6S20cWkVNYQFhuFCnSzLqGLGnTgedIkPGIgi/WRU19nGsFJunyG8RvUsR9YB+t90LcnZoV6TZA925NqY65ST/AEEBXL4GgZg24ZNjMbEPFhbftqo6POC7/TfyIASJV63tYGnJpnalJC4= 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 1697206371172946.4119208705093; Fri, 13 Oct 2023 07:12:51 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IFJJDm1ZNMb+AWEheX7wAt+AK5/jc+bjMFaO3F+B93zZuWHRb0ctollx7sOKyh2zrSr2fEpWQ== 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Evgeny Iakovlev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gavin Shan , =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-arm@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=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 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::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697206372071100009 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.41.0