Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: dac: adi-axi-dac: add cntrl chan check

Add validity check on CNTRL_X channels (valid as 0 to 15).

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
Link: https://patch.msgid.link/20250409-wip-bl-ad3552r-fixes-v5-1-fb429c3a6515@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Angelo Dureghello and committed by
Jonathan Cameron
02903563 b1ba4326

+24
+24
drivers/iio/dac/adi-axi-dac.c
··· 84 84 #define AXI_DAC_CHAN_CNTRL_7_REG(c) (0x0418 + (c) * 0x40) 85 85 #define AXI_DAC_CHAN_CNTRL_7_DATA_SEL GENMASK(3, 0) 86 86 87 + #define AXI_DAC_CHAN_CNTRL_MAX 15 87 88 #define AXI_DAC_RD_ADDR(x) (BIT(7) | (x)) 88 89 89 90 /* 360 degrees in rad */ ··· 187 186 u32 reg, raw; 188 187 int ret; 189 188 189 + if (chan > AXI_DAC_CHAN_CNTRL_MAX) 190 + return -EINVAL; 191 + 190 192 if (!st->dac_clk) { 191 193 dev_err(st->dev, "Sampling rate is 0...\n"); 192 194 return -EINVAL; ··· 234 230 int ret, vals[2]; 235 231 u32 reg, raw; 236 232 233 + if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX) 234 + return -EINVAL; 235 + 237 236 if (tone_2) 238 237 reg = AXI_DAC_CHAN_CNTRL_3_REG(chan->channel); 239 238 else ··· 271 264 u32 reg, raw, phase; 272 265 int ret, vals[2]; 273 266 267 + if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX) 268 + return -EINVAL; 269 + 274 270 if (tone_2) 275 271 reg = AXI_DAC_CHAN_CNTRL_4_REG(chan->channel); 276 272 else ··· 300 290 u32 reg; 301 291 u16 raw; 302 292 int ret; 293 + 294 + if (chan > AXI_DAC_CHAN_CNTRL_MAX) 295 + return -EINVAL; 303 296 304 297 if (!sample_rate || freq > sample_rate / 2) { 305 298 dev_err(st->dev, "Invalid frequency(%u) dac_clk(%llu)\n", ··· 355 342 u32 raw = 0, reg; 356 343 int ret; 357 344 345 + if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX) 346 + return -EINVAL; 347 + 358 348 ret = iio_str_to_fixpoint(buf, 100000, &integer, &frac); 359 349 if (ret) 360 350 return ret; ··· 400 384 int integer, frac, phase; 401 385 u32 raw, reg; 402 386 int ret; 387 + 388 + if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX) 389 + return -EINVAL; 403 390 404 391 ret = iio_str_to_fixpoint(buf, 100000, &integer, &frac); 405 392 if (ret) ··· 512 493 { 513 494 struct axi_dac_state *st = iio_backend_get_priv(back); 514 495 496 + if (chan > AXI_DAC_CHAN_CNTRL_MAX) 497 + return -EINVAL; 498 + 515 499 switch (data) { 516 500 case IIO_BACKEND_INTERNAL_CONTINUOUS_WAVE: 517 501 return regmap_update_bits(st->regmap, ··· 543 521 unsigned int freq; 544 522 int ret, tone; 545 523 524 + if (chan > AXI_DAC_CHAN_CNTRL_MAX) 525 + return -EINVAL; 546 526 if (!sample_rate) 547 527 return -EINVAL; 548 528 if (st->reg_config & AXI_DAC_CONFIG_DDS_DISABLE)