Skip to content

Commit ee97159

Browse files
Michael Hennerichnunojsa
authored andcommitted
iio: jesd204: axi_adxcvr: Add access checks for eye_data and PRBS attributes
Add validation to prevent reading uninitialized eye_data and PRBS attributes: - eye_data binary attribute: Check if enable is written and lane != -1 - eyescan_info: Check if enable is written and lane != -1 - prbs_error_counters: Check if prbs_select was written with non-zero value - prbs_status: Check if prbs_select was written with non-zero value Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
1 parent a7ce665 commit ee97159

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

drivers/iio/jesd204/axi_adxcvr.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,16 @@ static ssize_t adxcvr_prbs_error_counter_show(struct device *dev,
310310
char *buf)
311311
{
312312
struct adxcvr_state *st = dev_get_drvdata(dev);
313-
unsigned int count;
313+
unsigned int count, val;
314314
ssize_t len = 0;
315315
int i, ret;
316316

317317
guard(mutex)(&st->mutex);
318+
319+
/* Check if prbs_select was written with non-zero value */
320+
val = adxcvr_read(st, ADXCVR_REG_REG_PRBS_CNTRL);
321+
if ((val & 0xF) == 0)
322+
return -ENODATA;
318323
for (i = 0; i < st->num_lanes; i++) {
319324
ret = xilinx_xcvr_prbs_err_cnt_get(&st->xcvr,
320325
ADXCVR_DRP_PORT_CHANNEL(i), &count);
@@ -364,6 +369,12 @@ static ssize_t adxcvr_prbs_status_show(struct device *dev,
364369
const char *status;
365370

366371
guard(mutex)(&st->mutex);
372+
373+
/* Check if prbs_select was written with non-zero value */
374+
val = adxcvr_read(st, ADXCVR_REG_REG_PRBS_CNTRL);
375+
if ((val & 0xF) == 0)
376+
return -ENODATA;
377+
367378
val = adxcvr_read(st, ADXCVR_REG_REG_PRBS_STATUS);
368379

369380
if (ADXCVR_PRBS_LOCKED(val))

drivers/iio/jesd204/axi_adxcvr_eyescan.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ adxcvr_eyescan_bin_read(struct file *filp, struct kobject *kobj,
187187
dev = container_of(kobj, struct device, kobj);
188188
st = dev_get_drvdata(dev);
189189

190+
/* Check if eye scan is enabled and lane is set */
191+
if (st->eye->lane == -1)
192+
return -ENODATA;
193+
190194
if (unlikely(off >= st->eye->bin.size))
191195
return 0;
192196
if ((off + count) > st->eye->bin.size)
@@ -334,6 +338,10 @@ static ssize_t adxcvr_eyescan_info_read(struct device *dev,
334338
u32 hsize;
335339
int ret;
336340

341+
/* Check if eye scan is enabled and lane is set */
342+
if (st->eye->lane == -1)
343+
return -ENODATA;
344+
337345
ret = adxcvr_get_eyescan_es_hsize(st, &hsize);
338346
if (ret < 0)
339347
return ret;

0 commit comments

Comments
 (0)