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.


Reply via email to