Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3571621rwd; Sat, 3 Jun 2023 07:42:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4xTnLxw1mHyAcygU5U+9SMN1Yo55pJuaMA4pveTFHskyfxH+PjZ0CORPGiALV57av+Q2eR X-Received: by 2002:a05:6a00:3996:b0:64d:40e0:5580 with SMTP id fi22-20020a056a00399600b0064d40e05580mr8505648pfb.3.1685803360780; Sat, 03 Jun 2023 07:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685803360; cv=none; d=google.com; s=arc-20160816; b=sRVpX84Vx4dLblwaZUD2nUM1KNDbW84Xi/6cnMBve46TAsz4iav4nw7Bqn/TDyZWI2 z4t2cI5hJkztf6jsP6RZrm/HLK91kxwSPDhq9QOypgZFUXl42fhK6oksIJo9KVQQR4RR cczWUTzcq3PhQn8dyb3phyjVJ70uqg9mP32dNDzqNdr/x401rcIMIIrKFiPCc/sr227i jZUgeEsdy+MjkdpMozwE0Ba+NlXH6FlfJ0yghzD5eyUWDzQKP1XVBFqJK5tMNa+YvJOl asNc81PCFbW8bnpCo9sju+eNBwQ8zdEIkU6orIp+tq7wnKU+T52ioxchPtC2W80z8cyr YOgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from; bh=rPIRna0diklBhJ1Z3YyirUUg2CUSl9f1b22V7oih/is=; b=aMb17cdaDlSACa5tfRpcOqm7zG2gVaTQhFzaaNgyX3ulerf9Op7a9/D+ag9iFKNhPY RuP2WLlIX35qifmMp3OtlEpVzeHzTsFhfdzytGqxKXkk5XYXInnVF8Fk1euEjRPNNTFW r7FF2xTZthTx2t1UKT+IZi5O4LKTBBRo2XC/La6Do/npsesd5wlsa6DDj2sjGwjpDs0n +m25u/WRgoWOsV05G5qdjYwFP3odWpehbhP+usROglZMveTCNGA3IYcbWPRGnkIapHrx VQmOdD5to1o5Uhz5ZOJ3WoeKQ1yg7FhUN0Xrbk7kddcZd2UZGoD2oyXC3zgMhhlds175 bLxg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s129-20020a625e87000000b0064d6a514682si2511929pfb.366.2023.06.03.07.42.29; Sat, 03 Jun 2023 07:42:40 -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; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230024AbjFCOEo (ORCPT + 99 others); Sat, 3 Jun 2023 10:04:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbjFCOEm (ORCPT ); Sat, 3 Jun 2023 10:04:42 -0400 Received: from fgw22-7.mail.saunalahti.fi (fgw22-7.mail.saunalahti.fi [62.142.5.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B90619A for ; Sat, 3 Jun 2023 07:04:40 -0700 (PDT) Received: from localhost (88-113-26-95.elisa-laajakaista.fi [88.113.26.95]) by fgw22.mail.saunalahti.fi (Halon) with ESMTP id 93641df7-0217-11ee-a9de-005056bdf889; Sat, 03 Jun 2023 17:04:38 +0300 (EEST) From: andy.shevchenko@gmail.com Date: Sat, 3 Jun 2023 17:04:37 +0300 To: Herve Codina 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 v2 5/9] iio: inkern: Add a helper to query an available minimum raw value Message-ID: References: <20230523151223.109551-1-herve.codina@bootlin.com> <20230523151223.109551-6-herve.codina@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230523151223.109551-6-herve.codina@bootlin.com> X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no 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 Tue, May 23, 2023 at 05:12:19PM +0200, Herve Codina kirjoitti: > A helper, iio_read_max_channel_raw() exists to read the available > maximum raw value of a channel but nothing similar exists to read the > available minimum raw value. > > This new helper, iio_read_min_channel_raw(), fills the hole and can be > used for reading the available minimum raw value of a channel. > It is fully based on the existing iio_read_max_channel_raw(). ... > +static int iio_channel_read_min(struct iio_channel *chan, > + int *val, int *val2, int *type, > + enum iio_chan_info_enum info) > +{ > + int unused; > + const int *vals; > + int length; > + int ret; > + if (!val2) > + val2 = &unused; It's a single place, where this is used, can you move it there? > + ret = iio_channel_read_avail(chan, &vals, type, &length, info); > + if (ret < 0) > + return ret; > + > + switch (ret) { > + case IIO_AVAIL_RANGE: > + switch (*type) { > + case IIO_VAL_INT: > + *val = vals[0]; > + break; > + default: > + *val = vals[0]; > + *val2 = vals[1]; > + } > + return 0; > + > + case IIO_AVAIL_LIST: > + if (length <= 0) > + return -EINVAL; > + switch (*type) { > + case IIO_VAL_INT: > + *val = vals[--length]; > + while (length) { while (length--) { will do the job and at the same time... > + if (vals[--length] < *val) > + *val = vals[length]; ...this construction becomes less confusing (easier to parse). > + } > + break; > + default: > + /* FIXME: learn about min for other iio values */ I believe in a final version this comment won't be here. > + return -EINVAL; > + } > + return 0; > + > + default: > + return -EINVAL; > + } > +} -- With Best Regards, Andy Shevchenko