[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <519927e4-ea40-927a-4e56-0d87e7313934@gmx.com>
Date: Tue, 26 Jun 2018 10:48:19 +0800
From: cgxu519 <cgxu519@....com>
To: Joe Perches <joe@...ches.com>, jakub.kicinski@...ronome.com,
davem@...emloft.net
Cc: oss-drivers@...ronome.com, netdev@...r.kernel.org
Subject: Re: [PATCH v2 net] nfp: cast sizeof() to int when comparing with
error code
On 06/26/2018 10:29 AM, Joe Perches wrote:
> On Tue, 2018-06-26 at 09:16 +0800, Chengguang Xu wrote:
>> sizeof() will return unsigned value so in the error check
>> negative error code will be always larger than sizeof().
> []
>> diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nffw.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nffw.c
> []
>> @@ -232,7 +232,7 @@ struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp)
>> err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res),
>> nfp_resource_address(state->res),
>> fwinf, sizeof(*fwinf));
>> - if (err < sizeof(*fwinf))
>> + if (err < (int)sizeof(*fwinf))
>> goto err_release;
>>
>> if (!nffw_res_flg_init_get(fwinf))
> The way this is done in several places in the kernel is
> to test first for < 0 and then test for < sizeof
>
> if (err < 0 || err < sizeof(etc...)
>
> see net/ceph/ceph_common.c etc...
If we need to distinguish the cases <0 and >0 && <sizeof() then that
approach is better.
If not I think cast to int will be enough.
Thanks,
Chengguang.
Powered by blists - more mailing lists