From patchwork Fri Aug 26 04:49:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 9300817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 78C3F601C0 for ; Fri, 26 Aug 2016 04:51:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DE3C29492 for ; Fri, 26 Aug 2016 04:51:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6174A294A2; Fri, 26 Aug 2016 04:51:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0037E29492 for ; Fri, 26 Aug 2016 04:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752065AbcHZEuM convert rfc822-to-8bit (ORCPT ); Fri, 26 Aug 2016 00:50:12 -0400 Received: from smtp04.smtpout.orange.fr ([80.12.242.126]:22280 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751433AbcHZEuJ (ORCPT ); Fri, 26 Aug 2016 00:50:09 -0400 Received: from localhost.localdomain ([92.140.227.209]) by mwinf5d59 with ME id bgpC1t00A4XiYz803gpDk7; Fri, 26 Aug 2016 06:49:15 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 26 Aug 2016 06:49:15 +0200 X-ME-IP: 92.140.227.209 From: Christophe JAILLET To: mike.marciniszyn@intel.com, dennis.dalessandro@intel.com, dledford@redhat.com, sean.hefty@intel.com, hal.rosenstock@gmail.com Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Date: Fri, 26 Aug 2016 06:49:09 +0200 Message-Id: <1472186949-9025-1-git-send-email-christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Antivirus: avast! (VPS 160825-5, 25/08/2016), Outbound message X-Antivirus-Status: Clean Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;