* [PATCH] ALSA: drivers: make array 'names' const, reduces object code size
@ 2017-11-27 12:58 Colin King
2017-11-27 14:55 ` walter harms
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Colin King @ 2017-11-27 12:58 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, alsa-devel; +Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Don't populate array 'names' on the stack but instead make them static.
Makes the object code smaller by 50 bytes:
Before:
text data bss dec hex filename
21237 9192 1120 31549 7b3d linux/sound/drivers/dummy.o
After:
text data bss dec hex filename
21095 9280 1120 31495 7b07 linux/sound/drivers/dummy.o
(gcc version 7.2.0 x86_64)
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
sound/drivers/dummy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index 7b2b1f766b00..69db45bc0197 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -830,7 +830,7 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *info)
{
- const char *const names[] = { "None", "CD Player" };
+ static const char *const names[] = { "None", "CD Player" };
return snd_ctl_enum_info(info, 1, 2, names);
}
--
2.14.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] ALSA: drivers: make array 'names' const, reduces object code size
2017-11-27 12:58 [PATCH] ALSA: drivers: make array 'names' const, reduces object code size Colin King
@ 2017-11-27 14:55 ` walter harms
2017-11-27 15:40 ` Joe Perches
2017-11-27 17:34 ` Takashi Sakamoto
2017-11-27 19:51 ` Takashi Iwai
2 siblings, 1 reply; 8+ messages in thread
From: walter harms @ 2017-11-27 14:55 UTC (permalink / raw)
To: Colin King
Cc: Jaroslav Kysela, Takashi Iwai, alsa-devel, kernel-janitors,
linux-kernel
Am 27.11.2017 13:58, schrieb Colin King:
> From: Colin Ian King <colin.king@canonical.com>
>
> Don't populate array 'names' on the stack but instead make them static.
> Makes the object code smaller by 50 bytes:
>
> Before:
> text data bss dec hex filename
> 21237 9192 1120 31549 7b3d linux/sound/drivers/dummy.o
>
> After:
> text data bss dec hex filename
> 21095 9280 1120 31495 7b07 linux/sound/drivers/dummy.o
>
> (gcc version 7.2.0 x86_64)
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> sound/drivers/dummy.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
> index 7b2b1f766b00..69db45bc0197 100644
> --- a/sound/drivers/dummy.c
> +++ b/sound/drivers/dummy.c
> @@ -830,7 +830,7 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
> static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
> struct snd_ctl_elem_info *info)
> {
> - const char *const names[] = { "None", "CD Player" };
> + static const char *const names[] = { "None", "CD Player" };
>
> return snd_ctl_enum_info(info, 1, 2, names);
> }
nitpick: while here
snd_ctl_enum_info(info, 1, ARRAY_SIZE(names), names);
just my 2 cents,
re,
wh
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ALSA: drivers: make array 'names' const, reduces object code size
2017-11-27 14:55 ` walter harms
@ 2017-11-27 15:40 ` Joe Perches
2017-11-27 16:00 ` walter harms
0 siblings, 1 reply; 8+ messages in thread
From: Joe Perches @ 2017-11-27 15:40 UTC (permalink / raw)
To: wharms, Colin King
Cc: linux-kernel, alsa-devel, kernel-janitors, Takashi Iwai
On Mon, 2017-11-27 at 15:55 +0100, walter harms wrote:
> Am 27.11.2017 13:58, schrieb Colin King:
> > From: Colin Ian King <colin.king@canonical.com>
> > Don't populate array 'names' on the stack but instead make them static.
> > Makes the object code smaller by 50 bytes:
[]
> > diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
[]
> > @@ -830,7 +830,7 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
> > static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
> > struct snd_ctl_elem_info *info)
> > {
> > - const char *const names[] = { "None", "CD Player" };
> > + static const char *const names[] = { "None", "CD Player" };
> >
> > return snd_ctl_enum_info(info, 1, 2, names);
> > }
>
> nitpick: while here
> snd_ctl_enum_info(info, 1, ARRAY_SIZE(names), names);
>
> just my 2 cents,
True, but that seems counter style for most uses of snd_ctl_enum_info
$ git grep -w snd_ctl_enum_info | grep -v ARRAY_SIZE | wc -l
159
$ git grep -w snd_ctl_enum_info | grep ARRAY_SIZE | wc -l
10
but most of those seem to choose variable amounts of a single
array. Here, ARRAY_SIZE seems better to me too.
For another real nitpick, please prefer "const *" over "const*"
$ git grep -P "\*\s+const\b" | wc -l
7068
$ git grep -P "\*const\b" | wc -l
1801
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ALSA: drivers: make array 'names' const, reduces object code size
2017-11-27 15:40 ` Joe Perches
@ 2017-11-27 16:00 ` walter harms
0 siblings, 0 replies; 8+ messages in thread
From: walter harms @ 2017-11-27 16:00 UTC (permalink / raw)
To: Joe Perches
Cc: Colin King, Jaroslav Kysela, Takashi Iwai, alsa-devel,
kernel-janitors, linux-kernel
Am 27.11.2017 16:40, schrieb Joe Perches:
> On Mon, 2017-11-27 at 15:55 +0100, walter harms wrote:
>> Am 27.11.2017 13:58, schrieb Colin King:
>>> From: Colin Ian King <colin.king@canonical.com>
>>> Don't populate array 'names' on the stack but instead make them static.
>>> Makes the object code smaller by 50 bytes:
> []
>>> diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
> []
>>> @@ -830,7 +830,7 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
>>> static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
>>> struct snd_ctl_elem_info *info)
>>> {
>>> - const char *const names[] = { "None", "CD Player" };
>>> + static const char *const names[] = { "None", "CD Player" };
>>>
>>> return snd_ctl_enum_info(info, 1, 2, names);
>>> }
>>
>> nitpick: while here
>> snd_ctl_enum_info(info, 1, ARRAY_SIZE(names), names);
>>
>> just my 2 cents,
>
> True, but that seems counter style for most uses of snd_ctl_enum_info
>
> $ git grep -w snd_ctl_enum_info | grep -v ARRAY_SIZE | wc -l
> 159
> $ git grep -w snd_ctl_enum_info | grep ARRAY_SIZE | wc -l
> 10
>
> but most of those seem to choose variable amounts of a single
> array. Here, ARRAY_SIZE seems better to me too.
I will not argue. I was curious about the magic numbers and
int this case it seems an obvious choice in other cases
it may be wrong i did not and i will not investigate.
re,
wh
>
> For another real nitpick, please prefer "const *" over "const*"
>
> $ git grep -P "\*\s+const\b" | wc -l
> 7068
> $ git grep -P "\*const\b" | wc -l
> 1801
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ALSA: drivers: make array 'names' const, reduces object code size
2017-11-27 12:58 [PATCH] ALSA: drivers: make array 'names' const, reduces object code size Colin King
2017-11-27 14:55 ` walter harms
@ 2017-11-27 17:34 ` Takashi Sakamoto
2017-11-27 19:51 ` Takashi Iwai
2017-11-27 19:51 ` Takashi Iwai
2 siblings, 1 reply; 8+ messages in thread
From: Takashi Sakamoto @ 2017-11-27 17:34 UTC (permalink / raw)
To: Colin King, Jaroslav Kysela, Takashi Iwai, alsa-devel
Cc: kernel-janitors, linux-kernel, walter harms
Hi,
On Nov 27 2017 21:58, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Don't populate array 'names' on the stack but instead make them static.
> Makes the object code smaller by 50 bytes:
>
> Before:
> text data bss dec hex filename
> 21237 9192 1120 31549 7b3d linux/sound/drivers/dummy.o
>
> After:
> text data bss dec hex filename
> 21095 9280 1120 31495 7b07 linux/sound/drivers/dummy.o
>
> (gcc version 7.2.0 x86_64)
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> sound/drivers/dummy.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
> index 7b2b1f766b00..69db45bc0197 100644
> --- a/sound/drivers/dummy.c
> +++ b/sound/drivers/dummy.c
> @@ -830,7 +830,7 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
> static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
> struct snd_ctl_elem_info *info)
> {
> - const char *const names[] = { "None", "CD Player" };
> + static const char *const names[] = { "None", "CD Player" };
>
> return snd_ctl_enum_info(info, 1, 2, names);
> }
Total size of snd-dummy.ko increases but this patch has an advantage to
have the symbol in read-only section. This looks good to me.
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Another issue is addressed by the others, but here I focus on the
original intention of this patch.
Thanks
Takashi Sakamoto
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ALSA: drivers: make array 'names' const, reduces object code size
2017-11-27 12:58 [PATCH] ALSA: drivers: make array 'names' const, reduces object code size Colin King
2017-11-27 14:55 ` walter harms
2017-11-27 17:34 ` Takashi Sakamoto
@ 2017-11-27 19:51 ` Takashi Iwai
2 siblings, 0 replies; 8+ messages in thread
From: Takashi Iwai @ 2017-11-27 19:51 UTC (permalink / raw)
To: Colin King; +Cc: alsa-devel, Jaroslav Kysela, kernel-janitors, linux-kernel
On Mon, 27 Nov 2017 13:58:51 +0100,
Colin King wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> Don't populate array 'names' on the stack but instead make them static.
> Makes the object code smaller by 50 bytes:
>
> Before:
> text data bss dec hex filename
> 21237 9192 1120 31549 7b3d linux/sound/drivers/dummy.o
>
> After:
> text data bss dec hex filename
> 21095 9280 1120 31495 7b07 linux/sound/drivers/dummy.o
>
> (gcc version 7.2.0 x86_64)
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Applied, thanks.
Takashi
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ALSA: drivers: make array 'names' const, reduces object code size
2017-11-27 17:34 ` Takashi Sakamoto
@ 2017-11-27 19:51 ` Takashi Iwai
2017-11-28 10:39 ` Takashi Sakamoto
0 siblings, 1 reply; 8+ messages in thread
From: Takashi Iwai @ 2017-11-27 19:51 UTC (permalink / raw)
To: Takashi Sakamoto
Cc: alsa-devel, Colin King, Jaroslav Kysela, wharms, kernel-janitors,
linux-kernel
On Mon, 27 Nov 2017 18:34:17 +0100,
Takashi Sakamoto wrote:
>
> Hi,
>
> On Nov 27 2017 21:58, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > Don't populate array 'names' on the stack but instead make them static.
> > Makes the object code smaller by 50 bytes:
> >
> > Before:
> > text data bss dec hex filename
> > 21237 9192 1120 31549 7b3d linux/sound/drivers/dummy.o
> >
> > After:
> > text data bss dec hex filename
> > 21095 9280 1120 31495 7b07 linux/sound/drivers/dummy.o
> >
> > (gcc version 7.2.0 x86_64)
> >
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> > sound/drivers/dummy.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
> > index 7b2b1f766b00..69db45bc0197 100644
> > --- a/sound/drivers/dummy.c
> > +++ b/sound/drivers/dummy.c
> > @@ -830,7 +830,7 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
> > static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
> > struct snd_ctl_elem_info *info)
> > {
> > - const char *const names[] = { "None", "CD Player" };
> > + static const char *const names[] = { "None", "CD Player" };
> > return snd_ctl_enum_info(info, 1, 2, names);
> > }
>
> Total size of snd-dummy.ko increases but this patch has an advantage
> to have the symbol in read-only section.
The total size decreases :)
Takashi
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ALSA: drivers: make array 'names' const, reduces object code size
2017-11-27 19:51 ` Takashi Iwai
@ 2017-11-28 10:39 ` Takashi Sakamoto
0 siblings, 0 replies; 8+ messages in thread
From: Takashi Sakamoto @ 2017-11-28 10:39 UTC (permalink / raw)
To: Takashi Iwai
Cc: Colin King, alsa-devel, kernel-janitors, linux-kernel, wharms
On Nov 28 2017 04:51, Takashi Iwai wrote:
> On Mon, 27 Nov 2017 18:34:17 +0100,
> Takashi Sakamoto wrote:
>>
>> Hi,
>>
>> On Nov 27 2017 21:58, Colin King wrote:
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> Don't populate array 'names' on the stack but instead make them static.
>>> Makes the object code smaller by 50 bytes:
>>>
>>> Before:
>>> text data bss dec hex filename
>>> 21237 9192 1120 31549 7b3d linux/sound/drivers/dummy.o
>>>
>>> After:
>>> text data bss dec hex filename
>>> 21095 9280 1120 31495 7b07 linux/sound/drivers/dummy.o
>>>
>>> (gcc version 7.2.0 x86_64)
>>>
>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>>> ---
>>> sound/drivers/dummy.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
>>> index 7b2b1f766b00..69db45bc0197 100644
>>> --- a/sound/drivers/dummy.c
>>> +++ b/sound/drivers/dummy.c
>>> @@ -830,7 +830,7 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
>>> static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
>>> struct snd_ctl_elem_info *info)
>>> {
>>> - const char *const names[] = { "None", "CD Player" };
>>> + static const char *const names[] = { "None", "CD Player" };
>>> return snd_ctl_enum_info(info, 1, 2, names);
>>> }
>>
>> Total size of snd-dummy.ko increases but this patch has an advantage
>> to have the symbol in read-only section.
>
> The total size decreases :)
Ah, yes. The state of my local build tree is not good to calculate it...
In fact, the relocatable object decreases its size when built with a
header package from Ubuntu repository.
Thanks
Takashi Sakamoto
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-11-28 10:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-27 12:58 [PATCH] ALSA: drivers: make array 'names' const, reduces object code size Colin King
2017-11-27 14:55 ` walter harms
2017-11-27 15:40 ` Joe Perches
2017-11-27 16:00 ` walter harms
2017-11-27 17:34 ` Takashi Sakamoto
2017-11-27 19:51 ` Takashi Iwai
2017-11-28 10:39 ` Takashi Sakamoto
2017-11-27 19:51 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox