public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] lib: polynomial: Move to math/ and clean up
@ 2026-02-27  7:47 Andy Shevchenko
  2026-02-27  7:47 ` [PATCH v1 1/3] lib: polynomial: Move to math/ subfolder Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-02-27  7:47 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Randy Dunlap, Andy Shevchenko

While removing Baikal SoC and platform code pieces I found that this
code belongs to lib/math/ rather than generic lib/. Hence the move and
followed up cleanups.

No functional changes intended.

Andy Shevchenko (3):
  lib: polynomial: Move to math/ subfolder
  lib: math: polynomial: Don't use 'proxy' headers
  lib: math: polynomial: Remove link to non-exist file and fix spelling

 lib/Kconfig                 |  3 ---
 lib/Makefile                |  2 --
 lib/math/Kconfig            |  3 +++
 lib/math/Makefile           |  1 +
 lib/{ => math}/polynomial.c | 20 ++++++++------------
 5 files changed, 12 insertions(+), 17 deletions(-)
 rename lib/{ => math}/polynomial.c (90%)

-- 
2.50.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v1 1/3] lib: polynomial: Move to math/ subfolder
  2026-02-27  7:47 [PATCH v1 0/3] lib: polynomial: Move to math/ and clean up Andy Shevchenko
@ 2026-02-27  7:47 ` Andy Shevchenko
  2026-02-27  7:47 ` [PATCH v1 2/3] lib: math: polynomial: Don't use 'proxy' headers Andy Shevchenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-02-27  7:47 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Randy Dunlap, Andy Shevchenko

The algorithm behind polynomial belongs to our collection of
math equations and expressions handling. Move it to math/
subfolder where others of the kind are located.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/Kconfig                 | 3 ---
 lib/Makefile                | 2 --
 lib/math/Kconfig            | 3 +++
 lib/math/Makefile           | 1 +
 lib/{ => math}/polynomial.c | 0
 5 files changed, 4 insertions(+), 5 deletions(-)
 rename lib/{ => math}/polynomial.c (100%)

diff --git a/lib/Kconfig b/lib/Kconfig
index 0b8241e5b548..d6a5c699a919 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -637,9 +637,6 @@ config PLDMFW
 config ASN1_ENCODER
        tristate
 
-config POLYNOMIAL
-       tristate
-
 config FIRMWARE_TABLE
 	bool
 
diff --git a/lib/Makefile b/lib/Makefile
index abc32420b581..00668fda0203 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -244,8 +244,6 @@ obj-$(CONFIG_MEMREGION) += memregion.o
 obj-$(CONFIG_STMP_DEVICE) += stmp_device.o
 obj-$(CONFIG_IRQ_POLL) += irq_poll.o
 
-obj-$(CONFIG_POLYNOMIAL) += polynomial.o
-
 # stackdepot.c should not be instrumented or call instrumented functions.
 # Prevent the compiler from calling builtins like memcmp() or bcmp() from this
 # file.
diff --git a/lib/math/Kconfig b/lib/math/Kconfig
index 0634b428d0cb..0e6d9cffc5d6 100644
--- a/lib/math/Kconfig
+++ b/lib/math/Kconfig
@@ -5,6 +5,9 @@ config CORDIC
 	  This option provides an implementation of the CORDIC algorithm;
 	  calculations are in fixed point. Module will be called cordic.
 
+config POLYNOMIAL
+       tristate
+
 config PRIME_NUMBERS
 	tristate "Simple prime number generator for testing"
 	help
diff --git a/lib/math/Makefile b/lib/math/Makefile
index d1caba23baa0..9a3850d55b79 100644
--- a/lib/math/Makefile
+++ b/lib/math/Makefile
@@ -2,6 +2,7 @@
 obj-y += div64.o gcd.o lcm.o int_log.o int_pow.o int_sqrt.o reciprocal_div.o
 
 obj-$(CONFIG_CORDIC)		+= cordic.o
+obj-$(CONFIG_POLYNOMIAL)	+= polynomial.o
 obj-$(CONFIG_PRIME_NUMBERS)	+= prime_numbers.o
 obj-$(CONFIG_RATIONAL)		+= rational.o
 
diff --git a/lib/polynomial.c b/lib/math/polynomial.c
similarity index 100%
rename from lib/polynomial.c
rename to lib/math/polynomial.c
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 2/3] lib: math: polynomial: Don't use 'proxy' headers
  2026-02-27  7:47 [PATCH v1 0/3] lib: polynomial: Move to math/ and clean up Andy Shevchenko
  2026-02-27  7:47 ` [PATCH v1 1/3] lib: polynomial: Move to math/ subfolder Andy Shevchenko
