From: cgxu519 <cgxu519@gmx.com>
To: Joe Perches <joe@perches.com>,
jakub.kicinski@netronome.com, davem@davemloft.net
Cc: oss-drivers@netronome.com, netdev@vger.kernel.org
Subject: Re: [PATCH v2 net] nfp: cast sizeof() to int when comparing with error code
Date: Tue, 26 Jun 2018 10:48:19 +0800 [thread overview]
Message-ID: <519927e4-ea40-927a-4e56-0d87e7313934@gmx.com> (raw)
In-Reply-To: <308957d91294ec1883ec492eecb8ffe1d51a0689.camel@perches.com>
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.
next prev parent reply other threads:[~2018-06-26 2:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-26 1:16 [PATCH v2 net] nfp: cast sizeof() to int when comparing with error code Chengguang Xu
2018-06-26 2:10 ` Joe Perches
2018-06-26 7:21 ` Julia Lawall
2018-06-26 8:06 ` Julia Lawall
2018-06-26 8:21 ` cgxu519
2018-06-26 2:29 ` Joe Perches
2018-06-26 2:48 ` cgxu519 [this message]
2018-06-27 6:38 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=519927e4-ea40-927a-4e56-0d87e7313934@gmx.com \
--to=cgxu519@gmx.com \
--cc=davem@davemloft.net \
--cc=jakub.kicinski@netronome.com \
--cc=joe@perches.com \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox