Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/bdc7b9d12a63
branches:  trunk
changeset: 966036:bdc7b9d12a63
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Fri Oct 11 14:22:46 2019 +0000

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

diffstat:

 sys/dev/ic/am79900reg.h |  6 +++---
 sys/dev/pci/if_pcn.c    |  9 +++++----
 2 files changed, 8 insertions(+), 7 deletions(-)

diffs (61 lines):

diff -r 29641a634e71 -r bdc7b9d12a63 sys/dev/ic/am79900reg.h
--- a/sys/dev/ic/am79900reg.h   Fri Oct 11 13:32:46 2019 +0000
+++ b/sys/dev/ic/am79900reg.h   Fri Oct 11 14:22:46 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: am79900reg.h,v 1.9 2008/04/28 20:23:49 martin Exp $    */
+/*     $NetBSD: am79900reg.h,v 1.10 2019/10/11 14:22:46 msaitoh Exp $  */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
 };
 
 /* Receive message descriptor 1 (rmd1_bits) */
-#define        LE_R1_OWN       (1<<31)         /* LANCE owns the packet */
+#define        LE_R1_OWN       (1U<<31)        /* LANCE owns the packet */
 #define        LE_R1_ERR       (1<<30)         /* error summary */
 #define        LE_R1_FRAM      (1<<29)         /* framing error */
 #define        LE_R1_OFLO      (1<<28)         /* overflow error */
@@ -111,7 +111,7 @@
     "\20\40OWN\37ERR\36FRAM\35OFLO\34CRC\33BUFF\32STP\31ENP"
 
 /* Transmit message descriptor 1 (tmd1_bits) */
-#define        LE_T1_OWN       (1<<31)         /* LANCE owns the packet */
+#define        LE_T1_OWN       (1U<<31)        /* LANCE owns the packet */
 #define        LE_T1_ERR       (1<<30)         /* error summary */
 #define        LE_T1_ADD_FCS   (1<<29)         /* add FCS (PCnet-PCI) */
 #define        LE_T1_NO_FCS    (1<<29)         /* no FCS (ILACC) */
diff -r 29641a634e71 -r bdc7b9d12a63 sys/dev/pci/if_pcn.c
--- a/sys/dev/pci/if_pcn.c      Fri Oct 11 13:32:46 2019 +0000
+++ b/sys/dev/pci/if_pcn.c      Fri Oct 11 14:22:46 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_pcn.c,v 1.71 2019/05/28 07:41:49 msaitoh Exp $      */
+/*     $NetBSD: if_pcn.c,v 1.72 2019/10/11 14:22:46 msaitoh Exp $      */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_pcn.c,v 1.71 2019/05/28 07:41:49 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pcn.c,v 1.72 2019/10/11 14:22:46 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1708,12 +1708,13 @@
        sc->sc_initblock.init_rdra = htole32(PCN_CDRXADDR(sc, 0));
        sc->sc_initblock.init_tdra = htole32(PCN_CDTXADDR(sc, 0));
        sc->sc_initblock.init_mode = htole32(sc->sc_mode |
-           ((ffs(PCN_NTXDESC) - 1) << 28) |
+           (((uint32_t)ffs(PCN_NTXDESC) - 1) << 28) |
            ((ffs(PCN_NRXDESC) - 1) << 20));
 
        /* Set the station address in the init block. */
        sc->sc_initblock.init_padr[0] = htole32(enaddr[0] |
-           (enaddr[1] << 8) | (enaddr[2] << 16) | (enaddr[3] << 24));
+           (enaddr[1] << 8) | (enaddr[2] << 16) |
+           ((uint32_t)enaddr[3] << 24));
        sc->sc_initblock.init_padr[1] = htole32(enaddr[4] |
            (enaddr[5] << 8));
 



Home | Main Index | Thread Index | Old Index