Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp884904rwd; Tue, 13 Jun 2023 01:30:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Ep6B5cXhA4fcNcXsiAvf6k9bh+NAWHOfijXQECVl7sYNewjS8SwuqMK2aGw7Ai57OUULC X-Received: by 2002:a17:90a:c303:b0:250:8f09:75f2 with SMTP id g3-20020a17090ac30300b002508f0975f2mr8477750pjt.22.1686645029989; Tue, 13 Jun 2023 01:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686645029; cv=none; d=google.com; s=arc-20160816; b=TMh8p1NOV0+hBb/nFTo2PKiMCi415L0NOfmM9+umqqcICudued/HbruVp9ORtv52hy U6KxMFqscRkYSp2MDl3XLrLqCKhbX/wWL7BKZs4bll6GOhQBRSmVRtz+C8irxOUwa35g NTf7uzjc68WVklYCkoPXt+1btIUoYAEqjPEAO4xmHW+FzzII8qNsy055J3KU2Kz26JI2 cb8Z4q4CS1apxTOmqRrLefXZGSAag6rramEkwJCePy0kAhcOZ3NWK8X0al181Ii93v64 wN0nn65biYrrGTWjVPKB8nEJ1JZRIUfFEjTeOXr9HHrSBo8i5+MXq0svoOIdNujJrSuT X5JQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=rd/XsfPHYPjYWaY07hPncGtbRCyEuLUp22IAn5v29r4=; b=XH+4e/mpu7DWkUTkqNtdOrLby9bjL8wl2AoIT0kvWMD0fP0a9URJLeA1eQyIq/aMFq Xo8fDQ8KRT+E3UBOL2w8ajEYhfmLZltMd4rF0dHx02shi7KJ/eOyv7Eu+MQgxrakodHU hcL7YQa3MKVDCXHtAwBd60ThAAB+nB+xbdYBi0nIlelSAd0fAJY01TFyiO6t2CIuXgMk ofLdePSvqmB79ZLe3wdG+oQhhlg0pRBqU6//r2hC3jYC4lwOvljkYfF4XcGYXaRco0Oe bEchI5i3L648dSkM1Lu58YxQ5S1fhytnXTPquVbRwmKv5/NsNrIL/5KdkWX8oKR9i27l w7WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=oGdpKjgp; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a634b15000000b005486a1e9440si7771649pga.780.2023.06.13.01.30.17; Tue, 13 Jun 2023 01:30:29 -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=oGdpKjgp; 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 S240851AbjFMIBN (ORCPT + 99 others); Tue, 13 Jun 2023 04:01:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240843AbjFMIAv (ORCPT ); Tue, 13 Jun 2023 04:00:51 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7DEA1BD0; Tue, 13 Jun 2023 01:00:09 -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=1686643208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rd/XsfPHYPjYWaY07hPncGtbRCyEuLUp22IAn5v29r4=; b=oGdpKjgpNu08N2uUAgpCGHd8N5hAGIMRJCwlpnSNDv0ljGSyOFGfEqivtG8W6LNnRYFmgB O2lz/a+CDqHon+Vx+iu2vZyhBOqJRp22Vo7sjM3NVqfFDCjriQW2M0D8tV1wP5ibo6fqmT 8MxpRpBFvoJg+Nld2DCPm/mHEdYQjwymrgoKqgMUuVLLL5/7ZDyCbjJvy/mPrJWl4Voecg 8lLV+50gZAslzG68s4CpPEnj8My0R1zOmb9IpazpXumoJbUK1pB12MDb/WZ/5tolCKiWcm FDZQ+TKiVBfDhhX6z6H6+vHZKuAx2+814/BZ63VuvsJHcUwAscSMeEfdhKfZFg== 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 ESMTPSA id A7C961C0006; Tue, 13 Jun 2023 08:00:01 +0000 (UTC) Date: Tue, 13 Jun 2023 10:00:00 +0200 From: Herve Codina To: Andy Shevchenko Cc: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: Re: [PATCH v3 06/12] minmax: Introduce {min,max}_array() Message-ID: <20230613100000.6bd9e690@bootlin.com> In-Reply-To: References: <20230612122926.107333-1-herve.codina@bootlin.com> <20230612122926.107333-7-herve.codina@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, On Mon, 12 Jun 2023 17:10:40 +0300 Andy Shevchenko wrote: > On Mon, Jun 12, 2023 at 3:30 PM Herve Codina 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 > > > Signed-off-by: Herve Codina > > --- > > 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 >