Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Jaroslav Kysela <perex@perex.cz>
Cc: alsa-devel@alsa-project.org,
	Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: Re: [PATCH] ALSA: Warn when control names are truncated
Date: Wed, 29 Oct 2008 20:00:01 +0100	[thread overview]
Message-ID: <s5htzavdy6m.wl%tiwai@suse.de> (raw)
In-Reply-To: <Pine.LNX.4.61.0810291757060.12044@tm8103.perex-int.cz>

At Wed, 29 Oct 2008 19:31:25 +0100 (CET),
Jaroslav Kysela wrote:
> 
> On Wed, 29 Oct 2008, Takashi Iwai wrote:
> 
> > At Wed, 29 Oct 2008 15:51:40 +0100 (CET),
> > Jaroslav Kysela wrote:
> > > 
> > > On Wed, 29 Oct 2008, Takashi Iwai wrote:
> > > 
> > > > At Wed, 29 Oct 2008 14:40:30 +0000,
> > > > Mark Brown wrote:
> > > > > 
> > > > > This is likely to confuse user interfaces since the end of the control
> > > > > name is interpreted (eg, "Volume", "Switch").
> > > > > 
> > > > > Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> > > > 
> > > > Thanks, applied now.
> > > > 
> > > > 
> > > > > +		if (strcmp(ncontrol->name, kctl.id.name) != 0)
> > > 
> > > Maybe better is to just use end char comparsion to save few CPU ticks:
> > > 
> > > if (kctl.id.name[sizeof(kctl.id.name)-2] != '\0' &&
> > >     ncontrol->name[sizeof(kctl.id.name)-1] != '\0')
> > 
> > No, this may cause segfault
> 
> How? The first check in the fixed size variable initialized with zeros 
> allocated on heap ensures that ncontrol->name string is at least 
> sizeof(kctl.id.name) long. There is no possibility of segfault.

Hm, OK, this would work indeed surprisingly.

> 
> > (and way too hacky to understand what's the purpose of the code...)
> 
> The printk explains check nicely.

Uh, no.  The problem is that you'll likely need to consider what
really the code does and even whether it's correct at the first
glance.  That's definitely bad for readability.

Since the code path is absolutely no fast path and a rarely used
path, there is no win at all in practice for such a nano
optimization.


Takashi

  reply	other threads:[~2008-10-29 19:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-29 14:40 [PATCH] ALSA: Warn when control names are truncated Mark Brown
2008-10-29 14:46 ` Takashi Iwai
2008-10-29 14:51   ` Jaroslav Kysela
2008-10-29 14:55     ` Takashi Iwai
2008-10-29 18:31       ` Jaroslav Kysela
2008-10-29 19:00         ` Takashi Iwai [this message]
2008-10-29 14:55     ` Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2008-10-29 14:14 Mark Brown
2008-10-29 14:28 ` Takashi Iwai
2008-10-29 14:33   ` Mark Brown

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=s5htzavdy6m.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=perex@perex.cz \
    /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