[alsa-devel] [PATCH] 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.
Cc: Takashi Sakamoto o-takashi@sakamocchi.jp Fixes: f831b055ecec ("ASoC: core: Add support for masking out parts of coefficient blocks") Signed-off-by: Takashi Sakamoto takashi.sakamoto@miraclelinux.com --- sound/soc/soc-ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index 500f98c..76b199b 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -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:
On Mon, Mar 13, 2017 at 12:07:43PM +0900, Takashi Sakamoto wrote:
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.
Cc: Takashi Sakamoto o-takashi@sakamocchi.jp Fixes: f831b055ecec ("ASoC: core: Add support for masking out parts of coefficient blocks")
This is a style change rather than a fix.
participants (2)
-
Mark Brown
-
Takashi Sakamoto