public inbox for alsa-devel@alsa-project.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: alsa-devel@alsa-project.org, clemens@ladisch.de
Subject: Re: [PATCH 1/8] ALSA: control: change type from long due to the definition of sizeof operator
Date: Wed, 11 Feb 2015 12:53:59 +0100	[thread overview]
Message-ID: <s5h7fvopstk.wl-tiwai@suse.de> (raw)
In-Reply-To: <1423651052-19593-2-git-send-email-o-takashi@sakamocchi.jp>

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@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
> 

  reply	other threads:[~2015-02-11 11:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-11 10:37 [PATCH 0/8] ALSA: control: refactoring core codes Takashi Sakamoto
2015-02-11 10:37 ` [PATCH 1/8] ALSA: control: change type from long due to the definition of sizeof operator Takashi Sakamoto
2015-02-11 11:53   ` Takashi Iwai [this message]
2015-02-11 10:37 ` [PATCH 2/8] ALSA: control: obsolete switch statement with const value table Takashi Sakamoto
2015-02-11 10:51   ` Lars-Peter Clausen
2015-02-11 11:27     ` Takashi Sakamoto
2015-02-11 10:37 ` [PATCH 3/8] ALSA: control: gathering evaluations to access Takashi Sakamoto
2015-02-11 10:37 ` [PATCH 4/8] ALSA: control: add a comment about locking values after creating Takashi Sakamoto
2015-02-11 10:37 ` [PATCH 5/8] ALSA: control: rename loop index to i Takashi Sakamoto
2015-02-11 11:55   ` Takashi Iwai
2015-02-12 12:50     ` Takashi Sakamoto
2015-02-11 10:37 ` [PATCH 6/8] ALSA: control: fix over 80 characters lines Takashi Sakamoto
2015-02-11 12:01   ` Takashi Iwai
2015-02-12 12:47     ` Takashi Sakamoto
2015-02-12 12:54       ` Jaroslav Kysela
2015-02-11 10:37 ` [PATCH 7/8] ALSA: control: rename to appropriate macro name Takashi Sakamoto
2015-02-11 10:37 ` [PATCH 8/8] ALSA: control: arrange snd_ctl_new() as a local function Takashi Sakamoto
2015-02-11 12:49   ` Lars-Peter Clausen
2015-02-11 13:04     ` Takashi Iwai
2015-02-12 12:45       ` Takashi Sakamoto
2015-02-12 12:57         ` Takashi Iwai
2015-02-11 13:19 ` [PATCH 0/8] ALSA: control: refactoring core codes Takashi Iwai
2015-02-12 12:38   ` Takashi Sakamoto
2015-03-05 15:43 ` [PATCH 0/2][RFC] ALSA: core: optimizations for creating new controls Takashi Sakamoto
2015-03-05 15:43   ` [PATCH 1/2] ALSA: core: use precomputed table to check userspace control params Takashi Sakamoto
2015-03-05 15:43   ` [PATCH 2/2] ALSA: core: reduce stack usage related to snd_ctl_new() Takashi Sakamoto
2015-03-05 15:58   ` [PATCH 0/2][RFC] ALSA: core: optimizations for creating new controls Takashi Iwai
2015-03-07  4:57     ` Takashi Sakamoto
2015-03-10 13:13   ` [PATCH 0/2 v2] " Takashi Sakamoto
2015-03-10 13:13     ` [PATCH 1/2] ALSA: core: use precomputed table to check userspace control params Takashi Sakamoto
2015-03-10 13:13     ` [PATCH 2/2] ALSA: core: reduce stack usage related to snd_ctl_new() Takashi Sakamoto
2015-03-10 14:44     ` [PATCH 0/2 v2] ALSA: core: optimizations for creating new controls Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5h7fvopstk.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=o-takashi@sakamocchi.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox