Message ID | 20230612122926.107333-7-herve.codina@bootlin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2552113vqr; Mon, 12 Jun 2023 05:32:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6a3tcP/id/PB+ToKideYEt0Mg4G6jD45QsIMcWPah59EYkaYp2Y730PUCYkfwK6obP/6by X-Received: by 2002:a05:6402:2cd:b0:510:487a:ca3d with SMTP id b13-20020a05640202cd00b00510487aca3dmr4882284edx.23.1686573148220; Mon, 12 Jun 2023 05:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686573148; cv=none; d=google.com; s=arc-20160816; b=EHulzOYxdtGl1bot8nHn4FvHo4mRg54h2gVzm/Hmt9sGqWEhPft+KlOtGVbkHQ+5Qs Pdcq7LHYON7ECvSe6VJlzP3j5arPigswSgGeAUnbU0ayuaIOQJ6691f3bwYAJ7oBewVj B2+XO1L5lf4U4Axq4KTT4YmO9IVJcO0CsYCNnnEWtrmL9CwWrptlhm/EjdD9H4i96rj7 iumASk4DhDfc7PWhoGaAxibca525HLDWJIiC9/xfkWjrdWWZW0ZiwjoqcxO4gd/tOuBm g7OGqut2LBgJxBansunv1BpEF4NQohOHn3vFHx24GCQTJM702JLrQb6d/cMfi2dDj2k7 N6Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0zjmMFQWF61zw9+cDMz5UXwQs5v91FQYhgIX9kfi+g8=; b=L+3sEutKavm4YWOs1sIzlrZ02nOA23lWM0Ton7oxnXV+nYwewaPh0yGh6XqlnUWdOW fCTSQWf01vFpdxcuzOooUjztoALIk0T+qyHv4rgtk05ow5WhurwgyyK7qckKMF5bEcID 7t0VCNizkHcikt3JmCXj4i1Z6W4W2N1d3FAXOJv/mLItNNmE7JkrgTNEaPUnCBl1uzAI 4FcW1hxaOCz6nPHnK74FOp94gLBuR33Cbye8lw97oVHwJwJuE0otY/BfAlql9qk2XuzR VkBzQpCcaO4Eh8ITLLJwxgl17IJQnQE02XB2roOKGUqIKOUNpuYBVUnmZJ44UkH/78RE omkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=GPwEuaot; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020aa7de85000000b005184ac0d978si278103edv.604.2023.06.12.05.32.03; Mon, 12 Jun 2023 05:32:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=GPwEuaot; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234160AbjFLMbD (ORCPT <rfc822;rust.linux@gmail.com> + 99 others); Mon, 12 Jun 2023 08:31:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234050AbjFLMa3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 12 Jun 2023 08:30:29 -0400 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 927CC10E0; Mon, 12 Jun 2023 05:30:16 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686573014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0zjmMFQWF61zw9+cDMz5UXwQs5v91FQYhgIX9kfi+g8=; b=GPwEuaotHYy+KeLmHieSOGl4ZFBSI5jW9fbAzyelPnPJgZSUYNy2nJ9FQH481z2kbd79ev mWK4v88w1xCDOy6EglLRLeaHs00makBSqA4AJGxjD6TwPfQDBwPPuKovSv7V3mxM5r2QCp 4VJ4UhiAKmRONu8MVSCmGOtzpzNqp/GrwQrjNtfnG+qvyDEhHEeQy84ifJMS/jfoKeB2Nu nL1gGVg//0h7FtGkBRbit2gDlLHOX6XzuJD2VJwlxwdDUnQv5HshickA5soSnBtXunBI28 F9NolqiQPJl671dfvtxW3HhlH+LUGXfIaVs81/ZEVZ8FUjXXh369AS6RxJxgdw== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id F177A24000C; Mon, 12 Jun 2023 12:30:11 +0000 (UTC) From: Herve Codina <herve.codina@bootlin.com> To: Herve Codina <herve.codina@bootlin.com>, Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Jonathan Cameron <jic23@kernel.org>, Lars-Peter Clausen <lars@metafoo.de>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>, Andy Shevchenko <andy.shevchenko@gmail.com> Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy <christophe.leroy@csgroup.eu>, Thomas Petazzoni <thomas.petazzoni@bootlin.com> Subject: [PATCH v3 06/12] minmax: Introduce {min,max}_array() Date: Mon, 12 Jun 2023 14:29:20 +0200 Message-Id: <20230612122926.107333-7-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612122926.107333-1-herve.codina@bootlin.com> References: <20230612122926.107333-1-herve.codina@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768500125848482974?= X-GMAIL-MSGID: =?utf-8?q?1768500125848482974?= |
Series |
Add support for IIO devices in ASoC
|
|
Commit Message
Herve Codina
June 12, 2023, 12:29 p.m. UTC
Introduce min_array() (resp max_array()) in order to get the
minimal (resp maximum) of values present in an array.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
include/linux/minmax.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
Comments
On Mon, Jun 12, 2023 at 3:30 PM Herve Codina <herve.codina@bootlin.com> wrote: > > Introduce min_array() (resp max_array()) in order to get the > minimal (resp maximum) of values present in an array. Some comments below, after addressing them, Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> > Signed-off-by: Herve Codina <herve.codina@bootlin.com> > --- > include/linux/minmax.h | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/include/linux/minmax.h b/include/linux/minmax.h > index 396df1121bff..37a211f22404 100644 > --- a/include/linux/minmax.h > +++ b/include/linux/minmax.h > @@ -133,6 +133,32 @@ > */ > #define max_t(type, x, y) __careful_cmp((type)(x), (type)(y), >) > > +#define __minmax_array(op, array, len) ({ \ Maybe it's my MUA, maybe the code contains spaces, can you switch to TABs if it's the case? > + typeof(array) __array = (array); \ We have __must_be_array() You will need to fix the inclusions in minmax.h at the same time, it needs linux/build_bug.h (which includes compiler.h needed for __UNIQUE_ID() and for the above mentioned one). > + typeof(len) __len = (len); \ > + typeof(*__array + 0) __element = __array[--__len]; \ After above, this can be written as __array[0]. > + while (__len--) \ > + __element = op(__element, __array[__len]); \ > + __element; }) > + > +/** > + * min_array - return minimum of values present in an array > + * @array: array > + * @len: array length > + * > + * Note that @len must not be zero (empty array). > + */ > +#define min_array(array, len) __minmax_array(min, array, len) > + > +/** > + * max_array - return maximum of values present in an array > + * @array: array > + * @len: array length > + * > + * Note that @len must not be zero (empty array). > + */ > +#define max_array(array, len) __minmax_array(max, array, len) > + > /** > * clamp_t - return a value clamped to a given range using a given type > * @type: the type of variable to use
Hi Andy, On Mon, 12 Jun 2023 17:10:40 +0300 Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > On Mon, Jun 12, 2023 at 3:30 PM Herve Codina <herve.codina@bootlin.com> wrote: > > > > Introduce min_array() (resp max_array()) in order to get the > > minimal (resp maximum) of values present in an array. > > Some comments below, after addressing them, > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> > > > Signed-off-by: Herve Codina <herve.codina@bootlin.com> > > --- > > include/linux/minmax.h | 26 ++++++++++++++++++++++++++ > > 1 file changed, 26 insertions(+) > > > > diff --git a/include/linux/minmax.h b/include/linux/minmax.h > > index 396df1121bff..37a211f22404 100644 > > --- a/include/linux/minmax.h > > +++ b/include/linux/minmax.h > > @@ -133,6 +133,32 @@ > > */ > > #define max_t(type, x, y) __careful_cmp((type)(x), (type)(y), >) > > > > +#define __minmax_array(op, array, len) ({ \ > > Maybe it's my MUA, maybe the code contains spaces, can you switch to > TABs if it's the case? > > > + typeof(array) __array = (array); \ > > We have __must_be_array() Using __must_be_array() will lead to some failure. Indeed, we can have: --- 8< --- int *buff ... min = min_array(buff, nb_item); --- 8< --- In this case, __must_be_array() will report that buff is not an array. To avoid any confusion, what do you think if I renamed {min,max}_array() to {min,max}_buffer() and replace __array by __buff and use *(__buff + xxx) instead of array[xxx] in the macro. This will lead to: --- 8< --- #define __minmax_buffer(op, buff, len) ({ \ typeof(buff) __buff = (buff); \ typeof(len) __len = (len); \ typeof(*buff + 0) __element = *(__buff + --__len); \ while (__len--) \ __element = op(__element, *(__buff + __len])); \ __element; }) #define min_buffer(buffer, len) __minmax_array(min, buffer, len) #define max_buffer(buffer, len) __minmax_array(max, buffer, len) --- 8< --- Regards, Hervé > > You will need to fix the inclusions in minmax.h at the same time, it needs > linux/build_bug.h (which includes compiler.h needed for __UNIQUE_ID() > and for the above mentioned one). > > > + typeof(len) __len = (len); \ > > + typeof(*__array + 0) __element = __array[--__len]; \ > > After above, this can be written as __array[0]. > > > + while (__len--) \ > > + __element = op(__element, __array[__len]); \ > > + __element; }) > > + > > +/** > > + * min_array - return minimum of values present in an array > > + * @array: array > > + * @len: array length > > + * > > + * Note that @len must not be zero (empty array). > > + */ > > +#define min_array(array, len) __minmax_array(min, array, len) > > + > > +/** > > + * max_array - return maximum of values present in an array > > + * @array: array > > + * @len: array length > > + * > > + * Note that @len must not be zero (empty array). > > + */ > > +#define max_array(array, len) __minmax_array(max, array, len) > > + > > /** > > * clamp_t - return a value clamped to a given range using a given type > > * @type: the type of variable to use >
On Tue, Jun 13, 2023 at 11:00 AM Herve Codina <herve.codina@bootlin.com> wrote: > On Mon, 12 Jun 2023 17:10:40 +0300 > Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > > On Mon, Jun 12, 2023 at 3:30 PM Herve Codina <herve.codina@bootlin.com> wrote: > > > > > > Introduce min_array() (resp max_array()) in order to get the > > > minimal (resp maximum) of values present in an array. > > > > Some comments below, after addressing them, > > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> ... > > > + typeof(array) __array = (array); \ > > > > We have __must_be_array() > > Using __must_be_array() will lead to some failure. > Indeed, we can have: > --- 8< --- > int *buff > ... > min = min_array(buff, nb_item); > --- 8< --- > > In this case, __must_be_array() will report that buff is not an array. Oh, I missed that. > To avoid any confusion, what do you think if I renamed {min,max}_array() > to {min,max}_buffer() and replace __array by __buff and use *(__buff + xxx) > instead of array[xxx] in the macro. But functionally it's still against an array. I would stick with "array" in the name, but add a comment why __must_be_array() is not used. If we need a stricter variant, we may add a new wrapper with that check. That said, I think we can use __array[0] and similar indexed accesses. -- With Best Regards, Andy Shevchenko
On Tue, 13 Jun 2023 20:08:08 +0300 Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > On Tue, Jun 13, 2023 at 11:00 AM Herve Codina <herve.codina@bootlin.com> wrote: > > On Mon, 12 Jun 2023 17:10:40 +0300 > > Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > > > On Mon, Jun 12, 2023 at 3:30 PM Herve Codina <herve.codina@bootlin.com> wrote: > > > > > > > > Introduce min_array() (resp max_array()) in order to get the > > > > minimal (resp maximum) of values present in an array. > > > > > > Some comments below, after addressing them, > > > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> > > ... > > > > > + typeof(array) __array = (array); \ > > > > > > We have __must_be_array() > > > > Using __must_be_array() will lead to some failure. > > Indeed, we can have: > > --- 8< --- > > int *buff > > ... > > min = min_array(buff, nb_item); > > --- 8< --- > > > > In this case, __must_be_array() will report that buff is not an array. > > Oh, I missed that. > > > To avoid any confusion, what do you think if I renamed {min,max}_array() > > to {min,max}_buffer() and replace __array by __buff and use *(__buff + xxx) > > instead of array[xxx] in the macro. > > But functionally it's still against an array. > > I would stick with "array" in the name, but add a comment why > __must_be_array() is not used. If we need a stricter variant, we may > add a new wrapper with that check. That said, I think we can use > __array[0] and similar indexed accesses. > Right, I will provide an updated version on the next iteration. Thanks for your feedback. Hervé
diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 396df1121bff..37a211f22404 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -133,6 +133,32 @@ */ #define max_t(type, x, y) __careful_cmp((type)(x), (type)(y), >) +#define __minmax_array(op, array, len) ({ \ + typeof(array) __array = (array); \ + typeof(len) __len = (len); \ + typeof(*__array + 0) __element = __array[--__len]; \ + while (__len--) \ + __element = op(__element, __array[__len]); \ + __element; }) + +/** + * min_array - return minimum of values present in an array + * @array: array + * @len: array length + * + * Note that @len must not be zero (empty array). + */ +#define min_array(array, len) __minmax_array(min, array, len) + +/** + * max_array - return maximum of values present in an array + * @array: array + * @len: array length + * + * Note that @len must not be zero (empty array). + */ +#define max_array(array, len) __minmax_array(max, array, len) + /** * clamp_t - return a value clamped to a given range using a given type * @type: the type of variable to use