Skip to content

Commit e786cc2

Browse files
larsclausenjic23
authored andcommitted
staging:iio:ad7793: Implement stricter id checking
Instead of checking whether the id of the current device matches the id of any device supported by the driver, check whether it matches the id of the device which the driver was instantiated for. This makes sure that the driver is not accidentally instantiated for the wrong device. Signed-off-by: Lars-Peter Clausen <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 891c8bc commit e786cc2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/staging/iio/adc/ad7793.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@
102102
#define AD7795_CH_AIN1M_AIN1M 8 /* AIN1(-) - AIN1(-) */
103103

104104
/* ID Register Bit Designations (AD7793_REG_ID) */
105+
#define AD7785_ID 0xB
105106
#define AD7792_ID 0xA
106107
#define AD7793_ID 0xB
108+
#define AD7794_ID 0xF
107109
#define AD7795_ID 0xF
108110
#define AD7793_ID_MASK 0xF
109111

@@ -130,6 +132,7 @@
130132
*/
131133

132134
struct ad7793_chip_info {
135+
unsigned int id;
133136
const struct iio_chan_spec *channels;
134137
unsigned int num_channels;
135138
};
@@ -231,7 +234,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
231234

232235
id &= AD7793_ID_MASK;
233236

234-
if (!((id == AD7792_ID) || (id == AD7793_ID) || (id == AD7795_ID))) {
237+
if (id != st->chip_info->id) {
235238
dev_err(&st->sd.spi->dev, "device ID query failed\n");
236239
goto out;
237240
}
@@ -531,22 +534,27 @@ static DECLARE_AD7795_CHANNELS(ad7795, 24, 32);
531534

532535
static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
533536
[ID_AD7785] = {
537+
.id = AD7785_ID,
534538
.channels = ad7785_channels,
535539
.num_channels = ARRAY_SIZE(ad7785_channels),
536540
},
537541
[ID_AD7792] = {
542+
.id = AD7792_ID,
538543
.channels = ad7792_channels,
539544
.num_channels = ARRAY_SIZE(ad7792_channels),
540545
},
541546
[ID_AD7793] = {
547+
.id = AD7793_ID,
542548
.channels = ad7793_channels,
543549
.num_channels = ARRAY_SIZE(ad7793_channels),
544550
},
545551
[ID_AD7794] = {
552+
.id = AD7794_ID,
546553
.channels = ad7794_channels,
547554
.num_channels = ARRAY_SIZE(ad7794_channels),
548555
},
549556
[ID_AD7795] = {
557+
.id = AD7795_ID,
550558
.channels = ad7795_channels,
551559
.num_channels = ARRAY_SIZE(ad7795_channels),
552560
},

0 commit comments

Comments
 (0)