From a72838da9704fa428d2fa7a70a0fe27b0c97ec3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20S=C3=A1?= Date: Thu, 2 Oct 2025 16:09:03 +0100 Subject: [PATCH] iio: adc: adrv9002: fix frequency hopping table configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix multiple issues in the frequency hopping bin table write function: - Correct typo "bellow" to "below" in comment - Fix off-by-one error in entry bounds check (should be >= not >) - Use correct rx20_if variable for rx2OffsetFrequencyHz instead of rx10_if - Use correct rx2_gain variable for rx2GainIndex instead of rx1_gain These fixes ensure proper configuration of RX2 channel parameters and prevent potential buffer overflow when the entry index equals max_sz. Signed-off-by: Nuno Sá --- drivers/iio/adc/navassa/adrv9002.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/navassa/adrv9002.c b/drivers/iio/adc/navassa/adrv9002.c index 5966a8768a29b7..591c1cb62e7c87 100644 --- a/drivers/iio/adc/navassa/adrv9002.c +++ b/drivers/iio/adc/navassa/adrv9002.c @@ -4275,7 +4275,7 @@ static ssize_t adrv9002_fh_bin_table_write(struct adrv9002_rf_phy *phy, char *bu return -ENOMEM; memcpy(tbl->bin_table, buf, count); - /* The bellow is always safe as @bin_table is bigger (by 1 byte) than the bin attribute */ + /* The below is always safe as @bin_table is bigger (by 1 byte) than the bin attribute */ tbl->bin_table[count] = '\0'; max_sz = ARRAY_SIZE(tbl->hop_tbl); @@ -4301,7 +4301,7 @@ static ssize_t adrv9002_fh_bin_table_write(struct adrv9002_rf_phy *phy, char *bu return -EINVAL; } - if (entry > max_sz) { + if (entry >= max_sz) { dev_err(&phy->spi->dev, "Hop:%d table:%d too big:%d\n", hop, table, entry); return -EINVAL; } @@ -4315,10 +4315,10 @@ static ssize_t adrv9002_fh_bin_table_write(struct adrv9002_rf_phy *phy, char *bu tbl->hop_tbl[entry].hopFrequencyHz = lo; tbl->hop_tbl[entry].rx1OffsetFrequencyHz = rx10_if; - tbl->hop_tbl[entry].rx2OffsetFrequencyHz = rx10_if; + tbl->hop_tbl[entry].rx2OffsetFrequencyHz = rx20_if; tbl->hop_tbl[entry].rx1GainIndex = rx1_gain; tbl->hop_tbl[entry].tx1Attenuation_fifthdB = tx1_atten; - tbl->hop_tbl[entry].rx2GainIndex = rx1_gain; + tbl->hop_tbl[entry].rx2GainIndex = rx2_gain; tbl->hop_tbl[entry].tx2Attenuation_fifthdB = tx2_atten; entry++; }