Received: by 2002:a05:7208:3188:b0:7e:5202:c8b4 with SMTP id r8csp790188rbd; Fri, 23 Feb 2024 03:52:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXrTzfE1m1l7WOCXkaHtMmR3SF2wGi+te+K4omHwQB0xceLBXsWrlD+jOb1y9na072c1V9ed6wv3bNP3wQFGfFo7m5Tragu8KCEze+CJw== X-Google-Smtp-Source: AGHT+IE5NEiFm+sdXn3AcOy+XaiilFGyxfaChhxbecxDQYO/VYijuhfYjh66M3vV36BKXMEkqSA4 X-Received: by 2002:a05:620a:4443:b0:787:b85b:633 with SMTP id w3-20020a05620a444300b00787b85b0633mr773783qkp.18.1708689149578; Fri, 23 Feb 2024 03:52:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708689149; cv=pass; d=google.com; s=arc-20160816; b=qvRsm4kyj+AjAaxPSgyaIkTcf6XaGiS49AT+JqEENUG8/EXoiQGh9xb/MoKt+fEANg EcMdLZwCud55Snhn8x78Ps3bk8vYR5YU3ZNtJCDN3+pR4bzOTVq+w8853w3M38UVOGTc AwFZPxmuK3uwbP8AyhNQk2HBXWytdFM6jqwtz3wV6787oPesnZJnQBWm5A9CJ72M2F54 EAbEcRe5goZvvOHqOY8bEAG8EjPE3efqt6tRZpSvFFxJPVpBXftf6IIwhBMT4Ce1YZdZ CKDhXu2YXmIouAwOINmFvO2mHd+m7HYzNCoaPP0ts08xtp6vWQxVCwncAHkyTWMnpmyz 9f1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=OR/JvbZzT8viWh8xtWLE681BFdi6NYdpUdsvSSfKAUE=; fh=SkIaIH+DiL3te+x2Ka3BGj5xTg3fkbzpLQclWIFEB/Q=; b=BjGBZWa2WmAjShOE0V9pmyXxMwixVeLTjshiWElf+HMHCVdxbx5bP3E8RsfK22X1pr 07DimFnMoNo9IQirw6midwPb0IK6jQXcKAqXDqWDcZUOTcBJvKnZjU77/GGw2zJmIZjP 9lFp466AY3eo/sYf3cbL1wi421sP/Q/oES1BJSyIocZBxv2ViBEkTJD/m5OXrQAoMKKM JOCpdDuHbWWu34Rkr9MfE1r/6x02pxG2qt/WTvRgYNQi9IPH/uIspofJuT+qm0DKJy4B kKdEuPp/8OeU7s/vBO+vpuHDKxfcv8BiaWSjN3vYQPI/h45QU4lkTpgcggORkUR+aY0M VCHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jgjtbGYD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-78254-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78254-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h9-20020ac846c9000000b0042e4ad98c37si3217532qto.513.2024.02.23.03.52.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 03:52:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78254-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jgjtbGYD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-78254-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78254-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 070FB1C23250 for ; Fri, 23 Feb 2024 11:52:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D86B87C099; Fri, 23 Feb 2024 11:52:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jgjtbGYD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EFCC7BAEF for ; Fri, 23 Feb 2024 11:52:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708689122; cv=none; b=bTmHAmUARrJGY6vuqm9ZtZYOcAtS6m72pRKKDtemytVEaD4AeFSCnpvSZRSnU4gynOK2N0S8gukjdgkWvkZeQs2iteOeEbw8+o0O6qAXS/5CGSF7Y3hVDitBZX8IZBPN0B+byCoRW7kgyepxlLJS8z3X4puGNdt5+/SvceBqygs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708689122; c=relaxed/simple; bh=FNEmQ819X+4jzsi2LEQDgwiIxK1a6W9fcLNJsEFzcXo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GDMC0MfleAAtUXxcy8Xj0N9ACLW23QLtSfH1YP079naHHyXuteXwNqZiceN2qGFc7rcRFRLNGWoNDUvOitiLV38IfHb9IAb+ljoMwg05MdTTVcnul69BBXm+8OBcDsds8xy3aOG3rv1D1Ne7Mw7ZTD/4SUEcZjq6VqMkQ6Qta/s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jgjtbGYD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87D13C43390; Fri, 23 Feb 2024 11:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708689121; bh=FNEmQ819X+4jzsi2LEQDgwiIxK1a6W9fcLNJsEFzcXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jgjtbGYD7QTuXEz/tAsXFo0qynF8zdVuzsGr6cjWw9N1j+03d4f9L1AMdlb3rHNNw xVbSrZheauh+O0tka2zI2kgH66iabZOLWU0S61NcSFzbStTn0hAsEz3EgzoyRfuq0H 0Ii400wqnFm2owHwuxwKMLFKXVzr/mXsC8AsGb7m4htqpex+E2w5TuN2DEJ99SZcfi hit+GaowoEvv4mEoZbuwXm2I7IPC4XzJtF/G+YR6wFMCUF9Ev8oqR6N/tzxokDY13g jt7DZBJFGRdx0heCzq0tMr75+yXQVNRpGXxwwEXev/lv7GC2lES/PTusdqGms2MFPK l/jj7/KYLkUkg== From: "Jiri Slaby (SUSE)" To: stefani@seibold.net Cc: linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Andrew Morton Subject: [PATCH 2/4] kfifo: introduce and use kfifo_skip_count() Date: Fri, 23 Feb 2024 12:51:53 +0100 Message-ID: <20240223115155.8806-3-jirislaby@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240223115155.8806-1-jirislaby@kernel.org> References: <20240223115155.8806-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit kfifo_skip_count() is an extended version of kfifo_skip(), accepting also count. This will be useful in the serial code later. Now, it can be used to implement both kfifo_skip() and kfifo_dma_out_finish(). In the latter, 'len' only needs to be divided by 'type' size (as it was until now). And stop using statement expressions when the return value is cast to 'void'. Use classic 'do {} while (0)' instead. Note: perhaps we should skip 'count' records for the 'recsize' case, but the original (kfifo_dma_out_finish()) used to skip only one record. So this is kept unchanged and 'count' is still ignored in the recsize case. Signed-off-by: Jiri Slaby (SUSE) Cc: Stefani Seibold Cc: Andrew Morton Signed-off-by: Jiri Slaby (SUSE) --- include/linux/kfifo.h | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h index bc7a1f5bb0ce..9e64eb03c535 100644 --- a/include/linux/kfifo.h +++ b/include/linux/kfifo.h @@ -304,19 +304,25 @@ __kfifo_uint_must_check_helper( \ ) /** - * kfifo_skip - skip output data + * kfifo_skip_count - skip output data * @fifo: address of the fifo to be used + * @count: count of data to skip */ -#define kfifo_skip(fifo) \ -(void)({ \ +#define kfifo_skip_count(fifo, count) do { \ typeof((fifo) + 1) __tmp = (fifo); \ const size_t __recsize = sizeof(*__tmp->rectype); \ struct __kfifo *__kfifo = &__tmp->kfifo; \ if (__recsize) \ __kfifo_skip_r(__kfifo, __recsize); \ else \ - __kfifo->out++; \ -}) + __kfifo->out += (count); \ +} while(0) + +/** + * kfifo_skip - skip output data + * @fifo: address of the fifo to be used + */ +#define kfifo_skip(fifo) kfifo_skip_count(fifo, 1) /** * kfifo_peek_len - gets the size of the next fifo record @@ -790,17 +796,10 @@ __kfifo_int_must_check_helper( \ * Note that with only one concurrent reader and one concurrent * writer, you don't need extra locking to use these macros. */ -#define kfifo_dma_out_finish(fifo, len) \ -(void)({ \ +#define kfifo_dma_out_finish(fifo, len) do { \ typeof((fifo) + 1) __tmp = (fifo); \ - unsigned int __len = (len); \ - const size_t __recsize = sizeof(*__tmp->rectype); \ - struct __kfifo *__kfifo = &__tmp->kfifo; \ - if (__recsize) \ - __kfifo_skip_r(__kfifo, __recsize); \ - else \ - __kfifo->out += __len / sizeof(*__tmp->type); \ -}) + kfifo_skip_count(__tmp, (len) / sizeof(*__tmp->type)); \ +} while (0) /** * kfifo_out_peek - gets some data from the fifo -- 2.43.2