lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH6sp9OmMje3EAVisaToorOQb+j3AWm_RE_UTpXN6eYjFny72w@mail.gmail.com>
Date:	Wed, 8 Jul 2015 09:12:40 +0200
From:	Frans Klaver <fransklaver@...il.com>
To:	Christophe JAILLET <christophe.jaillet@...adoo.fr>
Cc:	Khalid Aziz <khalid@...ehiking.org>, JBottomley@...n.com,
	linux-scsi@...r.kernel.org,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	kernel-janitors@...r.kernel.org
Subject: Re: [PATCH] [SCSI] FlashPoint: optimize string comparison

On Wed, Jul 8, 2015 at 7:45 AM, Christophe JAILLET
<christophe.jaillet@...adoo.fr> 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
>>> <christophe.jaillet@...adoo.fr> wrote:
>>>>
>>>> Stop comparing the strings as soon as we know that they don't match.
>>>>
>>>> Signed-off-by: Christophe JAILLET <christophe.jaillet@...adoo.fr>
>>>> ---
>>>>   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.

Frans
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