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/c6f2ebaa6d7e
branches:  trunk
changeset: 1024168:c6f2ebaa6d7e
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon Oct 11 15:11:07 2021 +0000

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

diffstat:

 sys/dev/pci/if_rge.c |  10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diffs (39 lines):

diff -r 98e347633dd0 -r c6f2ebaa6d7e sys/dev/pci/if_rge.c
--- a/sys/dev/pci/if_rge.c      Mon Oct 11 15:08:17 2021 +0000
+++ b/sys/dev/pci/if_rge.c      Mon Oct 11 15:11:07 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_rge.c,v 1.20 2021/10/11 15:10:19 msaitoh Exp $      */
+/*     $NetBSD: if_rge.c,v 1.21 2021/10/11 15:11:07 msaitoh Exp $      */
 /*     $OpenBSD: if_rge.c,v 1.9 2020/12/12 11:48:53 jan Exp $  */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_rge.c,v 1.20 2021/10/11 15:10:19 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_rge.c,v 1.21 2021/10/11 15:11:07 msaitoh Exp $");
 
 #include <sys/types.h>
 
@@ -1503,9 +1503,9 @@
                            ETHER_ADDR_LEN) >> 26;
 
                        if (h < 32)
-                               hashes[0] |= (1 << h);
+                               hashes[0] |= (1U << h);
                        else
-                               hashes[1] |= (1 << (h - 32));
+                               hashes[1] |= (1U << (h - 32));
 
                        ETHER_NEXT_MULTI(step, enm);
                }
@@ -2068,7 +2068,7 @@
 {
        RGE_SETBIT_1(sc, RGE_EECMD, RGE_EECMD_WRITECFG);
        RGE_WRITE_4(sc, RGE_MAC0,
-           addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0]);
+           (uint32_t)addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0]);
        RGE_WRITE_4(sc, RGE_MAC4,
            addr[5] <<  8 | addr[4]);
        RGE_CLRBIT_1(sc, RGE_EECMD, RGE_EECMD_WRITECFG);



Home | Main Index | Thread Index | Old Index