Skip to contentSkip to conversation

mul_u64_u64_div_u64-basic-sanity-test.patch removed from -mm tree

merged mm-nonmm-stable Andrew Morton 1 participant 1 message Sep 2, 2024

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled

     Subject: mul_u64_u64_div_u64: basic sanity test
has been removed from the -mm tree.  Its filename was
     mul_u64_u64_div_u64-basic-sanity-test.patch

This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Nicolas Pitre <[email protected]>
Subject: mul_u64_u64_div_u64: basic sanity test
Date: Sun, 7 Jul 2024 15:05:20 -0400

Verify that edge cases produce proper results, and some more.

---

 lib/Kconfig.debug                   |   10 ++
 lib/math/Makefile                   |    1 
 lib/math/div64.c                    |    9 ++
 lib/math/test_mul_u64_u64_div_u64.c |   99 ++++++++++++++++++++++++++
 4 files changed, 118 insertions(+), 1 deletion(-)
lib/Kconfig.debug renamed from lib/Kconfig.debug~mul_u64_u64_div_u64-basic-sanity-test +10 -0
@@ -2280,6 +2280,16 @@ config TEST_DIV64
 
 	  If unsure, say N.
 
+config TEST_MULDIV64
+	tristate "mul_u64_u64_div_u64() test"
+	depends on DEBUG_KERNEL || m
+	help
+	  Enable this to turn on 'mul_u64_u64_div_u64()' function test.
+	  This test is executed only once during system boot (so affects
+	  only boot time), or at module load time.
+
+	  If unsure, say N.
+
 config TEST_IOV_ITER
 	tristate "Test iov_iter operation" if !KUNIT_ALL_TESTS
 	depends on KUNIT
lib/math/div64.c renamed from lib/math/div64.c~mul_u64_u64_div_u64-basic-sanity-test +8 -1
@@ -212,11 +212,18 @@ u64 mul_u64_u64_div_u64(u64 a, u64 b, u6
 
 #endif
 
+	/* make sure c is not zero, trigger exception otherwise */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdiv-by-zero"
+	if (unlikely(c == 0))
+		return 1/0;
+#pragma GCC diagnostic pop
+
 	int shift = __builtin_ctzll(c);
 
 	/* try reducing the fraction in case the dividend becomes <= 64 bits */
 	if ((n_hi >> shift) == 0) {
-		u64 n = (n_lo >> shift) | (n_hi << (64 - shift));
+		u64 n = shift ? (n_lo >> shift) | (n_hi << (64 - shift)) : n_lo;
 
 		return div64_u64(n, c >> shift);
 		/*
lib/math/Makefile renamed from lib/math/Makefile~mul_u64_u64_div_u64-basic-sanity-test +1 -0
@@ -6,4 +6,5 @@ obj-$(CONFIG_PRIME_NUMBERS)	+= prime_num
 obj-$(CONFIG_RATIONAL)		+= rational.o
 
 obj-$(CONFIG_TEST_DIV64)	+= test_div64.o
+obj-$(CONFIG_TEST_MULDIV64)	+= test_mul_u64_u64_div_u64.o
 obj-$(CONFIG_RATIONAL_KUNIT_TEST) += rational-test.o
lib/math/test_mul_u64_u64_div_u64.c new file +99 -0

99 lines not on this page · raw message

_

Patches currently in -mm which might be from [email protected] are