@ 2026-02-27  7:47 ` Andy Shevchenko
  2026-02-27 16:13   ` Kuan-Wei Chiu
  2026-02-27  7:48 ` [PATCH v1 3/3] lib: math: polynomial: Remove link to non-exist file and fix spelling Andy Shevchenko
  2026-02-27 16:27 ` [PATCH v1 0/3] lib: polynomial: Move to math/ and clean up Kuan-Wei Chiu
  3 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2026-02-27  7:47 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Randy Dunlap, Andy Shevchenko

Update header inclusions to follow IWYU (Include What You Use)
principle.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/math/polynomial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/math/polynomial.c b/lib/math/polynomial.c
index 66d383445fec..805d1de56b9a 100644
--- a/lib/math/polynomial.c
+++ b/lib/math/polynomial.c
@@ -10,7 +10,7 @@
  *
  */
 
-#include <linux/kernel.h>
+#include <linux/export.h>
 #include <linux/module.h>
 #include <linux/polynomial.h>
 
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 3/3] lib: math: polynomial: Remove link to non-exist file and fix spelling
  2026-02-27  7:47 [PATCH v1 0/3] lib: polynomial: Move to math/ and clean up Andy Shevchenko
  2026-02-27  7:47 ` [PATCH v1 1/3] lib: polynomial: Move to math/ subfolder Andy Shevchenko
  2026-02-27  7:47 ` [PATCH v1 2/3] lib: math: polynomial: Don't use 'proxy' headers Andy Shevchenko
@ 2026-02-27  7:48 ` Andy Shevchenko
  2026-02-27 21:18   ` Randy Dunlap
  2026-02-27 16:27 ` [PATCH v1 0/3] lib: polynomial: Move to math/ and clean up Kuan-Wei Chiu
  3 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2026-02-27  7:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Randy Dunlap, Andy Shevchenko

The Baikal SoC and platform support was dropped from the kernel,
remove the reference to non-exist file. While at it, fix spelling.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/math/polynomial.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/lib/math/polynomial.c b/lib/math/polynomial.c
index 805d1de56b9a..c1d113f7ca37 100644
--- a/lib/math/polynomial.c
+++ b/lib/math/polynomial.c
@@ -15,16 +15,13 @@
 #include <linux/polynomial.h>
 
 /*
- * Originally this was part of drivers/hwmon/bt1-pvt.c.
  * There the following conversion is used and should serve as an example here:
  *
  * The original translation formulae of the temperature (in degrees of Celsius)
  * to PVT data and vice-versa are following:
  *
- * N = 1.8322e-8*(T^4) + 2.343e-5*(T^3) + 8.7018e-3*(T^2) + 3.9269*(T^1) +
- *     1.7204e2
- * T = -1.6743e-11*(N^4) + 8.1542e-8*(N^3) + -1.8201e-4*(N^2) +
- *     3.1020e-1*(N^1) - 4.838e1
+ * N = 1.8322e-8*(T^4) + 2.343e-5*(T^3) + 8.7018e-3*(T^2) + 3.9269*(T^1) + 1.7204e2
+ * T = -1.6743e-11*(N^4) + 8.1542e-8*(N^3) + -1.8201e-4*(N^2) + 3.1020e-1*(N^1) - 4.838e1
  *
  * where T = [-48.380, 147.438]C and N = [0, 1023].
  *
@@ -35,10 +32,9 @@
  * formulae to accept millidegrees of Celsius. Here what they look like after
  * the alterations:
  *
- * N = (18322e-20*(T^4) + 2343e-13*(T^3) + 87018e-9*(T^2) + 39269e-3*T +
- *     17204e2) / 1e4
- * T = -16743e-12*(D^4) + 81542e-9*(D^3) - 182010e-6*(D^2) + 310200e-3*D -
- *     48380
+ * N = (18322e-20*(T^4) + 2343e-13*(T^3) + 87018e-9*(T^2) + 39269e-3*T + 17204e2) / 1e4
+ * T = -16743e-12*(D^4) + 81542e-9*(D^3) - 182010e-6*(D^2) + 310200e-3*D - 48380
+ *
  * where T = [-48380, 147438] mC and N = [0, 1023].
  *
  * static const struct polynomial poly_temp_to_N = {
@@ -68,13 +64,13 @@
  * polynomial_calc - calculate a polynomial using integer arithmetic
  *
  * @poly: pointer to the descriptor of the polynomial
- * @data: input value of the polynimal
+ * @data: input value of the polynomial
  *
  * Calculate the result of a polynomial using only integer arithmetic. For
  * this to work without too much loss of precision the coefficients has to
  * be altered. This is called factor redistribution.
  *
- * Returns the result of the polynomial calculation.
+ * Return: the result of the polynomial calculation.
  */
 long polynomial_calc(const struct polynomial *poly, long data)
 {
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 2/3] lib: math: polynomial: Don't use 'proxy' headers
  2026-02-27  7:47 ` [PATCH v1 2/3] lib: math: polynomial: Don't use 'proxy' headers Andy Shevchenko
