Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/rockchip Fix wrong calculation found by kUBSan....



details:   https://anonhg.NetBSD.org/src/rev/aee7018dc912
branches:  trunk
changeset: 1021254:aee7018dc912
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Thu May 20 01:41:55 2021 +0000

description:
Fix wrong calculation found by kUBSan. OK'd by jmcneill.

 The output was:
    UBSan: Undefined Behavior in ../../../../arch/arm/rockchip/
    rk_cru_composite.c:86:21, unsigned integer overflow: 0 divrem 0 cannot be
    represented in type 'unsigned int'

diffstat:

 sys/arch/arm/rockchip/rk_cru_composite.c |  7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r 3773e5f0f64a -r aee7018dc912 sys/arch/arm/rockchip/rk_cru_composite.c
--- a/sys/arch/arm/rockchip/rk_cru_composite.c  Thu May 20 01:07:24 2021 +0000
+++ b/sys/arch/arm/rockchip/rk_cru_composite.c  Thu May 20 01:41:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rk_cru_composite.c,v 1.5 2019/11/16 13:23:13 jmcneill Exp $ */
+/* $NetBSD: rk_cru_composite.c,v 1.6 2021/05/20 01:41:55 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rk_cru_composite.c,v 1.5 2019/11/16 13:23:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk_cru_composite.c,v 1.6 2021/05/20 01:41:55 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -83,7 +83,8 @@
                return (u_int)((uint64_t)prate * num / den);
        } else {
                const uint32_t val = CRU_READ(sc, composite->muxdiv_reg);
-               const u_int div = __SHIFTOUT(val, composite->div_mask) + 1;
+               const u_int div = (composite->div_mask != 0)
+                   ? __SHIFTOUT(val, composite->div_mask) + 1 : 1;
 
                return prate / div;
        }



Home | Main Index | Thread Index | Old Index