From patchwork Mon Mar 11 16:28:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 13589069 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 460F6C5475B for ; Mon, 11 Mar 2024 16:29:45 +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:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ILjgTmE+2hHSDpntGEIDqeA4U4v+uE3SnH0e//tsfSc=; b=LNG7JJ2s5QG6AF 5zxseECzLy3FHEK4R/FReia27C9WL/+Kz5CnDgcL6ILJkn7mwPLlu+j0R7/l3xPEXc9nJKdC803TN h2R090YcvQOtF5KyrxRcE4m5DzRqf2E0Zm7LtXibeq3b6hLu8QOVgKZ8bh1kSVQ27YiKqe0W6O/JP GUA4/I+UtaDbvyS9uemk3TeKZypy2l8Fw3iIuMvTLTOvomVY5aO7VhsWEOxPWkzOZwHPvGKp3S1Qb X98Ul+rkJQaXZjADFiQIMmwCHqdBx/4jl+zTOlQXIBAmCkxcLOBI+T8oC8+JqToSrMi47GQ5gUDBc Dj4+4nUcH0XOjswBggNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjiWp-00000002KXU-1MIs; Mon, 11 Mar 2024 16:29:31 +0000 Received: from out-176.mta0.migadu.com ([91.218.175.176]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjiWl-00000002KRk-08Vc for linux-arm-kernel@lists.infradead.org; Mon, 11 Mar 2024 16:29:30 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710174519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Fz+FWvrcKcTv16JX/4rIFVS9wfxLnJCR/qRfWEpLaNk=; b=RDPLo44sQaeMkdNhTv6N0tAMk2tGBUxNZLmt3ZalRc47ltWKJOh7MOtOHuM2AK/IIUtWKm MqjCWr/HAbThPLudVpfzuo6UojtXF2Qwh51ka8asfAs3n9KrVhxNJ0k1rJucqUrwJQto1y VIpnvPeAog6M3OEJ0GMmYBre8yFruG0= From: Sean Anderson To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Conall O'Griofa , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Lars-Peter Clausen , Sean Anderson Subject: [PATCH] iio: xilinx-ams: Don't include ams_ctrl_channels in scan_mask Date: Mon, 11 Mar 2024 12:28:00 -0400 Message-Id: <20240311162800.11074-1-sean.anderson@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240311_092927_517631_EF275ED2 X-CRM114-Status: GOOD ( 11.07 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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 */