[PATCH] math: Make RATIONAL tristate

1 view
Skip to first unread message

Geert Uytterhoeven

unread,
Jul 5, 2021, 7:46:38 AM7/5/21
to Trent Piepho, Colin Ian King, Andy Shevchenko, Andrew Morton, Brendan Higgins, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Geert Uytterhoeven
All but one symbols that select RATIONAL are tristate, but RATIONAL
itself is bool. Change it to tristate, so the rational fractions
support code can be modular if no builtin code relies on it.

While at it, add support for compile-testing and provide a help text.

Signed-off-by: Geert Uytterhoeven <ge...@linux-m68k.org>
---
Exposed by commit b6c75c4afceb8bc0 ("lib/math/rational: add Kunit test
cases") and CONFIG_KUNIT_ALL_TESTS=m.

I'm not so happy RATIONAL_KUNIT_TEST selects RATIONAL, as test code
should depend on the presence of the feature to test. Else enabling
a test may add unneeded code to a production kernel.
Perhaps the "if COMPILE_TEST" should be dropped, making RATIONAL
visible, so RATIONAL_KUNIT_TEST can depend on RATIONAL instead?
---
lib/math/Kconfig | 5 ++++-
lib/math/rational.c | 3 +++
2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/math/Kconfig b/lib/math/Kconfig
index f19bc9734fa7cc4b..14def252ea7db6e0 100644
--- a/lib/math/Kconfig
+++ b/lib/math/Kconfig
@@ -14,4 +14,7 @@ config PRIME_NUMBERS
If unsure, say N.

config RATIONAL
- bool
+ tristate "Rational fractions support" if COMPILE_TEST
+ help
+ This option provides support for rational fractions.
+ This symbol should be selected automatically by drivers that need it.
diff --git a/lib/math/rational.c b/lib/math/rational.c
index c0ab51d8fbb98d17..ec59d426ea638b0f 100644
--- a/lib/math/rational.c
+++ b/lib/math/rational.c
@@ -13,6 +13,7 @@
#include <linux/export.h>
#include <linux/minmax.h>
#include <linux/limits.h>
+#include <linux/module.h>

/*
* calculate best rational approximation for a given fraction
@@ -106,3 +107,5 @@ void rational_best_approximation(
}

EXPORT_SYMBOL(rational_best_approximation);
+
+MODULE_LICENSE("GPL v2");
--
2.25.1

Andy Shevchenko

unread,
Jul 5, 2021, 10:53:22 AM7/5/21
to Geert Uytterhoeven, Trent Piepho, Colin Ian King, Andrew Morton, Brendan Higgins, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
On Mon, Jul 05, 2021 at 01:46:33PM +0200, Geert Uytterhoeven wrote:
> All but one symbols that select RATIONAL are tristate, but RATIONAL
> itself is bool. Change it to tristate, so the rational fractions
> support code can be modular if no builtin code relies on it.
>
> While at it, add support for compile-testing and provide a help text.

...

> Exposed by commit b6c75c4afceb8bc0 ("lib/math/rational: add Kunit test
> cases") and CONFIG_KUNIT_ALL_TESTS=m.
>
> I'm not so happy RATIONAL_KUNIT_TEST selects RATIONAL, as test code
> should depend on the presence of the feature to test. Else enabling
> a test may add unneeded code to a production kernel.
> Perhaps the "if COMPILE_TEST" should be dropped, making RATIONAL
> visible, so RATIONAL_KUNIT_TEST can depend on RATIONAL instead?

...

> + tristate "Rational fractions support" if COMPILE_TEST

Making it tristate is okay, but visible (even for COMPILE_TEST)... why?
Just on purpose to be dependent on for test case? I understand your
justification above, but it will bring all hidden symbols to be unhidden
(due to test cases) and this is not the right thing to do in my opinion.

Why not to complain to KUnit people to fix their infra to avoid tests that
tries non-selected feature(s)?

--
With Best Regards,
Andy Shevchenko


Geert Uytterhoeven

unread,
Jul 6, 2021, 3:14:47 AM7/6/21
to Andy Shevchenko, Trent Piepho, Colin Ian King, Andrew Morton, Brendan Higgins, open list:KERNEL SELFTEST FRAMEWORK, kuni...@googlegroups.com, Linux Kernel Mailing List
Hi Andy,

On Mon, Jul 5, 2021 at 4:53 PM Andy Shevchenko
<andriy.s...@linux.intel.com> wrote:
> On Mon, Jul 05, 2021 at 01:46:33PM +0200, Geert Uytterhoeven wrote:
> > All but one symbols that select RATIONAL are tristate, but RATIONAL
> > itself is bool. Change it to tristate, so the rational fractions
> > support code can be modular if no builtin code relies on it.
> >
> > While at it, add support for compile-testing and provide a help text.
>
> ...
>
> > Exposed by commit b6c75c4afceb8bc0 ("lib/math/rational: add Kunit test
> > cases") and CONFIG_KUNIT_ALL_TESTS=m.
> >
> > I'm not so happy RATIONAL_KUNIT_TEST selects RATIONAL, as test code
> > should depend on the presence of the feature to test. Else enabling
> > a test may add unneeded code to a production kernel.
> > Perhaps the "if COMPILE_TEST" should be dropped, making RATIONAL
> > visible, so RATIONAL_KUNIT_TEST can depend on RATIONAL instead?
>
> ...
>
> > + tristate "Rational fractions support" if COMPILE_TEST
>
> Making it tristate is okay, but visible (even for COMPILE_TEST)... why?
> Just on purpose to be dependent on for test case? I understand your
> justification above, but it will bring all hidden symbols to be unhidden
> (due to test cases) and this is not the right thing to do in my opinion.

OK. Will drop in v2.

> Why not to complain to KUnit people to fix their infra to avoid tests that
> tries non-selected feature(s)?

I guess the audience is listening...

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Geert Uytterhoeven

unread,
Jul 6, 2021, 6:09:55 AM7/6/21
to Trent Piepho, Colin Ian King, Andy Shevchenko, Andrew Morton, Brendan Higgins, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Geert Uytterhoeven
All but one symbols that select RATIONAL are tristate, but RATIONAL
itself is bool. Change it to tristate, so the rational fractions
support code can be modular if no builtin code relies on it.

Signed-off-by: Geert Uytterhoeven <ge...@linux-m68k.org>
---
Exposed by commit b6c75c4afceb8bc0 ("lib/math/rational: add Kunit test
cases") and CONFIG_KUNIT_ALL_TESTS=m.

v2:
- Drop compile-testing and help text.
---
lib/math/Kconfig | 2 +-
lib/math/rational.c | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/math/Kconfig b/lib/math/Kconfig
index f19bc9734fa7cc4b..0634b428d0cb7f86 100644
--- a/lib/math/Kconfig
+++ b/lib/math/Kconfig
@@ -14,4 +14,4 @@ config PRIME_NUMBERS
If unsure, say N.

config RATIONAL
- bool
+ tristate

Andy Shevchenko

unread,
Jul 6, 2021, 6:32:09 AM7/6/21
to Geert Uytterhoeven, Trent Piepho, Colin Ian King, Andrew Morton, Brendan Higgins, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
On Tue, Jul 06, 2021 at 12:09:44PM +0200, Geert Uytterhoeven wrote:
> All but one symbols that select RATIONAL are tristate, but RATIONAL
> itself is bool. Change it to tristate, so the rational fractions
> support code can be modular if no builtin code relies on it.

Works for me,
Reviewed-by: Andy Shevchenko <andriy.s...@linux.intel.com>
Reply all
Reply to author
Forward
0 new messages