From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1BE2CC54E60 for ; Thu, 14 Mar 2024 15:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YnIGSyvzvskrfCHHkdNWSsUAN4/1puxZcuJ7aKPOm5U=; b=M4UFUqdd72ulLt wS8cPAjpFHesj1aXMzgJkzr19KCDyl+RZge5Eoj0w3DU3JzQqEBHKD4+kiZuQwaD3lgB2eLtBD9Gf O9pte9BzqH7hd0pGeKAUUFMVQbCSCAl1AheGYAIs9BnwpIEjYOrNMhF74iEcgIMz4APRt6q99cNZq U18Y5ZOXqtwhUVSr02IEiAAbC5SMDu76o8V8nfnDoXccaKG9h5tXGc1fq7kxiDH6pYuVeos3iWxn/ 93RThxrrdG0hFJIg2T9dxHSNLu5LvsiJPp+A7DjYP9uXHBOzml1riv4MgdumoqGedMjySTj7cVQ+L skd/9LaqihbVEAFAytiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rknK1-0000000EuJD-1VWi; Thu, 14 Mar 2024 15:48:45 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rknJy-0000000EuIW-464S for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2024 15:48:44 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8F7F0614F7; Thu, 14 Mar 2024 15:48:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98E77C433F1; Thu, 14 Mar 2024 15:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710431319; bh=OLsVf26jNfkPFiisfEugFBO1YbcQjLA5KAEGjzL2Fls=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=bPzhtKkEhBHnuGWggN1nm4nQo0KhM1ldUYWfoBQTGfDO1T9hGpq67UPj8H7FDITGN 7wtXS/ZM5VHib8AGEgYWVDVOCqv82XEAoqMj06KxmU9riKG6pfIjLSEraOdgiMrj23 aZe1tDnBIWbb1ZM6blvYH/4vT1+9cS0DSomOKhTIIS/HTZsO3/hg4+O8vjIDfsUPaM vpQQ2E2iux+1g7RXHDV2Eh65RwlcO0Ck6YP/WqcjTAs0i/XeoUqBSvS+kNZRHxalp3 vkXfXEnH1U0OyPie7GgK/OIlqhIppBH/fhEKTrekPwL5Y5X9vEJOuCJ8osMuh7KHap L2XceuIrwXPkQ== Date: Thu, 14 Mar 2024 15:48:24 +0000 From: Jonathan Cameron To: Sean Anderson Cc: linux-iio@vger.kernel.org, Conall O'Griofa , 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: <20240314154824.37150a54@jic23-huawei> In-Reply-To: <20240311162800.11074-1-sean.anderson@linux.dev> References: <20240311162800.11074-1-sean.anderson@linux.dev> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240314_084843_099057_7CA48001 X-CRM114-Status: GOOD ( 22.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 11 Mar 2024 12:28:00 -0400 Sean Anderson wrote: > 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 exclude them. > > Fixes: d5c70627a794 ("iio: adc: Add Xilinx AMS driver") > Signed-off-by: Sean Anderson 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? I just feel like if we leave these as things stand, we will get bitten by similar bugs in the future. At least with -1 it should be obvious why! Jonathan > --- > > 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 = BIT(0) | BIT(AMS_PS_SEQ_MAX); > - for (i = 0; i < indio_dev->num_channels; i++) > - scan_mask |= BIT_ULL(indio_dev->channels[i].scan_index); > + for (i = 0; i < indio_dev->num_channels; i++) { > + const struct iio_chan_spec *chan = &indio_dev->channels[i]; > + > + if (chan->scan_index < AMS_CTRL_SEQ_BASE) > + scan_mask |= BIT_ULL(chan->scan_index); > + } > > if (ams->ps_base) { > /* put sysmon in a soft reset to change the sequence */ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel