Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753153AbdLEWoH (ORCPT ); Tue, 5 Dec 2017 17:44:07 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:42907 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752621AbdLEWja (ORCPT ); Tue, 5 Dec 2017 17:39:30 -0500 X-Google-Smtp-Source: AGs4zMYdPpRoXlv4o8p2IiELvdMltDQgL/RjPNKK2utTqato+8kGlYv9o5oDkK4vpwJEPYFeZhCSQg== From: Serge Semin To: jdmason@kudzu.us, dave.jiang@intel.com, Allen.Hubbe@emc.com, Shyam-sundar.S-k@amd.com, Xiangliang.Yu@amd.com, gary.hook@amd.com Cc: Sergey.Semin@t-platforms.ru, linux-ntb@googlegroups.com, linux-kernel@vger.kernel.org, Serge Semin Subject: [PATCH v3 03/15] NTB: Fix UB/bug in ntb_mw_get_align() Date: Wed, 6 Dec 2017 01:39:06 +0300 Message-Id: <20171205223918.28727-4-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20171205223918.28727-1-fancer.lancer@gmail.com> References: <20171203191736.3399-1-fancer.lancer@gmail.com> <20171205223918.28727-1-fancer.lancer@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1081 Lines: 28 Simple (1 << pidx) operation causes undefined behaviour when pidx >= 32. It must be casted to u64 to match the actual return value of ntb_link_is_up() method, so to have all the possible peer indexes covered and to get rid of undefined behaviour. Additionally there are special macros in "linux/bitops.h" to perform the bit-set-shift operations, so it's recommended to have them used for proper bit setting. Signed-off-by: Serge Semin --- include/linux/ntb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/ntb.h b/include/linux/ntb.h index c1646f2c6344..488e586fb76c 100644 --- a/include/linux/ntb.h +++ b/include/linux/ntb.h @@ -764,7 +764,7 @@ static inline int ntb_mw_get_align(struct ntb_dev *ntb, int pidx, int widx, resource_size_t *size_align, resource_size_t *size_max) { - if (!(ntb_link_is_up(ntb, NULL, NULL) & (1 << pidx))) + if (!(ntb_link_is_up(ntb, NULL, NULL) & BIT_ULL(pidx))) return -ENOTCONN; return ntb->ops->mw_get_align(ntb, pidx, widx, addr_align, size_align, -- 2.12.0