Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1470542

[PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit.

From Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Newsgroups linux.kernel
Subject [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit.
Date 2016-08-26 07:00 +0200
Message-ID <sahpf-2mA-7@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


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.

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@wanadoo.fr>
---
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;
-- 
2.7.4


---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2016-08-26 07:00 +0200
  Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Doug Ledford <dledford@redhat.com> - 2016-08-26 15:40 +0200
    Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Doug Ledford <dledford@redhat.com> - 2016-08-26 20:10 +0200
      Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Doug Ledford <dledford@redhat.com> - 2016-08-26 21:40 +0200
        Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Leon Romanovsky <leon@kernel.org> - 2016-08-28 08:10 +0200
          Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Doug Ledford <dledford@redhat.com> - 2016-09-02 16:40 +0200
            Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Leon Romanovsky <leon@kernel.org> - 2016-09-04 11:10 +0200
      Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Leon Romanovsky <leon@kernel.org> - 2016-08-26 21:40 +0200
    Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2016-08-27 07:30 +0200
      Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Doug Ledford <dledford@redhat.com> - 2016-09-02 19:20 +0200

csiph-web