Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1861414rwd; Sun, 28 May 2023 04:01:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7t7O0ayg0ZVEN1jtdezQHCxKOK3pMIC/eYfFw4s6+atl79ERj29gSn4BR/SrPwAktyv+xi X-Received: by 2002:a17:902:f543:b0:1a6:45e5:a26a with SMTP id h3-20020a170902f54300b001a645e5a26amr10857570plf.27.1685271660293; Sun, 28 May 2023 04:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685271660; cv=none; d=google.com; s=arc-20160816; b=VYzWTY/h5LnYeIVDTNw1DzXHKjaoB7rab8rOY7t4Nbyzd1oURbwSvImV/2ZeE0+exS J6Dt+EJoMTJMRzekUpsFZN01EEaAewKRaoPUPAae6P+IZHv4wypySI2yGIjsG4EFmGpS zdFGzdFgAG8P6taBAJhZR1OtPFPcl+0RXLJCOGlyXWw3sNM3Nyjr9Yx8oSRpq2nyvnFa wMU0DFmvqAehbyThXhRNBZUnEVMhWRlYDthMZ+XyEgdFGEYmgt/ghkd0hC4aVJulmMKs Nzd19XO2yKkIxrhpLDY++r35eH0ICK2l29hs00uoIKWxjL8UZ5HsBaLuAGbG/ARbRYEG gPMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=VPf69s/gk1XGMQ8CNT837DomPnowiM8WtUn92nCG45U=; b=gcnqsx9PnN8NPFBdQzMqTDXVl8PxFVN85/KBd+32TIxxHyDuSfh8KzwBgxh68N0x6K FnUlUMydlYYH2dzyMRNOuKLwdDKUBQlv+hO59X2OuxQMOdUg5xab18SWAWk2ppjxR+hM +8jOJOSCVC7TVGToIleOFxzWOHZ06c0av/MgXBU4xM18SEkfsvvYzSp72wfe1syuU+xG W1h4bs9/7Ns6AJyUGqZS8TKK6cDOrBms5KvHVVy9hhg6/gaTwZdK19Zo3M4mfgkZhPCW jVfNFjrWODsJDONLDTiqgn8MZ+wcKrtv/xb72LmE5nwJLAonzN65FCxnh1dAQ8u2KuVF gV4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=irmPCYc5; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y8-20020a1709027c8800b001b042d1eccfsi24702pll.530.2023.05.28.04.00.47; Sun, 28 May 2023 04:01:00 -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=@intel.com header.s=Intel header.b=irmPCYc5; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229492AbjE1Kqp (ORCPT + 99 others); Sun, 28 May 2023 06:46:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjE1Kqn (ORCPT ); Sun, 28 May 2023 06:46:43 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D446A94; Sun, 28 May 2023 03:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685270802; x=1716806802; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=12XnZdCMLf2ECdKc7jgZMRFCTIoyk3JXcdiX3xQZb+Q=; b=irmPCYc5TVUOKtc/d/DxRU3LtE+AZmtBdFqiwqyQhOfLfhrtKEAIBlVQ uj1uOJIY59ZeQsw4yE2RxhR2meEteNY69uJCMak4HMxp9lQ7dDShVA80K nO883X3bnzP+x0Vbx+l6Pqe/etSoB2IRcBjtmSqRq8dFJD9dLeJvBY1gU VdWXQEj2sT/GJlyCI86VOIjy4meVJlRJQR8uK5sdKbPE0Wzwe4L0iSoW/ U2dGv/8ZteTh4JhDv2jCKRgd54JHVYg5Lyf8ujjffXc8/rSG8gWZI86M3 iy+p6hTUtz+NqKGzcUOdfLYDP0+ghVwEtECw6u+6p1a0c+WT7DHJo82a6 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10723"; a="344006203" X-IronPort-AV: E=Sophos;i="6.00,198,1681196400"; d="scan'208";a="344006203" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 03:46:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10723"; a="850056935" X-IronPort-AV: E=Sophos;i="6.00,198,1681196400"; d="scan'208";a="850056935" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga001.fm.intel.com with ESMTP; 28 May 2023 03:46:39 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1q3Dv3-000Jjg-0a; Sun, 28 May 2023 13:46:37 +0300 Date: Sun, 28 May 2023 13:46:36 +0300 From: Andy Shevchenko To: George Stark Cc: jic23@kernel.org, lars@metafoo.de, neil.armstrong@linaro.org, khilman@baylibre.com, jbrunet@baylibre.com, martin.blumenstingl@googlemail.com, nuno.sa@analog.com, linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org, kernel@sberdevices.ru Subject: Re: [PATCH v2] meson saradc: add iio device attrib to switch channel 7 mux Message-ID: References: <20230527214854.126517-1-gnstark@sberdevices.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230527214854.126517-1-gnstark@sberdevices.ru> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 28, 2023 at 12:48:54AM +0300, George Stark wrote: > Patch adds two sysfs nodes: chan7_mux to set mux state > and chan7_mux_available to show available mux states. > Mux can be used to debug and calibrate adc by > switching and measuring well-known inputs like GND, Vdd etc. Thank you for an update, my comments below. ... > --- Missing changelog, what has been done in v2, how it's different to v1. > drivers/iio/adc/meson_saradc.c | 65 ++++++++++++++++++++++++++++++++++ > 1 file changed, 65 insertions(+) ... > +static const char * const chan7_vol[] = { > + "gnd", > + "vdd/4", > + "vdd/2", > + "vdd*3/4", > + "vdd", > + "ch7_input", > +}; > + > +static ssize_t chan7_mux_show(struct device *dev, struct device_attribute *attr, > + char *buf) > +{ > + struct iio_dev *indio_dev = dev_to_iio_dev(dev); > + struct meson_sar_adc_priv *priv = iio_priv(indio_dev); > + unsigned int index = priv->chan7_mux_sel; > + > + if (index >= ARRAY_SIZE(chan7_vol)) > + index = ARRAY_SIZE(chan7_vol) - 1; I think this is incorrect and prone to error in the future in case this array will be extended. What I would expect is to return something like "unknown". > + return sysfs_emit(buf, "%s\n", chan7_vol[index]); > +} > + > +static ssize_t chan7_mux_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct iio_dev *indio_dev = dev_to_iio_dev(dev); > + int i; > + > + i = sysfs_match_string(chan7_vol, buf); > + if (i < 0) > + return -EINVAL; Do not shadow the error code if it's not justified. return i; > + meson_sar_adc_set_chan7_mux(indio_dev, i); > + return count; > +} > + Redundant blank line. > +static IIO_DEVICE_ATTR_RW(chan7_mux, -1); > + > +static ssize_t chan7_mux_available_show(struct device *dev, struct device_attribute *attr, > + char *buf) > +{ > + int i, len = 0; > + > + for (i = 0; i < ARRAY_SIZE(chan7_vol); i++) > + len += sysfs_emit_at(buf, len, "%s ", chan7_vol[i]); > + > + return len; > +} > + Ditto. > +static IIO_DEVICE_ATTR_RO(chan7_mux_available, -1); -- With Best Regards, Andy Shevchenko