[PATCH v7 06/18] iio: adc: at91-sama5d2_adc: add condition to validate calibration data
From: Varshini Rajendran
Date: Wed Dec 02 2026 - 02:05:57 EST
Add additional condition to validate the calibration data read from the
NVMEM cell using the TAG of the packet.
Signed-off-by: Varshini Rajendran <varshini.rajendran@xxxxxxxxxxxxx>
---
drivers/iio/adc/at91-sama5d2_adc.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
index 24746a916be5..01132aaf6dca 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -445,6 +445,9 @@ static const struct at91_adc_reg_layout sama7g5_layout = {
#define at91_adc_writel(st, reg, val) \
writel_relaxed(val, (st)->base + (st)->soc_info.platform->layout->reg)
+/* Temperature calibration tag "ACST" in ASCII */
+#define AT91_TEMP_CALIB_TAG_ACST 0x41435354
+
/**
* struct at91_adc_temp_calib_layout - temperature calibration packet layout
* @tag_idx: index of Packet tag in the NVMEM cell buffer
@@ -2297,7 +2300,8 @@ static int at91_adc_temp_sensor_init(struct at91_adc_state *st,
return dev_err_probe(dev, PTR_ERR(buf),
"Failed to read calibration data!\n");
- if (len < layout->min_len * sizeof(*buf)) {
+ if (len < layout->min_len * sizeof(*buf) ||
+ buf[layout->tag_idx] != AT91_TEMP_CALIB_TAG_ACST) {
dev_err(dev, "Invalid calibration data!\n");
return -EINVAL;
}
--
2.43.0