From mboxrd@z Thu Jan 1 00:00:00 1970 From: Khalid Aziz Date: Wed, 08 Jul 2015 13:59:23 +0000 Subject: Re: [PATCH] [SCSI] FlashPoint: optimize string comparison Message-Id: <559D2CBB.8090502@gonehiking.org> List-Id: References: <1436247543-7326-1-git-send-email-christophe.jaillet@wanadoo.fr> <559C06B4.2010808@gonehiking.org> <559CB8EC.1090008@wanadoo.fr> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: Frans Klaver , Christophe JAILLET Cc: JBottomley@odin.com, linux-scsi@vger.kernel.org, "linux-kernel@vger.kernel.org" , kernel-janitors@vger.kernel.org On 07/08/2015 01:12 AM, Frans Klaver wrote: > On Wed, Jul 8, 2015 at 7:45 AM, Christophe JAILLET > wrote: >> Le 07/07/2015 19:04, Khalid Aziz a =C3=A9crit : >>> >>> On 07/07/2015 02:45 AM, Frans Klaver wrote: >>>> >>>> On Tue, Jul 7, 2015 at 7:39 AM, Christophe JAILLET >>>> wrote: >>>>> >>>>> Stop comparing the strings as soon as we know that they don't match. >>>>> >>>>> Signed-off-by: Christophe JAILLET >>>>> --- >>>>> drivers/scsi/FlashPoint.c | 4 +++- >>>>> 1 file changed, 3 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/drivers/scsi/FlashPoint.c b/drivers/scsi/FlashPoint.c >>>>> index 5c74e4c..24a4d1a 100644 >>>>> --- a/drivers/scsi/FlashPoint.c >>>>> +++ b/drivers/scsi/FlashPoint.c >>>>> @@ -6280,8 +6280,10 @@ static unsigned char FPT_scmachid(unsigned char >>>>> p_card, >>>>> match =3D 1; >>>>> >>>>> for (k =3D 0; k < ID_STRING_LENGTH; k++) { >>>>> - if (p_id_string[k] !>>>>> FPT_scamInfo[i].id_= string[k]) >>>>> + if (p_id_string[k] !>>>>> FPT_scamInfo[i].id_= string[k]) { >>>>> match =3D 0; >>>>> + break; >>>>> + } >>>>> } >>>>> >>>>> if (match) { >>>> >>>> >>>> Why doesn't this use strncmp? >>>> >>>> Thanks, >>>> Frans >>>> >>> >>> I suspect that is how this code came from Mylex many years ago. Using >>> strncmp would indeed be a better way to clean this up. Also, further do= wn in >>> the same routine: >>> >>> if (FPT_scamInfo[match].state =3D ID_UNUSED) { >>> for (k =3D 0; k < ID_STRING_LENGTH; k++) { >>> FPT_scamInfo[match].id_string[k] >>> = p_id_string[k]; >>> } >>> >>> >>> This should use strncpy instead. There is another similar spot further >>> down. >>> >>> Christophe, if you can send a new patch with these clean-ups, that would >>> be great. >>> >>> Thanks, >>> Khalid >> >> >> Hi, >> >> I'm sorry but I won't propose a new patch for that. >> >> I had the same reaction at first (why not use strncmp?) but it seems to = be >> the way this driver is coded. Should we want to introduce strncmp here, >> then, as you have noticed, strcpy should be used to. memset could be also >> used in many places. Then looking elsewhere in the code, many things sho= uld, >> IMHO, also be fixed. (use consistently empty lines before/after code ; u= se >> consistently { }...) >> >> Another concern to me is "the use of carriage return". In the following >> examples, things could be much more readable if not limited to 50 chars = per >> line, or so. > > 80. Parts of the code are indented way too much, resulting in these > unreadable lines. I have to say that this entire driver looks like > something that (sh|w)ould be in staging right now. FlashPoint.c and BusLogic.c together make up the buslogic driver. I went=20 through a massive clean up of BusLogic.c (addressing issues like the=20 ones you guys are bringing up) when I took over maintenance of buslogic=20 driver and made it 64-bit clean. I am very much in agreement with=20 suggested clean ups, but this code has been in the kernel for a very=20 long time and cleaning it up at this point for the sake of clean up is=20 not a reason enough to destabilize a very stable driver. staging is for=20 drivers under development and in experimental state. buslogic driver is=20 most definitely not experimental. For now we either leave FlashPoint.c=20 as it is or clean it up as part of a bigger effort to add new=20 functionality or fix a major bug. Christophe's original patch fixes an inefficiency in the code, so my=20 take on it is to either accept the very specific fix without modifying=20 rest of the code or combine this fix with clean up of at least the=20 entire FPT_scmachid() routine. Thanks, Khalid -- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Khalid Aziz Subject: Re: [PATCH] [SCSI] FlashPoint: optimize string comparison Date: Wed, 08 Jul 2015 07:59:23 -0600 Message-ID: <559D2CBB.8090502@gonehiking.org> References: <1436247543-7326-1-git-send-email-christophe.jaillet@wanadoo.fr> <559C06B4.2010808@gonehiking.org> <559CB8EC.1090008@wanadoo.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: Sender: kernel-janitors-owner@vger.kernel.org To: Frans Klaver , Christophe JAILLET Cc: JBottomley@odin.com, linux-scsi@vger.kernel.org, "linux-kernel@vger.kernel.org" , kernel-janitors@vger.kernel.org List-Id: linux-scsi@vger.kernel.org On 07/08/2015 01:12 AM, Frans Klaver wrote: > On Wed, Jul 8, 2015 at 7:45 AM, Christophe JAILLET > wrote: >> Le 07/07/2015 19:04, Khalid Aziz a =C3=A9crit : >>> >>> On 07/07/2015 02:45 AM, Frans Klaver wrote: >>>> >>>> On Tue, Jul 7, 2015 at 7:39 AM, Christophe JAILLET >>>> wrote: >>>>> >>>>> Stop comparing the strings as soon as we know that they don't mat= ch. >>>>> >>>>> Signed-off-by: Christophe JAILLET >>>>> --- >>>>> drivers/scsi/FlashPoint.c | 4 +++- >>>>> 1 file changed, 3 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/drivers/scsi/FlashPoint.c b/drivers/scsi/FlashPoint.= c >>>>> index 5c74e4c..24a4d1a 100644 >>>>> --- a/drivers/scsi/FlashPoint.c >>>>> +++ b/drivers/scsi/FlashPoint.c >>>>> @@ -6280,8 +6280,10 @@ static unsigned char FPT_scmachid(unsigned= char >>>>> p_card, >>>>> match =3D 1; >>>>> >>>>> for (k =3D 0; k < ID_STRING_LENGTH; k++) { >>>>> - if (p_id_string[k] !=3D >>>>> FPT_scamInfo[i].id_string[k]) >>>>> + if (p_id_string[k] !=3D >>>>> FPT_scamInfo[i].id_string[k]) { >>>>> match =3D 0; >>>>> + break; >>>>> + } >>>>> } >>>>> >>>>> if (match) { >>>> >>>> >>>> Why doesn't this use strncmp? >>>> >>>> Thanks, >>>> Frans >>>> >>> >>> I suspect that is how this code came from Mylex many years ago. Usi= ng >>> strncmp would indeed be a better way to clean this up. Also, furthe= r down in >>> the same routine: >>> >>> if (FPT_scamInfo[match].state =3D=3D ID_UNUSED) { >>> for (k =3D 0; k < ID_STRING_LENGTH; k++) { >>> FPT_scamInfo[match].id_string[k] =3D >>> p_id_string[k]; >>> } >>> >>> >>> This should use strncpy instead. There is another similar spot furt= her >>> down. >>> >>> Christophe, if you can send a new patch with these clean-ups, that = would >>> be great. >>> >>> Thanks, >>> Khalid >> >> >> Hi, >> >> I'm sorry but I won't propose a new patch for that. >> >> I had the same reaction at first (why not use strncmp?) but it seems= to be >> the way this driver is coded. Should we want to introduce strncmp he= re, >> then, as you have noticed, strcpy should be used to. memset could be= also >> used in many places. Then looking elsewhere in the code, many things= should, >> IMHO, also be fixed. (use consistently empty lines before/after code= ; use >> consistently { }...) >> >> Another concern to me is "the use of carriage return". In the follow= ing >> examples, things could be much more readable if not limited to 50 ch= ars per >> line, or so. > > 80. Parts of the code are indented way too much, resulting in these > unreadable lines. I have to say that this entire driver looks like > something that (sh|w)ould be in staging right now. =46lashPoint.c and BusLogic.c together make up the buslogic driver. I w= ent=20 through a massive clean up of BusLogic.c (addressing issues like the=20 ones you guys are bringing up) when I took over maintenance of buslogic= =20 driver and made it 64-bit clean. I am very much in agreement with=20 suggested clean ups, but this code has been in the kernel for a very=20 long time and cleaning it up at this point for the sake of clean up is=20 not a reason enough to destabilize a very stable driver. staging is for= =20 drivers under development and in experimental state. buslogic driver is= =20 most definitely not experimental. For now we either leave FlashPoint.c=20 as it is or clean it up as part of a bigger effort to add new=20 functionality or fix a major bug. Christophe's original patch fixes an inefficiency in the code, so my=20 take on it is to either accept the very specific fix without modifying=20 rest of the code or combine this fix with clean up of at least the=20 entire FPT_scmachid() routine. Thanks, Khalid -- To unsubscribe from this list: send the line "unsubscribe kernel-janito= rs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935430AbbGHPuX (ORCPT ); Wed, 8 Jul 2015 11:50:23 -0400 Received: from resqmta-po-01v.sys.comcast.net ([96.114.154.160]:49061 "EHLO resqmta-po-01v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965203AbbGHPuN (ORCPT ); Wed, 8 Jul 2015 11:50:13 -0400 Message-ID: <559D2CBB.8090502@gonehiking.org> Date: Wed, 08 Jul 2015 07:59:23 -0600 From: Khalid Aziz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Frans Klaver , Christophe JAILLET CC: JBottomley@odin.com, linux-scsi@vger.kernel.org, "linux-kernel@vger.kernel.org" , kernel-janitors@vger.kernel.org Subject: Re: [PATCH] [SCSI] FlashPoint: optimize string comparison References: <1436247543-7326-1-git-send-email-christophe.jaillet@wanadoo.fr> <559C06B4.2010808@gonehiking.org> <559CB8EC.1090008@wanadoo.fr> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/08/2015 01:12 AM, Frans Klaver wrote: > On Wed, Jul 8, 2015 at 7:45 AM, Christophe JAILLET > wrote: >> Le 07/07/2015 19:04, Khalid Aziz a écrit : >>> >>> On 07/07/2015 02:45 AM, Frans Klaver wrote: >>>> >>>> On Tue, Jul 7, 2015 at 7:39 AM, Christophe JAILLET >>>> wrote: >>>>> >>>>> Stop comparing the strings as soon as we know that they don't match. >>>>> >>>>> Signed-off-by: Christophe JAILLET >>>>> --- >>>>> drivers/scsi/FlashPoint.c | 4 +++- >>>>> 1 file changed, 3 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/drivers/scsi/FlashPoint.c b/drivers/scsi/FlashPoint.c >>>>> index 5c74e4c..24a4d1a 100644 >>>>> --- a/drivers/scsi/FlashPoint.c >>>>> +++ b/drivers/scsi/FlashPoint.c >>>>> @@ -6280,8 +6280,10 @@ static unsigned char FPT_scmachid(unsigned char >>>>> p_card, >>>>> match = 1; >>>>> >>>>> for (k = 0; k < ID_STRING_LENGTH; k++) { >>>>> - if (p_id_string[k] != >>>>> FPT_scamInfo[i].id_string[k]) >>>>> + if (p_id_string[k] != >>>>> FPT_scamInfo[i].id_string[k]) { >>>>> match = 0; >>>>> + break; >>>>> + } >>>>> } >>>>> >>>>> if (match) { >>>> >>>> >>>> Why doesn't this use strncmp? >>>> >>>> Thanks, >>>> Frans >>>> >>> >>> I suspect that is how this code came from Mylex many years ago. Using >>> strncmp would indeed be a better way to clean this up. Also, further down in >>> the same routine: >>> >>> if (FPT_scamInfo[match].state == ID_UNUSED) { >>> for (k = 0; k < ID_STRING_LENGTH; k++) { >>> FPT_scamInfo[match].id_string[k] = >>> p_id_string[k]; >>> } >>> >>> >>> This should use strncpy instead. There is another similar spot further >>> down. >>> >>> Christophe, if you can send a new patch with these clean-ups, that would >>> be great. >>> >>> Thanks, >>> Khalid >> >> >> Hi, >> >> I'm sorry but I won't propose a new patch for that. >> >> I had the same reaction at first (why not use strncmp?) but it seems to be >> the way this driver is coded. Should we want to introduce strncmp here, >> then, as you have noticed, strcpy should be used to. memset could be also >> used in many places. Then looking elsewhere in the code, many things should, >> IMHO, also be fixed. (use consistently empty lines before/after code ; use >> consistently { }...) >> >> Another concern to me is "the use of carriage return". In the following >> examples, things could be much more readable if not limited to 50 chars per >> line, or so. > > 80. Parts of the code are indented way too much, resulting in these > unreadable lines. I have to say that this entire driver looks like > something that (sh|w)ould be in staging right now. FlashPoint.c and BusLogic.c together make up the buslogic driver. I went through a massive clean up of BusLogic.c (addressing issues like the ones you guys are bringing up) when I took over maintenance of buslogic driver and made it 64-bit clean. I am very much in agreement with suggested clean ups, but this code has been in the kernel for a very long time and cleaning it up at this point for the sake of clean up is not a reason enough to destabilize a very stable driver. staging is for drivers under development and in experimental state. buslogic driver is most definitely not experimental. For now we either leave FlashPoint.c as it is or clean it up as part of a bigger effort to add new functionality or fix a major bug. Christophe's original patch fixes an inefficiency in the code, so my take on it is to either accept the very specific fix without modifying rest of the code or combine this fix with clean up of at least the entire FPT_scmachid() routine. Thanks, Khalid