]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
NTB: Fix UB/bug in ntb_mw_get_align()
authorSerge Semin <fancer.lancer@gmail.com>
Wed, 6 Dec 2017 14:31:54 +0000 (17:31 +0300)
committerJon Mason <jdmason@kudzu.us>
Mon, 29 Jan 2018 03:17:24 +0000 (22:17 -0500)
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 <fancer.lancer@gmail.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Jon Mason <jdmason@kudzu.us>
include/linux/ntb.h

index 21b1826a095341f9ffdee3f885c8c713f13f75b8..181d16601dd9c8bc1fa4112099dea637e962cfd0 100644 (file)
@@ -767,7 +767,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,