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: 13589068 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 E74DA47F63 for ; Mon, 11 Mar 2024 16:28:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174527; cv=none; b=uvkFqfG3XU8ZXEmGmIqmguJHpcGzirpNnLeF1xSA9/7TiZquRxiSqKFy8Rn/rHMg4S4x+ZNwzpn6GSMbByeyjKPQ39nEw+9PSZIzrFAGw2uXDxbG6C7fNAXcMeFPngf4dUIorPpG+4LP3y0oLhdWupMUnbBoHeWPfptHMvOvQ1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174527; c=relaxed/simple; bh=BOe/URe3IpcizYmw7Op+xPHG8Hus1zm8G3nNk6OMm1k=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=jdukxWwoznN/RdCQVW6QziCv0S8KQ5RELz56L4INLLbVGS3bCuL6Srraz4fZPAG/dSSxDMJxdkqv5ZybGcKUxRfDpjldw5gCC+WUZ7BcTgwyuLNKe1ZyuWMjPyW/iI0E4Cs9TWi7MSR4QMaEIXU9UndusHacjONzeFHstDpw834= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=RDPLo44s; arc=none smtp.client-ip=91.218.175.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="RDPLo44s" 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> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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 */