Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Use unsigned to avoid undefined behavior. Found ...



details:   https://anonhg.NetBSD.org/src/rev/cd0fdd09e313
branches:  trunk
changeset: 845821:cd0fdd09e313
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Thu Oct 17 15:57:56 2019 +0000

description:
Use unsigned to avoid undefined behavior. Found by kUBSan.

diffstat:

 sys/dev/pci/if_bce.c |   6 +++---
 sys/dev/pci/if_mcx.c |  12 ++++++------
 2 files changed, 9 insertions(+), 9 deletions(-)

diffs (81 lines):

diff -r 8ae561e54a4f -r cd0fdd09e313 sys/dev/pci/if_bce.c
--- a/sys/dev/pci/if_bce.c      Thu Oct 17 14:33:02 2019 +0000
+++ b/sys/dev/pci/if_bce.c      Thu Oct 17 15:57:56 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_bce.c,v 1.52 2019/05/30 02:32:18 msaitoh Exp $   */
+/* $NetBSD: if_bce.c,v 1.53 2019/10/17 15:57:56 msaitoh Exp $   */
 
 /*
  * Copyright (c) 2003 Clifford Wright. All rights reserved.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bce.c,v 1.52 2019/05/30 02:32:18 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bce.c,v 1.53 2019/10/17 15:57:56 msaitoh Exp $");
 
 #include "vlan.h"
 
@@ -1010,7 +1010,7 @@
        uint32_t        rval;
 
        bus_space_write_4(sc->bce_btag, sc->bce_bhandle, BCE_FILT_LOW,
-           mac[2] << 24 | mac[3] << 16 | mac[4] << 8 | mac[5]);
+           (uint32_t)mac[2] << 24 | mac[3] << 16 | mac[4] << 8 | mac[5]);
        bus_space_write_4(sc->bce_btag, sc->bce_bhandle, BCE_FILT_HI,
            mac[0] << 8 | mac[1] | 0x10000);    /* MAGIC */
        bus_space_write_4(sc->bce_btag, sc->bce_bhandle, BCE_FILT_CTL,
diff -r 8ae561e54a4f -r cd0fdd09e313 sys/dev/pci/if_mcx.c
--- a/sys/dev/pci/if_mcx.c      Thu Oct 17 14:33:02 2019 +0000
+++ b/sys/dev/pci/if_mcx.c      Thu Oct 17 15:57:56 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_mcx.c,v 1.4 2019/09/28 16:22:45 tnn Exp $ */
+/*     $NetBSD: if_mcx.c,v 1.5 2019/10/17 15:57:56 msaitoh Exp $ */
 /*     $OpenBSD: if_mcx.c,v 1.33 2019/09/12 04:23:59 jmatthew Exp $ */
 
 /*
@@ -130,7 +130,7 @@
 #define MCX_CMDQ_DOORBELL              0x0018
 
 #define MCX_STATE              0x01fc
-#define MCX_STATE_MASK                 (1 << 31)
+#define MCX_STATE_MASK                 (1U << 31)
 #define MCX_STATE_INITIALIZING         (1 << 31)
 #define MCX_STATE_READY                        (0 << 31)
 #define MCX_STATE_INTERFACE_MASK       (0x3 << 24)
@@ -1324,7 +1324,7 @@
 
 struct mcx_sq_ctx {
        uint32_t                sq_flags;
-#define MCX_SQ_CTX_RLKEY                       (1 << 31)
+#define MCX_SQ_CTX_RLKEY                       (1U << 31)
 #define MCX_SQ_CTX_FRE_SHIFT                   (1 << 29)
 #define MCX_SQ_CTX_FLUSH_IN_ERROR              (1 << 28)
 #define MCX_SQ_CTX_MIN_WQE_INLINE_SHIFT                24
@@ -1434,7 +1434,7 @@
 
 struct mcx_rq_ctx {
        uint32_t                rq_flags;
-#define MCX_RQ_CTX_RLKEY                       (1 << 31)
+#define MCX_RQ_CTX_RLKEY                       (1U << 31)
 #define MCX_RQ_CTX_VLAN_STRIP_DIS              (1 << 28)
 #define MCX_RQ_CTX_MEM_RQ_TYPE_SHIFT           24
 #define MCX_RQ_CTX_STATE_SHIFT                 20
@@ -6501,7 +6501,7 @@
 
        proto_cap = be32toh(ptys.rp_eth_proto_cap);
        for (i = 0; i < __arraycount(mcx_eth_cap_map); i++) {
-               if ((proto_cap & (1 << i)) && (mcx_eth_cap_map[i] != 0))
+               if ((proto_cap & (1U << i)) && (mcx_eth_cap_map[i] != 0))
                        ifmedia_add(&sc->sc_media, IFM_ETHER |
                            mcx_eth_cap_map[i], 0, NULL);
        }
@@ -6531,7 +6531,7 @@
 
        media_oper = 0;
        for (i = 0; i < __arraycount(mcx_eth_cap_map); i++) {
-               if (proto_oper & (1 << i)) {
+               if (proto_oper & (1U << i)) {
                        media_oper = mcx_eth_cap_map[i];
                }
        }



Home | Main Index | Thread Index | Old Index