@ 2026-02-27 16:13   ` Kuan-Wei Chiu
  2026-02-27 16:18     ` Andy Shevchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Kuan-Wei Chiu @ 2026-02-27 16:13 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-kernel, Andrew Morton, Randy Dunlap

Hi Andy,

On Fri, Feb 27, 2026 at 08:47:59AM +0100, Andy Shevchenko wrote:
> Update header inclusions to follow IWYU (Include What You Use)
> principle.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  lib/math/polynomial.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/math/polynomial.c b/lib/math/polynomial.c
> index 66d383445fec..805d1de56b9a 100644
> --- a/lib/math/polynomial.c
> +++ b/lib/math/polynomial.c
> @@ -10,7 +10,7 @@
>   *
>   */
>  
> -#include <linux/kernel.h>
> +#include <linux/export.h>
>  #include <linux/module.h>
>  #include <linux/polynomial.h>

Since polynomial.c uses mult_frac(), perhaps we should also add an
explicit #include <linux/math.h>?

Regards,
Kuan-Wei

>  
> -- 
> 2.50.1
> 
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 2/3] lib: math: polynomial: Don't use 'proxy' headers
  2026-02-27 16:13   ` Kuan-Wei Chiu
@ 2026-02-27 16:18     ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-02-27 16:18 UTC (permalink / raw)
  To: Kuan-Wei Chiu; +Cc: linux-kernel, Andrew Morton, Randy Dunlap

On Sat, Feb 28, 2026 at 12:13:34AM +0800, Kuan-Wei Chiu wrote:
> On Fri, Feb 27, 2026 at 08:47:59AM +0100, Andy Shevchenko wrote:
> > Update header inclusions to follow IWYU (Include What You Use)
> > principle.

...

> > -#include <linux/kernel.h>
> > +#include <linux/export.h>
> >  #include <linux/module.h>

#include <linux/math.h>

> >  #include <linux/polynomial.h>
> 
> Since polynomial.c uses mult_frac(), perhaps we should also add an
> explicit #include <linux/math.h>?

Good point! I missed it somehow. Andrew, do you want a new version or can you
amend that in this patch?

Thanks for the review!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 0/3] lib: polynomial: Move to math/ and clean up
  2026-02-27  7:47 [PATCH v1 0/3] lib: polynomial: Move to math/ and clean up Andy Shevchenko
                   ` (2 preceding siblings ...)
  2026-02-27  7:48 ` [PATCH v1 3/3] lib: math: polynomial: Remove link to non-exist file and fix spelling Andy Shevchenko
@ 2026-02-27 16:27 ` Kuan-Wei Chiu
  3 siblings, 0 replies; 8+ messages in thread
