From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: [PATCH] ALSA: Warn when control names are truncated Date: Wed, 29 Oct 2008 20:00:01 +0100 Message-ID: References: <1225291230-17812-1-git-send-email-broonie@opensource.wolfsonmicro.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 4C36E24449 for ; Wed, 29 Oct 2008 20:00:01 +0100 (CET) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Jaroslav Kysela Cc: alsa-devel@alsa-project.org, Mark Brown List-Id: alsa-devel@alsa-project.org 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 > > > > > > > > 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