Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2162518lqp; Sun, 24 Mar 2024 06:08:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUykBcr/QDiVlP3FpX2eIbkceiT/o6fkk9f42/FbhVbYJotbm9MvGzd9veVjcLYhm4byNyVXDjvnVWm8heTP9BQgoGDOrXnJj4189UlQw== X-Google-Smtp-Source: AGHT+IH83DuY9H7lpABIanyAMAPYmXIH84iSzEaUGA4i2Ad07gjKVz+oeufmKbe5OyuTQtDFlRSz X-Received: by 2002:a50:d4c5:0:b0:56b:ad9b:b2f6 with SMTP id e5-20020a50d4c5000000b0056bad9bb2f6mr2631452edj.24.1711285702407; Sun, 24 Mar 2024 06:08:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711285702; cv=pass; d=google.com; s=arc-20160816; b=QqiVKbW3kpHjasO8NJTZXh5iWCwYSJyXtlfiNdjpxNjeZnekMut3bY0PCkJMKe6ujz y46rRDl6ciW4ZdQxN4q4fP4swBRh6fa7SH9+39VSbgE0m9MuXgnbVQ5VzqvII+z+8PXi mye5pLeVAyCAB+t2aW6TTRMhL/oOAuDrhGszrX54lDtVrkguqEehL2A6OBfvL5jbyejK gxVfnlJKR0ETbUUjEP2MFKv3e9Q+ZYM+LOPt+9C4EOl6ikoEgnxj/NU7OU7ZDn07ExNm CGOUT3g3WxWK7YsNDhwI2D5l76vifSxRniZPn/L4UoPg6okSw1M3sSc+Ds1eikYQQhGt xYsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=I657crtg6+SU/3j640qmZsG7/s5fEXNWOUbeWKd4X6Y=; fh=MyNZIgpx1MSNRB2sApNtUWYmWkOO0A8hUBu4tnLlvBw=; b=uX059hz12hRXDK3jk/0olyd1RYKdEeI+UF3vZVCjnCy0/OJlHCMG4+TyIma/hrSXSJ N5iN1BqFdB4iNFwDQvRFw952RyYVAi/YyChbP7SCxglOpgqdQZ5+wP3P2dsGllL2b0eZ Z1753i9CM4VTMOjVCyoJwv/LQakAXskIGIULZbEZwngrb0Y9HIgsHLQdRK43d4uwlsUG F1D6qfs6pogEOVuxE5wGM1ElQFsS/a8j5oF3w2MXgADI06zOqKqjDPsONnQaaapqGd/8 L+qb0BeyPQOrl8G95y/dyBZ06N+s20swpz1Fbr5ENnkVXiEw2MykX7vrSIRRpD0ye2hM 5jyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rd+9Qsgi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112674-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112674-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m11-20020a056402430b00b0056bf9ae1936si1347411edc.485.2024.03.24.06.08.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 06:08:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112674-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rd+9Qsgi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112674-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112674-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0B2121F21390 for ; Sun, 24 Mar 2024 13:08:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45CA017BCF; Sun, 24 Mar 2024 13:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rd+9Qsgi" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60B831A38EA; Sun, 24 Mar 2024 13:08:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711285693; cv=none; b=lCzUkIx/wiWEkL7E4pinbMxZg9vszK3+AaNgTaYIvPoUfyQh4oTb/Ne1CwWlx+RJ1MNLWhCwqjpnMChwsIhDN9gKrgD/Pu7wGzgntugXT59u+3Zq+6HzctRwCXp0Xzty1pXOH6CcOeTVcutZt5BlOoJLgQtnXkHhricQbMhkh9E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711285693; c=relaxed/simple; bh=nfUcghzizgYYm6MDQuZDNwGKaMDBsPTJ7jiCL02Z46c=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H4OAKdCVzUhKnhQNi3NbxcPAQesUdBky7GZKpxB3sHuMrCw+B9g+YFW5alikIIOY4lWzsW/zEUvrzwEOcLwAjpml4zOUGHVp8qvAuaA2mVY/sOpHxm+aqxOlVnkjx6XgfIfQwJjbbrQr29BEobr7a8tXde0mnUgx0MMwPozQKDU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rd+9Qsgi; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C19EC433F1; Sun, 24 Mar 2024 13:08:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711285692; bh=nfUcghzizgYYm6MDQuZDNwGKaMDBsPTJ7jiCL02Z46c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=rd+9QsgiBv0WXLpZ/y8rOCqMF9QKq6oaUP/fcSzeBZjl1hY10NH9dgntlx9jnLJ6g VDK+zzgOPj2PMd/r8UsS3zIqWNLIuykEU45kPkvQ5suVVKBzAlTnTqzCTc/zTPeOUj qtVivZZhJpm+t2YldwO9+jSE8dqI6Py2NqueRiUAEDb/B9cPiSLvXoaRdZbqwQu/J3 8/kclF/NaQRKAqzEdQ7OTxA4A/ZECyEGQyH5o58pW9C+e/3iu1h+3chYF6SUJjo/sv 6ZLG2ab2KPxVlVCqwhF1EQ1mXNO6CPkT1ANu2JItxtqR5cPBB1DCNX0e/wRPDo2pne aFcU5M3iRYPpw== Date: Sun, 24 Mar 2024 13:07:56 +0000 From: Jonathan Cameron To: Julien Stephan Cc: Lars-Peter Clausen , Michael Hennerich , Nuno =?UTF-8?B?U8Oh?= , David Lechner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot Subject: Re: [PATCH v5 5/7] iio: adc: ad7380: prepare for parts with more channels Message-ID: <20240324130756.598a4b36@jic23-huawei> In-Reply-To: <20240319-adding-new-ad738x-driver-v5-5-ce7df004ceb3@baylibre.com> References: <20240319-adding-new-ad738x-driver-v5-0-ce7df004ceb3@baylibre.com> <20240319-adding-new-ad738x-driver-v5-5-ce7df004ceb3@baylibre.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 19 Mar 2024 11:11:26 +0100 Julien Stephan wrote: > The current driver supports only parts with 2 channels. > In order to prepare the support of new compatible ADCs with more > channels, this commit: > - defines MAX_NUM_CHANNEL to specify the maximum number of > channels currently supported by the driver > - adds available_scan_mask member in ad7380_chip_info structure > - fixes spi xfer struct len depending on number of channels > - fixes scan_data.raw buffer size to handle more channels > - adds a timing specifications structure in ad7380_chip_info structure > > Signed-off-by: Julien Stephan > struct ad7380_state { > @@ -148,15 +168,15 @@ struct ad7380_state { > struct spi_device *spi; > struct regmap *regmap; > unsigned int vref_mv; > - unsigned int vcm_mv[2]; > + unsigned int vcm_mv[MAX_NUM_CHANNELS]; > /* > * DMA (thus cache coherency maintenance) requires the > * transfer buffers to live in their own cache lines. > - * Make the buffer large enough for 2 16-bit samples and one 64-bit > + * Make the buffer large enough for MAX_NUM_CHANNELS 16-bit samples and one 64-bit > * aligned 64 bit timestamp. > */ > struct { > - u16 raw[2]; > + u16 raw[MAX_NUM_CHANNELS]; This can get problematic for drivers supporting devices with varying numbers of channels. You are fine up to 4 channels as the structure layout isn't changing. The reason is that it implies the timestamp location, which if you were for instance to support 8 channels would be incorrect if only 4 of them were enabled. Now the timestamp location is only used implicitly in the driver (as the IIO core handles the actual insertion of the data) so it's not a bug as such to do this, but it can give people the wrong impression during testing etc. As such, I'd like to see the comment mention that "as MAX_NUM_CHANNELS is 4 the layout of the structure is the same for all parts". Note I've reviewed one driver today that did have different layouts depending on which device was in use and ended up falsely indicating the timestamp was later than it actually was in the buffer. Hence my request for a defensive comment! > > s64 ts __aligned(8); > } scan_data __aligned(IIO_DMA_MINALIGN);