mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-06 17:35:20 +02:00
iio: adc: ad7124: fix config comparison
commit2f6b92d0f6
upstream. The ad7124_find_similar_live_cfg() computes the compare size by substracting the address of the cfg struct from the address of the live field. Because the live field is the first field in the struct, the result is 0. Also, the memcmp() call is made from the start of the cfg struct, which includes the live and cfg_slot fields, which are not relevant for the comparison. Fix by grouping the relevant fields with struct_group() and use the size of the group to compute the compare size; make the memcmp() call from the address of the group. Fixes:7b8d045e49
("iio: adc: ad7124: allow more than 8 channels") Signed-off-by: Dumitru Ceclan <dumitru.ceclan@analog.com> Reviewed-by: Nuno Sa <nuno.sa@analog.com> Link: https://patch.msgid.link/20240731-ad7124-fix-v1-2-46a76aa4b9be@analog.com Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ecc8e1bcac
commit
fb5d58f238
|
@ -146,15 +146,18 @@ struct ad7124_chip_info {
|
||||||
struct ad7124_channel_config {
|
struct ad7124_channel_config {
|
||||||
bool live;
|
bool live;
|
||||||
unsigned int cfg_slot;
|
unsigned int cfg_slot;
|
||||||
enum ad7124_ref_sel refsel;
|
/* Following fields are used to compare equality. */
|
||||||
bool bipolar;
|
struct_group(config_props,
|
||||||
bool buf_positive;
|
enum ad7124_ref_sel refsel;
|
||||||
bool buf_negative;
|
bool bipolar;
|
||||||
unsigned int vref_mv;
|
bool buf_positive;
|
||||||
unsigned int pga_bits;
|
bool buf_negative;
|
||||||
unsigned int odr;
|
unsigned int vref_mv;
|
||||||
unsigned int odr_sel_bits;
|
unsigned int pga_bits;
|
||||||
unsigned int filter_type;
|
unsigned int odr;
|
||||||
|
unsigned int odr_sel_bits;
|
||||||
|
unsigned int filter_type;
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ad7124_channel {
|
struct ad7124_channel {
|
||||||
|
@ -333,11 +336,12 @@ static struct ad7124_channel_config *ad7124_find_similar_live_cfg(struct ad7124_
|
||||||
ptrdiff_t cmp_size;
|
ptrdiff_t cmp_size;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
cmp_size = (u8 *)&cfg->live - (u8 *)cfg;
|
cmp_size = sizeof_field(struct ad7124_channel_config, config_props);
|
||||||
for (i = 0; i < st->num_channels; i++) {
|
for (i = 0; i < st->num_channels; i++) {
|
||||||
cfg_aux = &st->channels[i].cfg;
|
cfg_aux = &st->channels[i].cfg;
|
||||||
|
|
||||||
if (cfg_aux->live && !memcmp(cfg, cfg_aux, cmp_size))
|
if (cfg_aux->live &&
|
||||||
|
!memcmp(&cfg->config_props, &cfg_aux->config_props, cmp_size))
|
||||||
return cfg_aux;
|
return cfg_aux;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user