Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 3 additions & 37 deletions drivers/iio/adc/ad7124.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* AD7124 SPI ADC driver
Expand Down Expand Up @@ -302,40 +302,14 @@

switch (st->channels[channel].cfg.filter_type) {
case AD7124_SINC3_FILTER:
return DIV_ROUND_CLOSEST(fadc * 230, 1000);
return DIV_ROUND_CLOSEST(fadc * 272, 1000);
case AD7124_SINC4_FILTER:
return DIV_ROUND_CLOSEST(fadc * 262, 1000);
return DIV_ROUND_CLOSEST(fadc * 230, 1000);
default:
return -EINVAL;
}
}

static void ad7124_set_3db_filter_freq(struct ad7124_state *st, unsigned int channel,
unsigned int freq)
{
unsigned int sinc4_3db_odr;
unsigned int sinc3_3db_odr;
unsigned int new_filter;
unsigned int new_odr;

sinc4_3db_odr = DIV_ROUND_CLOSEST(freq * 1000, 230);
sinc3_3db_odr = DIV_ROUND_CLOSEST(freq * 1000, 262);

if (sinc4_3db_odr > sinc3_3db_odr) {
new_filter = AD7124_SINC3_FILTER;
new_odr = sinc4_3db_odr;
} else {
new_filter = AD7124_SINC4_FILTER;
new_odr = sinc3_3db_odr;
}

if (new_odr != st->channels[channel].cfg.odr)
st->channels[channel].cfg.live = false;

st->channels[channel].cfg.filter_type = new_filter;
st->channels[channel].cfg.odr = new_odr;
}

static struct ad7124_channel_config *ad7124_find_similar_live_cfg(struct ad7124_state *st,
struct ad7124_channel_config *cfg)
{
Expand Down Expand Up @@ -740,16 +714,8 @@

st->channels[chan->address].cfg.pga_bits = res;
break;
case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
if (val2 != 0) {
ret = -EINVAL;
break;
}

ad7124_set_3db_filter_freq(st, chan->address, val);
break;
default:
ret = -EINVAL;
ret = -EINVAL;
}

mutex_unlock(&st->cfgs_lock);
Expand Down Expand Up @@ -895,7 +861,7 @@

static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan_spec *chan)
{
struct device *dev = &st->sd.spi->dev;

Check warning on line 864 in drivers/iio/adc/ad7124.c

View workflow job for this annotation

GitHub Actions / build_llvm_x86_64 / build

clang_analyzer: Value stored to 'dev' during its initialization is never read [deadcode.DeadStores] 864 | struct device *dev = &st->sd.spi->dev; | ^~~ ~~~~~~~~~~~~~~~~
struct ad7124_channel *ch = &st->channels[chan->channel];
int ret;

Expand Down Expand Up @@ -1131,7 +1097,7 @@
},
};

chan[num_channels] = (struct iio_chan_spec) {

Check warning on line 1100 in drivers/iio/adc/ad7124.c

View workflow job for this annotation

GitHub Actions / build_gcc_arm / build

smatch: potentially one past the end of array 'chan[num_channels]'

Check warning on line 1100 in drivers/iio/adc/ad7124.c

View workflow job for this annotation

GitHub Actions / build_gcc_arm / build

smatch: potentially one past the end of array 'chan[num_channels]'
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET) |
Expand Down Expand Up @@ -1209,7 +1175,7 @@

