From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752104AbcKQVeq (ORCPT ); Thu, 17 Nov 2016 16:34:46 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33471 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750714AbcKQVeo (ORCPT ); Thu, 17 Nov 2016 16:34:44 -0500 Subject: Re: sound: bebop: strncmp length oddity To: Takashi Sakamoto , Takashi Iwai , Joe Perches References: <1477777020.23018.8.camel@perches.com> Cc: alsa-devel , Clemens Ladisch , Takashi Iwai , LKML From: Nicolas Iooss Message-ID: <6ad63c31-5faf-41e9-525b-b9bf089439ef@m4x.org> Date: Thu, 17 Nov 2016 22:34:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/11/16 21:07, Takashi Sakamoto wrote: > On Nov 17 2016 20:47, Takashi Iwai wrote: >> On Sat, 29 Oct 2016 23:37:00 +0200, >> Joe Perches wrote: >>> >>> 15 isn't the length of the string, is that really what's desired? >>> >>> linux/next/sound/firewire/bebob/bebop.c >>> >>> ----------------------------- >>> >>> static bool >>> check_audiophile_booted(struct fw_unit *unit) >>> { >>> char name[24] = {0}; >>> >>> if (fw_csr_string(unit->directory, CSR_MODEL, name, sizeof(name)) >>> < 0) >>> return false; >>> >>> return strncmp(name, "FW Audiophile Bootloader", 15) != 0; >>> } >> >> Indeed it looks bogus. Even "FW...." string is already 24 letters, so >> it's over name[] array size. >> >> Sakamoto-san, could you fix it properly? > > It's OK just to compare first a few characters, while I left whole > string for our information because model-specific information is easily > lost. > > For M-Audio's FireWire Audiophile, modalias of > 'ieee1394:ven00000D6Cmo00010060sp' hits this unit only. However the unit > has two states relevant to loaded firmware. Initial firmware returns 'FW > Audiophile Bootloader', while functional firmware returns 'FW > Audiophile'. Just comparing the first 15 characters is the shortest way > to defferentiate them. (Actually 14 characters. I guess that I did avoid > comparison based on LWS...) > > Therefore, changing comparison range is not for bug fix, just for > readers. But I agree with these patches because the code is a bit > confusing. I'll post a patch soon for this aim with appropriate > information, sorry for Nicolas. All right, so long as the code is modified in a way that makes it more consistent, I am all right. It is one patch less I need to care about :) Nicolas