[alsa-devel] [PATCH 1/8] ALSA: control: change type from long due to the definition of sizeof operator
Takashi Iwai
tiwai at suse.de
Wed Feb 11 12:53:59 CET 2015
At Wed, 11 Feb 2015 19:37:25 +0900,
Takashi Sakamoto wrote:
>
> The sizeof() operator returns 'unsigned' value, while it's assigned to 'long'.
The type of sizeof() is size_t, which is unsigned long on Linux.
(Imagine the return value of sizeof() for an array over 4GB.)
Takashi
> And in this case, the value is not so large.
>
> This commit change the type of assigned value to 'unsigned int'. Additonally,
> rename local variable assigned to the value.
>
> Signed-off-by: Takashi Sakamoto <o-takashi at sakamocchi.jp>
> ---
> sound/core/control.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/sound/core/control.c b/sound/core/control.c
> index 35324a8..ea49abc 100644
> --- a/sound/core/control.c
> +++ b/sound/core/control.c
> @@ -1007,7 +1007,7 @@ struct user_element {
> struct snd_ctl_elem_info info;
> struct snd_card *card;
> void *elem_data; /* element data */
> - unsigned long elem_data_size; /* size of element data in bytes */
> + unsigned int elem_data_size; /* size of element data in bytes */
> void *tlv_data; /* TLV data */
> unsigned long tlv_data_size; /* TLV data size */
> void *priv_data; /* private data (like strings for enumerated type) */
> @@ -1164,7 +1164,7 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
> struct snd_card *card = file->card;
> struct snd_kcontrol kctl, *_kctl;
> unsigned int access;
> - long private_size;
> + unsigned int elem_data_size;
> struct user_element *ue;
> int idx, err;
>
> @@ -1204,42 +1204,42 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
> switch (info->type) {
> case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
> case SNDRV_CTL_ELEM_TYPE_INTEGER:
> - private_size = sizeof(long);
> + elem_data_size = sizeof(long);
> if (info->count > 128)
> return -EINVAL;
> break;
> case SNDRV_CTL_ELEM_TYPE_INTEGER64:
> - private_size = sizeof(long long);
> + elem_data_size = sizeof(long long);
> if (info->count > 64)
> return -EINVAL;
> break;
> case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
> - private_size = sizeof(unsigned int);
> + elem_data_size = sizeof(unsigned int);
> if (info->count > 128 || info->value.enumerated.items == 0)
> return -EINVAL;
> break;
> case SNDRV_CTL_ELEM_TYPE_BYTES:
> - private_size = sizeof(unsigned char);
> + elem_data_size = sizeof(unsigned char);
> if (info->count > 512)
> return -EINVAL;
> break;
> case SNDRV_CTL_ELEM_TYPE_IEC958:
> - private_size = sizeof(struct snd_aes_iec958);
> + elem_data_size = sizeof(struct snd_aes_iec958);
> if (info->count != 1)
> return -EINVAL;
> break;
> default:
> return -EINVAL;
> }
> - private_size *= info->count;
> - ue = kzalloc(sizeof(struct user_element) + private_size, GFP_KERNEL);
> + elem_data_size *= info->count;
> + ue = kzalloc(sizeof(struct user_element) + elem_data_size, GFP_KERNEL);
> if (ue == NULL)
> return -ENOMEM;
> ue->card = card;
> ue->info = *info;
> ue->info.access = 0;
> ue->elem_data = (char *)ue + sizeof(*ue);
> - ue->elem_data_size = private_size;
> + ue->elem_data_size = elem_data_size;
> if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) {
> err = snd_ctl_elem_init_enum_names(ue);
> if (err < 0) {
> --
> 2.1.0
>
More information about the Alsa-devel
mailing list