From: Kuan-Wei Chiu @ 2026-02-27 16:27 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-kernel, Andrew Morton, Randy Dunlap

On Fri, Feb 27, 2026 at 08:47:57AM +0100, Andy Shevchenko wrote:
> While removing Baikal SoC and platform code pieces I found that this
> code belongs to lib/math/ rather than generic lib/. Hence the move and
> followed up cleanups.
> 
> No functional changes intended.
> 
> Andy Shevchenko (3):
>   lib: polynomial: Move to math/ subfolder
>   lib: math: polynomial: Don't use 'proxy' headers
>   lib: math: polynomial: Remove link to non-exist file and fix spelling

With the #include <math.h> added in patch #2
for the series:

Reviewed-by: Kuan-Wei Chiu <visitorckw@gmail.com>

Regards,
Kuan-Wei

> 
>  lib/Kconfig                 |  3 ---
>  lib/Makefile                |  2 --
>  lib/math/Kconfig            |  3 +++
>  lib/math/Makefile           |  1 +
>  lib/{ => math}/polynomial.c | 20 ++++++++------------
>  5 files changed, 12 insertions(+), 17 deletions(-)
>  rename lib/{ => math}/polynomial.c (90%)
> 
> -- 
> 2.50.1
> 
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 3/3] lib: math: polynomial: Remove link to non-exist file and fix spelling
  2026-02-27  7:48 ` [PATCH v1 3/3] lib: math: polynomial: Remove link to non-exist file and fix spelling Andy Shevchenko
@ 2026-02-27 21:18   ` Randy Dunlap
  0 siblings, 0 replies; 8+ messages in thread
From: Randy Dunlap @ 2026-02-27 21:18 UTC (permalink / raw)
  To: Andy Shevchenko, linux-kernel; +Cc: Andrew Morton



On 2/26/26 11:48 PM, Andy Shevchenko wrote:
> diff --git a/lib/math/polynomial.c b/lib/math/polynomial.c
> index 805d1de56b9a..c1d113f7ca37 100644
> --- a/lib/math/polynomial.c
> +++ b/lib/math/polynomial.c
> @@ -15,16 +15,13 @@
>  #include <linux/polynomial.h>
>  
>  /*
> - * Originally this was part of drivers/hwmon/bt1-pvt.c.
>   * There the following conversion is used and should serve as an example here:

That's a little confusing without having the first (deleted) line.
Maybe just say:
 * The following conversion is an example:

or
 * Example conversion:

>   *
>   * The original translation formulae of the temperature (in degrees of Celsius)
>   * to PVT data and vice-versa are following:

anyway:
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>

-- 
~Randy

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-02-27 21:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27  7:47 [PATCH v1 0/3] lib: polynomial: Move to math/ and clean up Andy Shevchenko
2026-02-27  7:47 ` [PATCH v1 1/3] lib: polynomial: Move to math/ subfolder Andy Shevchenko
2026-02-27  7:47 ` [PATCH v1 2/3] lib: math: polynomial: Don't use 'proxy' headers Andy Shevchenko
2026-02-27 16:13   ` Kuan-Wei Chiu
2026-02-27 16:18     ` Andy Shevchenko
2026-02-27  7:48 ` [PATCH v1 3/3] lib: math: polynomial: Remove link to non-exist file and fix spelling Andy Shevchenko
2026-02-27 21:18   ` Randy Dunlap
2026-02-27 16:27 ` [PATCH v1 0/3] lib: polynomial: Move to math/ and clean up Kuan-Wei Chiu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox