Module Name:    src
Committed By:   msaitoh
Date:           Thu Oct 17 15:57:56 UTC 2019

Modified Files:
        src/sys/dev/pci: if_bce.c if_mcx.c

Log Message:
 Use unsigned to avoid undefined behavior. Found by kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/dev/pci/if_bce.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/pci/if_mcx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_bce.c
diff -u src/sys/dev/pci/if_bce.c:1.52 src/sys/dev/pci/if_bce.c:1.53
--- src/sys/dev/pci/if_bce.c:1.52	Thu May 30 02:32:18 2019
+++ src/sys/dev/pci/if_bce.c	Thu Oct 17 15:57:56 2019
@@ -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 @@ bce_add_mac(struct bce_softc *sc, uint8_
 	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,

Index: src/sys/dev/pci/if_mcx.c
diff -u src/sys/dev/pci/if_mcx.c:1.4 src/sys/dev/pci/if_mcx.c:1.5
--- src/sys/dev/pci/if_mcx.c:1.4	Sat Sep 28 16:22:45 2019
+++ src/sys/dev/pci/if_mcx.c	Thu Oct 17 15:57:56 2019
@@ -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 @@ CTASSERT(sizeof(struct mcx_wq_ctx) == 0x
 
 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_cmd_destroy_sq_out {
 
 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 @@ mcx_media_add_types(struct mcx_softc *sc
 
 	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 @@ mcx_media_status(struct ifnet *ifp, stru
 
 	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];
 		}
 	}

Reply via email to