static int __ad7124_calibrate_all(struct ad7124_state *st, struct iio_dev *indio_dev)
{
struct device *dev = &st->sd.spi->dev;

Check warning on line 1178 in drivers/iio/adc/ad7124.c

View workflow job for this annotation

GitHub Actions / build_llvm_x86_64 / build

clang_analyzer: Value stored to 'dev' during its initialization is never read [deadcode.DeadStores] 1178 | struct device *dev = &st->sd.spi->dev; | ^~~ ~~~~~~~~~~~~~~~~
int ret, i;

for (i = 0; i < st->num_channels; i++) {
Expand Down
2 changes: 2 additions & 0 deletions drivers/iio/adc/ad7944.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
const struct ad7944_timing_spec *timing_spec;
u32 max_sample_rate_hz;
const struct iio_chan_spec channels[2];
const struct iio_chan_spec offload_channels[1];

Check warning on line 116 in drivers/iio/adc/ad7944.c

View workflow job for this annotation

GitHub Actions / checks / checks

coccicheck: 28-44 WARNING use flexible-array member instead (https //www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
};

/* get number of bytes for SPI xfer */
Expand Down Expand Up @@ -382,6 +382,8 @@

if (chan->scan_type.sign == 's')
*val = sign_extend32(*val, chan->scan_type.realbits - 1);
else
*val &= GENMASK(chan->scan_type.realbits - 1, 0);

return IIO_VAL_INT;
}
Expand Down Expand Up @@ -635,7 +637,7 @@
* Scan mask is needed since we always have to read all devices in the
* chain in one SPI transfer.
*/
scan_masks[0] = GENMASK(n_chain_dev - 1, 0);

Check warning on line 640 in drivers/iio/adc/ad7944.c

View workflow job for this annotation

GitHub Actions / build_llvm_x86_64 / build

clang_analyzer: Right shift by '32' overflows the capacity of 'unsigned long' [core.BitwiseShift] 640 | scan_masks[0] = GENMASK(n_chain_dev - 1, 0); | ^

*chain_scan_masks = scan_masks;

Expand Down Expand Up @@ -807,7 +809,7 @@
/* Fall back to low speed usage when no SPI offload available. */
if (ret == -ENODEV) {
if (adc->spi_mode == AD7944_SPI_MODE_CHAIN) {
indio_dev->available_scan_masks = chain_scan_masks;

Check warning on line 812 in drivers/iio/adc/ad7944.c

View workflow job for this annotation

GitHub Actions / build_llvm_x86_64 / build

clang_analyzer: Assigned value is garbage or undefined [core.uninitialized.Assign] 812 | indio_dev->available_scan_masks = chain_scan_masks; | ^ ~~~~~~~~~~~~~~~~
indio_dev->channels = chain_chan;
indio_dev->num_channels = n_chain_dev + 1;
} else {
Expand Down
6 changes: 6 additions & 0 deletions drivers/iio/dac/ad3552r.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
if (ret < 0)
return ret;

reg &= ~mask;

Check warning on line 118 in drivers/iio/dac/ad3552r.c

View workflow job for this annotation

GitHub Actions / build_gcc_arm / build

gcc_fanalayzer: use of uninitialized value 'reg' [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 118 | reg &= ~mask; | ^~ 'ad3552r_probe': events 1-3 | | 617 | static int ad3552r_probe(struct spi_device *spi) | | ^~~~~~~~~~~~~ | | | | | (1) entry to 'ad3552r_probe' |...... | 624 | if (!indio_dev) | | ~ | | | | | (2) following 'false' branch (when 'indio_dev' is non-NULL)... |...... | 627 | dac = iio_priv(indio_dev); | | ~ | | | | | (3) inlined call to 'iio_priv' from 'ad3552r_probe' | +--> 'iio_priv': event 4 | |./include/linux/iio/iio.h:814:25: | 814 | return indio_dev->priv; | | ~~~~~~~~~^~~~~~ | | | | | (4) ...to here | <------+ | 'ad3552r_probe': event 5 | |drivers/iio/dac/ad3552r.c:630:12: | 630 | if (!dac->model_data) | | ^ | | | | | (5) following 'false' branch... | 'ad3552r_probe': event 6 | |./include/linux/mutex.h:66:9: | 66 | __mutex_init((mutex), #mutex, &__key); \ | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (6) ...to here

Check warning on line 118 in drivers/iio/dac/ad3552r.c

View workflow job for this annotation

GitHub Actions / build_gcc_arm / build

gcc_fanalayzer: use of uninitialized value 'reg' [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 118 | reg &= ~mask; | ^~ 'ad3552r_init': events 1-2 | | 578 | static int ad3552r_init(struct ad3552r_desc *dac) | | ^~~~~~~~~~~~ | | | | | (1) entry to 'ad3552r_init' |...... | 583 | err = ad3552r_reset(dac); | | ~~~~~~~~~~~~~~~~~~ | | | | | (2) calling 'ad3552r_reset' from 'ad3552r_init' | +--> 'ad3552r_reset': events 3-8 | | 362 | static int ad3552r_reset(struct ad3552r_desc *dac) | | ^~~~~~~~~~~~~ | | | | | (3) entry to 'ad3552r_reset' |...... | 370 | if (IS_ERR(dac->gpio_reset)) | | ~ | | | | | (4) following 'false' branch... |...... | 374 | if (dac->gpio_reset) { | | ~ | | | | | (5) ...to here | | (6) following 'false' branch... |...... | 380 | ret = ad3552r_update_reg_field(dac, | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (7) ...to here | | (8) calling 'ad3552r_update_reg_field' from 'ad3552r_reset' | 381 | AD3552R_REG_ADDR_INTERFACE_CONFIG_A, | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 382 | AD3552R_MASK_SOFTWARE_RESET, | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 383 | AD3552R_MASK_SOFTWARE_RESET); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | +--> 'ad3552r_update_reg_field': events 9-12 | | 108 | static int ad3552r_update_reg_field(struct ad3552r_desc *dac, u8 addr, u16 mask, | | ^~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (9) entry to 'ad3552r_update_reg_field' |...... | 112 | u16 reg; | | ~~~ | | | | | (10) region created on stack here | | (11) capacity: 2 bytes | 113 | | 114 | ret = ad3552r_read_reg(dac, addr, &reg); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (12) calling 'ad3552r_read_reg' from 'ad3552r_update_reg_field' | +--> 'ad3552r_read_reg': events 13-14 | | 88 | static int ad3552r_read_reg(struct ad3552r_desc *dac, u8 addr, u16 *val) | | ^~~~~~~~~~~~~~~~ | | | | | (13) entry to 'ad3552r_read_reg' |...... | 93 | reg_len = _ad3552r_reg_len(addr); | | ~~~~~~~~~~~~~~~~~~~~~~ | | | | | (14) calling '_ad3552r_reg_len' from 'ad3552r_read_reg' | +--> '_ad3552r_reg_len': events 15-16 | | 32 | static u8 _ad3552r_reg_len(u8 addr) | | ^~~~~~~~~~~~~~~~ | | | | | (15) entry to '_ad3552r_reg_len' | 33 | { | 34 | switch (addr) { | | ~~~~~~ | | | | | (16) following 'default:' branch... | '_ad3552r_reg_len': event 17 | |cc1: | (17): ...to here | '_ad3552r_reg_len': event 18 | |cc1: | (18): calling '_ad3552r_reg_len.part.0' from '_ad3552r_reg_len' | +--> '_ad3552r_reg_len.part.0': events 19-22 | | 32 | static u8 _ad3552r_reg_len(u8 addr) | | ^~~~~~~~~~~~~~~~ | | | | | (19) entry to '_ad3552r_reg_len.part.0' |...... | 46 | if (addr > AD3552R_REG_ADDR_HW_LDAC_24B) | | ~ | | | | | (20) following 'false' branch (when 'addr <= 55')... | 47 | return 3; | 48 | if (addr > AD3552R_REG_ADDR_HW_LDAC_16B) | | ~ | | | | | (21) ...to here | | (22) following 'false' branch (when 'addr <= 40')... | '_ad3552r_reg_len.part.0': event 23 | |cc1: | (23): ...to here | <------+ | '_ad3552r_reg_len': event 24 | |cc1: | (24): returning to '_ad3552r_reg_len' from '_ad3552r_reg_len.part.0' | <------+ | 'ad3552r_read_reg': events 25-26 | | 93 | reg_len = _ad3552r_reg_len(addr); | | ^~~~~~~~~~~~~~~~~~~~~~ | | | | | (25) returning to 'ad3552r_read_reg' from '_ad3552r_reg_len' | 94 | err = ad3552r_transfer(dac, addr, reg_len, buf, true); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (26) calling 'ad3552r_transfer' from 'ad3552r_read_reg' | +--> 'ad3552r_transfer': events 27-31 | | 55 | static int ad3552r_transfer(struct ad3552r_desc *dac, u8 addr, u32 len, | | ^~~~~~~~~~~~~~~~ | | | | | (27) entry to 'ad3552r_transfer' |...... | 62 | buf[0] |= is_read ? AD3552R_READ_BIT : 0; | | ~~ | | | | | (28) following 'true' branch (when 'is_read != 0')... | | (29) ...to here | 63 | if (is_read) | | ~ | | | | | (30) following 'true' branch (when 'is_read != 0')... | 64 | return spi_write_then_read(dac->spi, buf, 1, data, len); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (31) ...to here | <------+ | 'ad3552r_read_reg': events 32-33 | | 94 | err = ad3552r_transfer(dac, addr, reg_len, buf, true); | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (

Check warning on line 118 in drivers/iio/dac/ad3552r.c

View workflow job for this annotation

GitHub Actions / build_llvm_x86_64 / build

clang_analyzer: The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage [core.uninitialized.Assign] 118 | reg &= ~mask; | ^
reg |= val;

return ad3552r_write_reg(dac, addr, reg);
Expand Down Expand Up @@ -158,7 +158,7 @@
mutex_unlock(&dac->lock);
if (err < 0)
return err;
*val = tmp_val;

Check warning on line 161 in drivers/iio/dac/ad3552r.c

View workflow job for this annotation

GitHub Actions / build_llvm_x86_64 / build

clang_analyzer: Assigned value is garbage or undefined [core.uninitialized.Assign] 161 | *val = tmp_val; | ^ ~~~~~~~
return IIO_VAL_INT;
case IIO_CHAN_INFO_ENABLE:
mutex_lock(&dac->lock);
Expand All @@ -167,7 +167,7 @@
mutex_unlock(&dac->lock);
if (err < 0)
return err;
*val = !((tmp_val & AD3552R_MASK_CH_DAC_POWERDOWN(ch)) >>

Check warning on line 170 in drivers/iio/dac/ad3552r.c

View workflow job for this annotation

GitHub Actions / build_llvm_x86_64 / build

clang_analyzer: The left operand of '&' is a garbage value [core.UndefinedBinaryOperatorResult] 170 | *val = !((tmp_val & AD3552R_MASK_CH_DAC_POWERDOWN(ch)) >> | ~~~~~~~ ^
__ffs(AD3552R_MASK_CH_DAC_POWERDOWN(ch)));
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
Expand Down Expand Up @@ -325,7 +325,7 @@
if (err < 0)
return err;

if (val1 != val)

Check warning on line 328 in drivers/iio/dac/ad3552r.c

View workflow job for this annotation

GitHub Actions / build_gcc_arm / build

gcc_fanalayzer: use of uninitialized value 'val' [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 328 | if (val1 != val) | ~~~~~^~~~~~ 'ad3552r_probe': events 1-3 | | 617 | static int ad3552r_probe(struct spi_device *spi) | | ^~~~~~~~~~~~~ | | | | | (1) entry to 'ad3552r_probe' |...... | 624 | if (!indio_dev) | | ~ | | | | | (2) following 'false' branch (when 'indio_dev' is non-NULL)... |...... | 627 | dac = iio_priv(indio_dev); | | ~ | | | | | (3) inlined call to 'iio_priv' from 'ad3552r_probe' | +--> 'iio_priv': event 4 | |./include/linux/iio/iio.h:814:25: | 814 | return indio_dev->priv; | | ~~~~~~~~~^~~~~~ | | | | | (4) ...to here | <------+ | 'ad3552r_probe': event 5 | |drivers/iio/dac/ad3552r.c:630:12: | 630 | if (!dac->model_data) | | ^ | | | | | (5) following 'false' branch... | 'ad3552r_probe': event 6 | |./include/linux/mutex.h:66:9: | 66 | __mutex_init((mutex), #mutex, &__key); \ | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (6) ...to here

Check warning on line 328 in drivers/iio/dac/ad3552r.c

View workflow job for this annotation

GitHub Actions / build_llvm_x86_64 / build

clang_analyzer: The right operand of '!=' is a garbage value [core.UndefinedBinaryOperatorResult] 328 | if (val1 != val) | ^
return -ENODEV;

err = ad3552r_write_reg(dac, AD3552R_REG_ADDR_SCRATCH_PAD, val2);
Expand Down Expand Up @@ -410,6 +410,12 @@
return ret;
}

/* Clear reset error flag, see ad3552r manual, rev B table 38. */
ret = ad3552r_write_reg(dac, AD3552R_REG_ADDR_ERR_STATUS,
AD3552R_MASK_RESET_STATUS);
if (ret)
return ret;

return ad3552r_update_reg_field(dac,
AD3552R_REG_ADDR_INTERFACE_CONFIG_A,
AD3552R_MASK_ADDR_ASCENSION,
Expand Down
Loading