Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1674994ioo; Sun, 22 May 2022 23:58:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3bIZtwTb7GYI5KChEiXulReiECTBUgYMSe24zhlZN99GaGCwUJikTXAAaK6Q+R9YEqyfg X-Received: by 2002:a63:e80a:0:b0:3f6:2cc9:63b5 with SMTP id s10-20020a63e80a000000b003f62cc963b5mr19075339pgh.4.1653289112869; Sun, 22 May 2022 23:58:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653289112; cv=none; d=google.com; s=arc-20160816; b=Ta50ZGdWtiWpaBF3tAebfvw7rrv+ToanJpmjBc4hjhtbcESQd10Y+b2CIf01f9eRaZ D/JFNKDvipsn7OnZbRKFUdfTTqIhFfBGoOBGYn2SGahZRellaQJt/Fnpa4qkF7GDvOmt 3rW0oUsaOX7oug4PKwI3EQxPi0Mn87O5fokD29q2ZuRtSfrlD9QCB1/Z2xzRQZuLkQgE iiZUNAZ4FSxZ0F6ccDbW/9Rjce9T8YJPTTfgE1Mwn9igHkpXEdLCWLqUr3jhv3sPVTLW MRoD6Qi/F7D2Z4epmuwWpyBidLIFXvUQrN6OflG+jvO5lrk2whvbgBQoUpEbe2Y2X7U2 BqFw== 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:subject:cc:to:from:date :dkim-signature; bh=wRSdiGthj9qSEVK9YMCN1yM534+v4n4JqEBVqZkxzb0=; b=BgR8eoEYJXM6tqnp67Q0b86jdCq8y6nOqbXyjs1WovrHVw0uaWcUE2sxjl68/JLija ZJDz+VfsRAfCgQ1o0cvMZoFztwVc5pnZboVxJuj3kCUyzyhiUNUgXJkmmadKBCKmzzWd 9sdBP1wSh1lJG/D+Xvz03F3GBj2UDro2rh7gtGpCvgDX3m9mLIcmQgwbWzT+9WiGZaOy DNeXzCz3BeDd1ku4KYpIlHhlC0Pike9AbPR7D75l4TsxjhWqyCFAAhDTiIDcdDjSJot+ XV7WYT+zD0X9zsqWJlt8jm1nzXEG9zfPIeLfE3pQCdj25qoTenw/Pimkau5JlG7fOrHh Td3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hNdqND7H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id nu10-20020a17090b1b0a00b001e008038781si12036031pjb.105.2022.05.22.23.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 23:58:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hNdqND7H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8037945507; Sun, 22 May 2022 23:23:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244100AbiEVKfw (ORCPT + 99 others); Sun, 22 May 2022 06:35:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230336AbiEVKfu (ORCPT ); Sun, 22 May 2022 06:35:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 918EE26130; Sun, 22 May 2022 03:35:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2C8EF60F80; Sun, 22 May 2022 10:35:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DC03C385AA; Sun, 22 May 2022 10:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653215748; bh=ToPPiqXwjV73nuk6F3aB1XXuCBH0hY3ecj+MRp5HnJ0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hNdqND7HH8gf9A01HNghh2ETdxi3oognFIrhLdUrazqBUIlRJT6erMOeANnv6DUfJ 1pUCV5wyTgOT7CmG8nPItqVXmOPxEpOkuABoFE9pgN4vK4l66jKmfh7BfwoqI7D9ER ZBbSmZFBoYgg8yLN/I2shLxYNLeqfpVypSt1MtwOY+S3Bv28XMAeaHDLaGdfUecnz+ UbhX1UZ0Ek5CJFH6XdEPmt9DHiJxRdbQMVcf/2JvoWMT8UzGgqG/LKLAK/aJqd7EhD bXtNB3G+4sFwOPRp6wS/2UnLGlUektGLYfMfhVB3rEKOXzNaC6XWwtYUuQiTw1Uvlh 5TRIo76rWt8og== Date: Sun, 22 May 2022 11:44:33 +0100 From: Jonathan Cameron To: Tomas Melin Cc: LI Qingwu , lars@metafoo.de, robh+dt@kernel.org, andy.shevchenko@gmail.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Subject: Re: [PATCH V6 3/5] iio: accel: sca3300: modified to support multi chips Message-ID: <20220522114433.6d3257e1@jic23-huawei> In-Reply-To: References: <20220513124135.1295822-1-Qing-wu.Li@leica-geosystems.com.cn> <20220513124135.1295822-4-Qing-wu.Li@leica-geosystems.com.cn> <20220514151003.42fa5044@jic23-huawei> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 > >> +static int sca3300_set_frequency(struct sca3300_data *data, int val) > >> +{ > >> + const struct sca3300_chip_info *chip = data->chip; > >> + unsigned int index; > >> + unsigned int i; > >> + > >> + if (sca3300_get_op_mode(data, &index)) > >> + return -EINVAL; > >> + > >> + for (i = 0; i < chip->num_avail_modes; i++) { > >> + if ((val == chip->freq_table[chip->freq_map[i]]) && > > > > The conditions being checked here are far from obvious, so I think this would benefit > > from an explanatory comment. > > > > Something along the lines of, > > "Find a mode in which the requested sampling frequency is available > > and the scaling currently set is retained". > > > In addition to a comment, how about small restructure of loop and giving > local variables that tell the purpose, something like > > > ... > > unsigned int opmode_scale, new_scale; > > opmode_scale = chip->accel_scale[chip->accel_scale_map[index]]; > > /* > * Find a mode in which the requested sampling frequency is available > * and the scaling currently set is retained > */ > for (i = 0; i < chip->num_avail_modes; i++) { > if (val == chip->freq_table[chip->freq_map[i]]) { > new_scale = chip->accel_scale[chip->accel_scale_map[i]]); > if (opmode_scale == new_scale) > break; > } > } > > > That way it's IMHO more clear what we are comparing. LGTM. Thanks, Jonathan > > Thanks, > Tomas