Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2186775rwb; Sun, 4 Sep 2022 10:05:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR57apezYGMshAqQ3QFigzydaTA26xA94SB9KbZjuUnyUbBZMHasqFakWx4W8MXCdrhu8D6F X-Received: by 2002:a17:902:f650:b0:172:8ee1:7f40 with SMTP id m16-20020a170902f65000b001728ee17f40mr46279001plg.101.1662311129007; Sun, 04 Sep 2022 10:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662311128; cv=none; d=google.com; s=arc-20160816; b=OcnyG4O/9xiS6BVswb1edNCrgo+63nCdlUrhREAe9MgMMefKD/CkE1yL7/SKQyFGOV ksUVwKMhxG1F0pw4iBk4MhJoVOCG8mwTP/eoBIheqqI0ta5L1OOKsbMT6/0Y1mzRKh3f Q5nP1io/WLM65iy0dvDA9xwWir3EWpvFPJXeDMwGDJzxhZ9QAU5UEQSOcUkAjU1uJifb TdkxWhoi2hGRy0VD7fkESw2F6lb/yKxO7fd9n6eVhNnRV01JTI+qqjZQ/o4Wg1+U9i8+ 792iUfu5JAy3m4YuxdYYB1xzpMa+aOKwbE27MWQaY6fCYCxG4yZfFxppDiRvcQA57XYF 474Q== 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=CFezfxgu6CbYmsB/a0XHAwCjARBvoYeQvCuxb2j4Oig=; b=gTRoVpli99toHFMIHs13pkCewJfTQvT+w7wh/fDKYo54EEgWN3B2dj60XhUMOvfxNj bRNw3SA11gBg/6eFbWrpKwAvCzynVO+HK8rX2H1QQNLG/J1NSBbaj647Iy03oBdY9Qyo qs6y9cbxWQFjMqAF1HPtIZBHt3d1oAP2UEAqNBL+m9majBp+UxbUUMCJbnP62sdcKlMq Zzuci/p17CSXtLmcDrrxieogWwiEapxQsW2ryegR2xnKGiioEf7aSAjczJ8PVdrWSzAR vTn8kxiymO6+mEplp9uBKckHAB+W5C3XEvoOZ8H5gt/yC4WrPTN9KQlhjnNAssDy+9sr OvoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J7czZ7K9; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a170902ce8f00b001744cf05e58si8899705plg.305.2022.09.04.10.05.16; Sun, 04 Sep 2022 10:05: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=@kernel.org header.s=k20201202 header.b=J7czZ7K9; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234925AbiIDQuP (ORCPT + 99 others); Sun, 4 Sep 2022 12:50:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230337AbiIDQuN (ORCPT ); Sun, 4 Sep 2022 12:50:13 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1028140B0; Sun, 4 Sep 2022 09:50:11 -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 sin.source.kernel.org (Postfix) with ESMTPS id 20BC7CE0B97; Sun, 4 Sep 2022 16:50:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F11AFC433D6; Sun, 4 Sep 2022 16:50:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662310207; bh=jcxJce531SFVVxvZzrqQFD0MFmKdV7Jnsc1mjlOBdH0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=J7czZ7K90dD5MorIwSTBO+HK60CbLbXiKx1GZyAWq9Itc2mhUkkD0Ui+aaetC4M3g AATQWY9uDA6I6apWKBQ4Udz5ZDh09uD3gRHQdq0FOZeWdY6GdDlf7NHIH6pKfvLMCQ rX+5ru+meCvjfSvONQlsu5xEUD6ssnow2nFvuEYjLlDTGi6/jcUH26Fe9YJiRYTt8a gfMLBfEtWR6+KWVvSDDdKfZ9CvcPcym1HaeKh84HqlYdgJUWRla3/POpBJaxSY66e9 ccSHzFJ5358YaNPv4qqPHegA/qgbSPB9arqdFcTPM7hqyHC+z3C2BWg9LWfeyRNshM z2+hWWGxVJFdg== Date: Sun, 4 Sep 2022 17:15:59 +0100 From: Jonathan Cameron To: Andy Shevchenko Cc: Vincent Whitchurch , kernel , Lars-Peter Clausen , linux-iio , Linux Kernel Mailing List Subject: Re: [PATCH v2 1/5] iio: adc: mcp320x: use callbacks for RX conversion Message-ID: <20220904171559.1bf77d42@jic23-huawei> In-Reply-To: References: <20220831100506.3368103-1-vincent.whitchurch@axis.com> <20220831100506.3368103-2-vincent.whitchurch@axis.com> 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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 31 Aug 2022 15:40:49 +0300 Andy Shevchenko wrote: > On Wed, Aug 31, 2022 at 1:05 PM Vincent Whitchurch > wrote: > > > > Replace the device_index switch with callbacks from the chip_info > > structure, so that the latter has all the information needed to handle > > the variants. > > Below are for the further patches, as I see the original code has the > same disadvantages. > > ... > > > struct mcp320x_chip_info { > > const struct iio_chan_spec *channels; > > unsigned int num_channels; > > unsigned int resolution; > > > unsigned int conv_time; /* usec */ > > Instead of a comment, I would rename it to conv_time_us. > > > + int (*convert_rx)(struct mcp320x *adc); > > }; > > ... > > > + return adc->rx_buf[0] << 5 | adc->rx_buf[1] >> 3; > > > + return adc->rx_buf[0] << 2 | adc->rx_buf[1] >> 6; > > > + return adc->rx_buf[0] << 7 | adc->rx_buf[1] >> 1; > > > + return adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4; > > > + return sign_extend32((adc->rx_buf[0] & 0x1f) << 8 | adc->rx_buf[1], 12); > > All above should really use > > u16 buf = be16_to_cpu(&adc->rx_buf[0]); > > return buf >> 3 /* 6, 1, 4 (respectively) */; This made me look a bit closer at the code. rx_buf isn't necessarily aligned... This may be a good usecase for an anonymous union. Which would be fine except one of the callbacks (and original code) uses be32_to_cpup() which is not unaligned safe. I'm not keen to push unrelated work onto someone doing good stuff on a driver, but in this particular case it does seem reasonable to tidy all this up given you are moving the code anyway. Jonathan > > ... > > > + if (raw & BIT(22) && raw & BIT(23)) > > > + return -EIO; /* cannot have overrange AND underrange */ > > + else if (raw & BIT(22)) > > Redundant 'else'. > > > + raw &= ~BIT(22); /* overrange */ > > + else if (raw & BIT(23) || raw & BIT(21)) > > if (raw & (BIT(23) | BIT(21))) ? > > > + raw |= GENMASK(31, 22); /* underrange or negative */ > > ... > > > [mcp3201] = { > > .channels = mcp3201_channels, > > .num_channels = ARRAY_SIZE(mcp3201_channels), > > + .convert_rx = mcp3201_convert_rx, > > > .resolution = 12 > > + Comma in such lines. > > > }, >