Re: [PATCH] platform/x86: huawei-wmi: Fix misuse of strcmp() function

From: Gustavo A. R. Silva
Date: Tue Oct 15 2019 - 15:51:54 EST


Hi Ayman,

On 10/15/19 14:08, ayman.bagabas@xxxxxxxxx wrote:

>> /* Huawei laptops come with one battery only */
>> - if (strcmp(battery->desc->name, "BAT") != 1)
>
> Note we don't have a battery number in BATx, strcmp would return 1 if
> battery->desc->name is "BAT0" or any one digit. This is a desired
> behavior where some Huawei laptops identify the first battery as "BAT1"
> and this would match if name is greater than "BAT" by one digit.
>

Great to know this is not a bug. I don't think there is any
other instance in the whole codebase like this one: strcmp(...) != 1
So, that's an odd thing to see... Maybe you can consider adding
the whole description above as a code comment? :)

> Maybe strcmp(battery->desc->name, "BAT") < 0 is a better way to go.
>

Yeah; this is bit more specific.

Thanks!
--
Gustavo