alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: seq: initialize whole fields of automatic variable with union type
@ 2016-08-30  0:11 Takashi Sakamoto
  2016-08-30  5:11 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Sakamoto @ 2016-08-30  0:11 UTC (permalink / raw)
  To: clemens, tiwai; +Cc: alsa-devel

Currently, automatic variable of 'union ioctl_arg' type is initialized
by designated initialization. Although, the actual effect is interpretation
of early element of int type and initialization of 'int pversion'.
Therefore the first field corresponding to int type is initialized to zero.
This is against my expectation to initialize whole fields.

This commit uses memset() to initialize the variable, instead of designated
initialization.

Fixes: 04a56dd8ed0d ('ALSA: seq: change ioctl command operation to get data in kernel space')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/core/seq/seq_clientmgr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c
index 286394b..fd50c38 100644
--- a/sound/core/seq/seq_clientmgr.c
+++ b/sound/core/seq/seq_clientmgr.c
@@ -2100,7 +2100,7 @@ static long snd_seq_ioctl(struct file *file, unsigned int cmd,
 		struct snd_seq_client_pool	client_pool;
 		struct snd_seq_remove_events	remove_events;
 		struct snd_seq_query_subs	query_subs;
-	} buf = {0};
+	} buf;
 	const struct ioctl_handler *handler;
 	unsigned long size;
 	int err;
@@ -2114,6 +2114,9 @@ static long snd_seq_ioctl(struct file *file, unsigned int cmd,
 	}
 	if (handler->cmd == 0)
 		return -ENOTTY;
+
+	memset(&buf, 0, sizeof(union ioctl_arg));
+
 	/*
 	 * All of ioctl commands for ALSA sequencer get an argument of size
 	 * within 13 bits. We can safely pick up the size from the command.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: seq: initialize whole fields of automatic variable with union type
  2016-08-30  0:11 [PATCH] ALSA: seq: initialize whole fields of automatic variable with union type Takashi Sakamoto
@ 2016-08-30  5:11 ` Takashi Iwai
  2016-08-30  6:34   ` Takashi Sakamoto
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2016-08-30  5:11 UTC (permalink / raw)
  To: Takashi Sakamoto; +Cc: alsa-devel, clemens

On Tue, 30 Aug 2016 02:11:54 +0200,
Takashi Sakamoto wrote:
> 
> Currently, automatic variable of 'union ioctl_arg' type is initialized
> by designated initialization. Although, the actual effect is interpretation
> of early element of int type and initialization of 'int pversion'.
> Therefore the first field corresponding to int type is initialized to zero.
> This is against my expectation to initialize whole fields.
> 
> This commit uses memset() to initialize the variable, instead of designated
> initialization.
> 
> Fixes: 04a56dd8ed0d ('ALSA: seq: change ioctl command operation to get data in kernel space')
> Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> ---
>  sound/core/seq/seq_clientmgr.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c
> index 286394b..fd50c38 100644
> --- a/sound/core/seq/seq_clientmgr.c
> +++ b/sound/core/seq/seq_clientmgr.c
> @@ -2100,7 +2100,7 @@ static long snd_seq_ioctl(struct file *file, unsigned int cmd,
>  		struct snd_seq_client_pool	client_pool;
>  		struct snd_seq_remove_events	remove_events;
>  		struct snd_seq_query_subs	query_subs;
> -	} buf = {0};
> +	} buf;
>  	const struct ioctl_handler *handler;
>  	unsigned long size;
>  	int err;
> @@ -2114,6 +2114,9 @@ static long snd_seq_ioctl(struct file *file, unsigned int cmd,
>  	}
>  	if (handler->cmd == 0)
>  		return -ENOTTY;
> +
> +	memset(&buf, 0, sizeof(union ioctl_arg));

The common practice is to pass sizeof(buf).


Takashi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: seq: initialize whole fields of automatic variable with union type
  2016-08-30  5:11 ` Takashi Iwai
@ 2016-08-30  6:34   ` Takashi Sakamoto
  0 siblings, 0 replies; 3+ messages in thread
From: Takashi Sakamoto @ 2016-08-30  6:34 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, clemens

On Aug 30 2016 14:11, Takashi Iwai wrote:
> On Tue, 30 Aug 2016 02:11:54 +0200,
> Takashi Sakamoto wrote:
>>
>> Currently, automatic variable of 'union ioctl_arg' type is initialized
>> by designated initialization. Although, the actual effect is interpretation
>> of early element of int type and initialization of 'int pversion'.
>> Therefore the first field corresponding to int type is initialized to zero.
>> This is against my expectation to initialize whole fields.
>>
>> This commit uses memset() to initialize the variable, instead of designated
>> initialization.
>>
>> Fixes: 04a56dd8ed0d ('ALSA: seq: change ioctl command operation to get data in kernel space')
>> Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
>> ---
>>  sound/core/seq/seq_clientmgr.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c
>> index 286394b..fd50c38 100644
>> --- a/sound/core/seq/seq_clientmgr.c
>> +++ b/sound/core/seq/seq_clientmgr.c
>> @@ -2100,7 +2100,7 @@ static long snd_seq_ioctl(struct file *file, unsigned int cmd,
>>  		struct snd_seq_client_pool	client_pool;
>>  		struct snd_seq_remove_events	remove_events;
>>  		struct snd_seq_query_subs	query_subs;
>> -	} buf = {0};
>> +	} buf;
>>  	const struct ioctl_handler *handler;
>>  	unsigned long size;
>>  	int err;
>> @@ -2114,6 +2114,9 @@ static long snd_seq_ioctl(struct file *file, unsigned int cmd,
>>  	}
>>  	if (handler->cmd == 0)
>>  		return -ENOTTY;
>> +
>> +	memset(&buf, 0, sizeof(union ioctl_arg));
>
> The common practice is to pass sizeof(buf).

OK. I'll post revised version later.


Regards

Takashi Sakamoto

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-30  6:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-30  0:11 [PATCH] ALSA: seq: initialize whole fields of automatic variable with union type Takashi Sakamoto
2016-08-30  5:11 ` Takashi Iwai
2016-08-30  6:34   ` Takashi Sakamoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).