Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp194633lqb; Thu, 14 Mar 2024 08:48:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV90LXpqRnI+oCEN2A4PPBgcEDnUTBkbzIwFnQfIXP/kKkyd8sksPqmBkJ0huaWGp1UyLkHRhFCLxT5yikwP8Hc+bmIcJLrYWWhf1leaQ== X-Google-Smtp-Source: AGHT+IEZUfNB7A3Y6XHrFenFSbADNM9vHy7qxjcZKJ1bGm7tAjKeqdEsZZ2TOjOQNcx9ALwvePzd X-Received: by 2002:a17:906:11db:b0:a46:6808:2cee with SMTP id o27-20020a17090611db00b00a4668082ceemr1427669eja.66.1710431328282; Thu, 14 Mar 2024 08:48:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710431328; cv=pass; d=google.com; s=arc-20160816; b=T/REYASjzR7PNijDBPh+Y3w8VGVRY1ly1vjWN19KSw/hqJgAUWmMFUTbwf4C5Fws6+ iJ593O44kGy+GzVbztM5z/0jfI7qLLYOyNBMgk3rtkHztdddN2z096PWWLzRDEK++rrF sa5ev1wD0yPzK4SOLWsgVS47mO4XBlfZriEHVzZVcLJ0coMWVwoDSe/z8tJ4tk/QSDJT FwZ0tBOcfDJkxGHyRqmErFFlqsXFQpl7t0Kw0h4QwddLsUykIS/YqsODzhOThoGa4eD4 JYuvEhDko6xjKFDuaJ2garUAuoPoS/qTe1iWrgapZSzbk+HKtKuAM8SLpCQotso8pwGm Nexw== 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=pdDknncIO6QT2GiNPspxlhS1glseeNNC6YnxE67fL08=; fh=CP0b6dx7n3r4Uy2obpYnjsyaNGX0EelW+xlRP3ApVM8=; b=sraIvVpEJuB+CUeBlKrCGqssM+5x+L3SHpqco3dErxToDUmOAdViYMpqW2NoyL5MLV YatWuOwc5ab16i433n7S70H57tHxPma2ZaajmrJBaSMJp3QN0mIWFWdoYVYcSv9l95Sx j/dQuCUMuYw28kuLqqxDtLpE7xD29IdDihQRDKXRRmg6QNdM50Ue+6rPQDnbm2kuzLiQ ofuU1MoIy9ODxKuM3T/0xfHC6c5HnoEOnPy3XRVpRDzPErpN7YIWaFsGWof3XtFLkzni 3gxypop4+Edjsj5ktYmhAOvCz2aRiyXoj3m9sKHWUcS0vfE68LM77/+bK+DdldPAOMPf STXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bPzhtKkE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-103526-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103526-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d21-20020a1709064c5500b00a462507f2a0si827152ejw.66.2024.03.14.08.48.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 08:48:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-103526-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bPzhtKkE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-103526-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103526-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 D315C1F2364F for ; Thu, 14 Mar 2024 15:48:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A7587316C; Thu, 14 Mar 2024 15:48:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bPzhtKkE" 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 6F5F370CDE; Thu, 14 Mar 2024 15:48:39 +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=1710431319; cv=none; b=q6e17FLbJtwHBV2bZ4WpKPnWGA+PISfmb45oGrffeVdwq0aV2nXQN2Nsmtq19sZiCGVACeDwqf3W88MKQp8bvU6eluHsYNEgzmZzZ16r3mrChHdqEjBlIJQIdKpDVW5Cvf5S96j8CLuIRfc8T4iepjfKEd3QfgtLiwnmgwJB6uI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710431319; c=relaxed/simple; bh=OLsVf26jNfkPFiisfEugFBO1YbcQjLA5KAEGjzL2Fls=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WNeLVUvV6hg4EyMxmqJR8bYnEU5slG/N0l3JQ25HLONM4APrvB2QTN4mZ3R9YYyKfca05A1nHdXnHDjGITP6+TNaqvYTSQjOw1ERrCwx5kTH8Yvu05RGb2UkbAUnyWZtKKtVzi0aKRbuHEJukrji+2fPKZIa8eZbdn7s3nuRI7Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bPzhtKkE; arc=none smtp.client-ip=10.30.226.201 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) 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 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 */