ASoC: core: remove redundunt address operation for array type variable
PATCH 1/1 ASoC: core: remove redundunt address operation for array type variable
The type of 'struct snd_ctl_elem_value.value.bytes.data' is 'unsigned char[512]'. In C language specification, address operation (&) for this type is just ignored, therefore:
struct snd_ctl_elem_value elem_value;printf("%p\n", elem_value.value.bytes.data);printf("%p\n", &elem_value.value.bytes.data);
These two evaluation have the same value, a pointer to the first element of the array.
This kind of address operation is not good for readers, because it easily brings confusions as an address operations to pointers. For example,
struct snd_kcontrol_new template;printf("%p\n", template.name);printf("%p\n", &template.name);
These two evaluation have the different value. The former is 'unsigned char *', while the latter is 'unsigned char **'.
This commit removes redundant address operation for array type variable to avoid misreading in reader side.
--- sound/soc/soc-ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/soc-ops.c +2 -2
@@ -658,11 +658,11 @@ int snd_soc_bytes_get(struct snd_kcontrol *kcontrol, ucontrol->value.bytes.data[0 ] &= ~params->mask;break ;case 2 : - ((u16 *)(&ucontrol->value.bytes.data))[0 ] + ((u16 *)ucontrol->value.bytes.data)[0 ] &=cpu_to_be16 (~params->mask);break ;case 4 : - ((u32 *)(&ucontrol->value.bytes.data))[0 ] + ((u32 *)ucontrol->value.bytes.data)[0 ] &=cpu_to_be32 (~params->mask);break ;default :
Signature · 1 line
2.9.3
Mark Brown
maintainerQuoted 5 lines · Takashi Sakamoto
These two evaluation have the same value, a pointer to the first element of the array.
This kind of address operation is not good for readers, because it easily brings confusions as an address operations to pointers. For example,
This is done explicitly for clarity, in order to make it clear that the value is a pointer rather than being (say) an integer. The value is the same as you say but that's only clear if the reader realizes that data is an array. If I were clarifying this I'd change to explicitly take the address of the first element of the array rather than the array as a whole.
Quoted 2 lines
Cc Takashi Sakamoto <[email protected]>Fixes f831b055ecec ("ASoC: core: Add support for masking out parts of coefficient blocks")
This is a style change rather than a fix.