Received: by 2002:ab2:6486:0:b0:1ef:eae8:a797 with SMTP id de6csp344134lqb; Sat, 16 Mar 2024 06:36:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUtXW2Glots8/Xtk8OP2m2PGd2l7JZ2z6Zo9f25jZbERGZKLsnzP2UAUNkHTNYKRpqjEq8zKQNsSH+j7t3qAsN83q4H3Cj+2OYkxlTsJA== X-Google-Smtp-Source: AGHT+IGXWfZE7tb8aozlw5cvcvJAZug762WH5B0ziQ5jhpV2hoGLr8/fcJfUMPNELgMAMqWy7pvu X-Received: by 2002:a05:6a00:3d56:b0:6e4:890a:7af with SMTP id lp22-20020a056a003d5600b006e4890a07afmr6865713pfb.26.1710596217999; Sat, 16 Mar 2024 06:36:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710596217; cv=pass; d=google.com; s=arc-20160816; b=O24meKNNsLdbzfiHFw6vRRZnKG3IZLSr0MrjIQallJzgeOXgYog0xU6QsDnkLwpY6c tE9e0QX2dQ9lnb5RoDndYoyPFn4t10Yv5blk4MSs7slAr5wzOVkP4i6ShYlqMU6xZOV7 xDZfqhgbvn6jJYCJjI/5NgBYIMO6Hn459i/zf+PgeOho23gqtr/8ztwI0rAazeteU1Qb dXhNzlrZmpu3n3PxBOogxrgNuxkG7CYWYr+fqa6Fq+5YZRQ/oHu2kgvmt5CELiGAahE5 mjIsMQo9JCjzRQmApljjvkCwcaBkUmdjOoNvFACm2fxw/AkAyNoUpSE4VyCaGMBbs02u tORA== 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=U+G5Ta6f3GNV8YMGcXcw+nFOhdGnjajVF4sd4CL6FLM=; fh=rQ480tiYROFsCEF4wHQxLBInI6A5DrZEzKWX0oNf/KQ=; b=s664M0jYHKzJIzJcw19DZW6AKWK3X+XZTKT/x7qBs0EfBPDfWJ/VPzXKc9I4j0mzWg kxViD2BqIfLsKYsUleU0+ydYfe96gS40u+hOx46UwIlIasBkzltIhzKQA2nO0AUWRu4T 00m/CbClDwSJZGRnvgw6dzQ++QFIX2NHh5fJq/wXNJiDAyzlD/RnKtgIyXYCu3sLkS8Z SK0zSTScCgL+J4H8vE8hO6SEaB8FiyE0XzcG/3VVHhPvs7AMGDHCtiK+5B16iv9TUrNk yUb8EmPnBFEQ95brCNd8GBysAZ69H3+1X82ClBepmInCwHki0WWd/HiaBFvTZsNgZT7s 4m/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PO0TnXNO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-105187-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105187-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q15-20020a635c0f000000b005dc12137745si4471277pgb.151.2024.03.16.06.36.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Mar 2024 06:36:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-105187-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PO0TnXNO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-105187-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105187-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C9EF7B2134B for ; Sat, 16 Mar 2024 13:36:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B069018C36; Sat, 16 Mar 2024 13:36:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PO0TnXNO" 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 C57082F4A; Sat, 16 Mar 2024 13:36:42 +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=1710596202; cv=none; b=DqzD1syLxEC0lxvjWcmi21c3cbxwMtITEDa1CJ0JSWOY1NcmNRW1RdVU75UPcHmYmTx+ajMLIpQ64GndGfZ9CZxKX1/OCSJuWAl2sxeY86xnfzxLMYFlDt8XBluFbwJdajOYa1Vs45S0hZRvaUPfvwEVx8/arTltF1k2IlOnspk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710596202; c=relaxed/simple; bh=XdPZXsL26Mxip3HHx+7NpZ0egkvJ9o2OTxsp0p3pia0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GkTEBzOZLNbYXGbBlofyTL6c/FmznHsBvlQHxJM4W/GHwYDPexCYoOthu6c64PbQB02AzAaG9aBIRJS8nNUysswTd6xeD4WnhseerOq3o2G9ysRM1u+W++owD3gcKAEMOpsoH+dYtevbE5BNKETxie5NLO5Xyt4VSdK58AJSkWE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PO0TnXNO; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84C9CC433F1; Sat, 16 Mar 2024 13:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710596202; bh=XdPZXsL26Mxip3HHx+7NpZ0egkvJ9o2OTxsp0p3pia0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PO0TnXNOGamjsfEbRH6yEFyRPVD8RjF2gBrc8MCuTjX/19Iec1G3oDKOTADkQ6JbF hvs/YoBB0J5dU2Swq4I4wb4a3LmIwn3n50IsHVK5Dc2z2r7mZjUxSPfeYADMOuxli9 8NbBW2cLqq8M0gffAXC1i7JZS5fPzpbJqFXyiwZAzPGtgDjWtKtbt+JUYkL2G6GdgO W0GoWLgEYUptw8RLHEve+Jgk1KAZDI+HK1RImUJOZuZXUsLS09ICXtBLLeZxBMlJOj IrmzUGewQ6AFLe/Zw5+Ng7AwnBYr9flOS/jlrkfYkV0qsJuKx8zxyKy7bZkmtniAWC tRD9eBkMqTZfg== Date: Sat, 16 Mar 2024 13:36:27 +0000 From: Jonathan Cameron To: Sean Anderson Cc: "O'Griofa, Conall" , "linux-iio@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , Lars-Peter Clausen Subject: Re: [PATCH] iio: xilinx-ams: Don't include ams_ctrl_channels in scan_mask Message-ID: <20240316133627.5d2bf585@jic23-huawei> In-Reply-To: <3b481539-0c9c-4110-ad03-bd252e80efb0@linux.dev> References: <20240311162800.11074-1-sean.anderson@linux.dev> <20240314154824.37150a54@jic23-huawei> <3b481539-0c9c-4110-ad03-bd252e80efb0@linux.dev> 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=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, 15 Mar 2024 13:47:40 -0400 Sean Anderson wrote: > Hi Conall, >=20 > On 3/15/24 09:18, O'Griofa, Conall wrote: > > [AMD Official Use Only - General] > >=20 > > Hi, > >=20 > > I think there was a fix for this issue applied to the version that was = running on 5.15 that didn't seem to make it into the upstream driver. > > Please see link for reference https://github.com/Xilinx/linux-xlnx/comm= it/608426961f16ab149b1b699f1c35f7ad244c0720 > >=20 > > I think a similar fix to the above patch is may be beneficial? =20 >=20 > These patches look functionally identical to me. Because there are no channels with scan index between 22 * 2 + 16 (that patch) and 22 * 3 (your patch) that is the effect is indeed the same. But given the issues is the 64 limit on maximum scan index, 22 * 3 =3D 66 is an ugly value to compare with. I'm still very against the use of scan_index for anything other than scan indices (which is why partly how this bug wasn't noticed in the first palce). So the check should be scan_index !=3D -1 and uses of those values elsewhere in the driver should be fixed (which looks simple to do from a quick glance at the code). Jonathan >=20 > --Sean >=20 > >> -----Original Message----- > >> From: Sean Anderson > >> Sent: Thursday, March 14, 2024 5:30 PM > >> To: Jonathan Cameron > >> Cc: linux-iio@vger.kernel.org; O'Griofa, Conall ; > >> linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; La= rs-Peter > >> Clausen > >> Subject: Re: [PATCH] iio: xilinx-ams: Don't include ams_ctrl_channels = in > >> scan_mask > >> > >> Caution: This message originated from an External Source. Use proper c= aution > >> when opening attachments, clicking links, or responding. > >> > >> > >> On 3/14/24 11:48, Jonathan Cameron wrote: =20 > >> > On Mon, 11 Mar 2024 12:28:00 -0400 > >> > Sean Anderson wrote: > >> > =20 > >> >> ams_enable_channel_sequence constructs a "scan_mask" for all the PS > >> >> and PL channels. This works out fine, since scan_index for these > >> >> channels is less than 64. However, it also includes the > >> >> ams_ctrl_channels, where scan_index is greater than 64, triggering > >> >> undefined behavior. Since we don't need these channels anyway, just= =20 > >> exclude them. =20 > >> >> > >> >> Fixes: d5c70627a794 ("iio: adc: Add Xilinx AMS driver") > >> >> Signed-off-by: Sean Anderson =20 > >> > > >> > Hi Sean, > >> > > >> > I'd ideally like to understand why we have channels with such large > >> > scan indexes. Those values should only be used for buffered capture. > >> > It feels like they are being abused here. Can we set them to -1 > >> > instead and check based on that? > >> > For a channel, a scan index of -1 means it can't be captured via the > >> > buffered interfaces but only accessed via sysfs reads. > >> > I think that's what we have here? =20 > >> > >> From what I can tell, none of the channels support buffered reads. And= we can't > >> nai=CC=88vely convert the scan_index to -1, since that causes sysfs na= ming conflicts > >> (not to mention the compatibility break). > >> =20 > >> > > >> > I just feel like if we leave these as things stand, we will get bitt= en > >> > by similar bugs in the future. At least with -1 it should be obviou= s why! =20 > >> > >> There are just as likely to be bugs confusing the PL/PS subdevices... > >> > >> FWIW I had no trouble identifying the channels involved with this bug. > >> > >> --Sean > >> =20 > >> > Jonathan > >> > > >> > =20 > >> >> --- > >> >> > >> >> drivers/iio/adc/xilinx-ams.c | 8 ++++++-- > >> >> 1 file changed, 6 insertions(+), 2 deletions(-) > >> >> > >> >> diff --git a/drivers/iio/adc/xilinx-ams.c > >> >> b/drivers/iio/adc/xilinx-ams.c index a55396c1f8b2..4de7ce598e4d > >> >> 100644 > >> >> --- a/drivers/iio/adc/xilinx-ams.c > >> >> +++ b/drivers/iio/adc/xilinx-ams.c > >> >> @@ -414,8 +414,12 @@ static void ams_enable_channel_sequence(struct > >> >> iio_dev *indio_dev) > >> >> > >> >> /* Run calibration of PS & PL as part of the sequence */ > >> >> scan_mask =3D BIT(0) | BIT(AMS_PS_SEQ_MAX); > >> >> - for (i =3D 0; i < indio_dev->num_channels; i++) > >> >> - scan_mask |=3D BIT_ULL(indio_dev->channels[i].scan_ind= ex); > >> >> + for (i =3D 0; i < indio_dev->num_channels; i++) { > >> >> + const struct iio_chan_spec *chan =3D > >> >> + &indio_dev->channels[i]; > >> >> + > >> >> + if (chan->scan_index < AMS_CTRL_SEQ_BASE) > >> >> + scan_mask |=3D BIT_ULL(chan->scan_index); > >> >> + } > >> >> > >> >> if (ams->ps_base) { > >> >> /* put sysmon in a soft reset to change the sequence *= / =20 > >> > =20 >=20