1 // SPDX-License-Identifier: GPL-2.0-only 1 // SPDX-License-Identifier: GPL-2.0-only 2 #include <linux/compiler.h> 2 #include <linux/compiler.h> 3 #include <linux/gcd.h> 3 #include <linux/gcd.h> 4 #include <linux/export.h> 4 #include <linux/export.h> 5 #include <linux/lcm.h> 5 #include <linux/lcm.h> 6 6 7 /* Lowest common multiple */ 7 /* Lowest common multiple */ 8 unsigned long lcm(unsigned long a, unsigned lo 8 unsigned long lcm(unsigned long a, unsigned long b) 9 { 9 { 10 if (a && b) 10 if (a && b) 11 return (a / gcd(a, b)) * b; 11 return (a / gcd(a, b)) * b; 12 else 12 else 13 return 0; 13 return 0; 14 } 14 } 15 EXPORT_SYMBOL_GPL(lcm); 15 EXPORT_SYMBOL_GPL(lcm); 16 16 17 unsigned long lcm_not_zero(unsigned long a, un 17 unsigned long lcm_not_zero(unsigned long a, unsigned long b) 18 { 18 { 19 unsigned long l = lcm(a, b); 19 unsigned long l = lcm(a, b); 20 20 21 if (l) 21 if (l) 22 return l; 22 return l; 23 23 24 return (b ? : a); 24 return (b ? : a); 25 } 25 } 26 EXPORT_SYMBOL_GPL(lcm_not_zero); 26 EXPORT_SYMBOL_GPL(lcm_not_zero); 27 27
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.