From: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Christophe JAILLET
<christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>,
mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
dennis.dalessandro-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit.
Date: Fri, 26 Aug 2016 09:35:11 -0400 [thread overview]
Message-ID: <cf61e699-9e2d-a594-64e6-43ea33b239d9@redhat.com> (raw)
In-Reply-To: <1472186949-9025-1-git-send-email-christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 3016 bytes --]
On 8/26/2016 12:49 AM, Christophe JAILLET wrote:
> The 2nd parameter of 'find_first_bit' is the number of bits to search.
> In this case, we are passing 'sizeof(unsigned long)' which is likely to
> be 4 or 8.
If the size can be 4 or 8, then using 64 universally is not correct.
Why not use sizeof() * 8 (or << 3)?
> It is likely that the number of bits of 'port_mask' was expected here. This
> variable is a 'u64', so use 64 instead.
>
> It has been spotted by the following coccinelle script:
> @@
> expression ret, x;
>
> @@
> * ret = \(find_first_bit \| find_first_zero_bit\) (x, sizeof(...));
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
> ---
> Not sure that using 64 directly is the best option.
> Maybe '8 * sizeof(port_mask)' as used in the same file for
> 'for_each_set_bit' would be better
> ---
> drivers/infiniband/hw/hfi1/mad.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/infiniband/hw/hfi1/mad.c b/drivers/infiniband/hw/hfi1/mad.c
> index 1263abe01999..2c6c138c41b2 100644
> --- a/drivers/infiniband/hw/hfi1/mad.c
> +++ b/drivers/infiniband/hw/hfi1/mad.c
> @@ -2632,8 +2632,7 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp,
> * port the request came in on.
> */
> port_mask = be64_to_cpu(req->port_select_mask[3]);
> - port_num = find_first_bit((unsigned long *)&port_mask,
> - sizeof(port_mask));
> + port_num = find_first_bit((unsigned long *)&port_mask, 64);
>
> if ((u8)port_num != port) {
> pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
> @@ -2836,8 +2835,7 @@ static int pma_get_opa_porterrors(struct opa_pma_mad *pmp,
> * port the request came in on.
> */
> port_mask = be64_to_cpu(req->port_select_mask[3]);
> - port_num = find_first_bit((unsigned long *)&port_mask,
> - sizeof(port_mask));
> + port_num = find_first_bit((unsigned long *)&port_mask, 64);
>
> if (port_num != port) {
> pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
> @@ -3009,8 +3007,7 @@ static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp,
> * the request came in on.
> */
> port_mask = be64_to_cpu(req->port_select_mask[3]);
> - port_num = find_first_bit((unsigned long *)&port_mask,
> - sizeof(port_mask));
> + port_num = find_first_bit((unsigned long *)&port_mask, 64);
>
> if (port_num != port) {
> pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
> @@ -3246,8 +3243,7 @@ static int pma_set_opa_errorinfo(struct opa_pma_mad *pmp,
> * the request came in on.
> */
> port_mask = be64_to_cpu(req->port_select_mask[3]);
> - port_num = find_first_bit((unsigned long *)&port_mask,
> - sizeof(port_mask));
> + port_num = find_first_bit((unsigned long *)&port_mask, 64);
>
> if (port_num != port) {
> pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
>
--
Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
GPG Key ID: 0E572FDD
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 884 bytes --]
next prev parent reply other threads:[~2016-08-26 13:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-26 4:49 [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit Christophe JAILLET
[not found] ` <1472186949-9025-1-git-send-email-christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
2016-08-26 13:35 ` Doug Ledford [this message]
2016-08-26 18:01 ` Doug Ledford
2016-08-26 19:29 ` Leon Romanovsky
[not found] ` <20160826192957.GG594-2ukJVAZIZ/Y@public.gmane.org>
2016-08-26 19:34 ` Doug Ledford
2016-08-28 6:06 ` Leon Romanovsky
[not found] ` <20160828060640.GI594-2ukJVAZIZ/Y@public.gmane.org>
2016-09-02 14:39 ` Doug Ledford
2016-09-04 9:04 ` Leon Romanovsky
2016-08-27 5:25 ` Christophe JAILLET
[not found] ` <d3eea048-5c7e-a5e9-900b-fabf0f6e38c8-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
2016-09-02 17:11 ` Doug Ledford
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=cf61e699-9e2d-a594-64e6-43ea33b239d9@redhat.com \
--to=dledford-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org \
--cc=dennis.dalessandro-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).