Re: [PATCH 2/2] math: rational: add a KUnit case for a semi-convergent term above LONG_MAX

From: Trent Piepho

Date: Tue Dec 01 2026 - 13:54:56 EST


On Tue, Dec 1, 2026 at 4:46 AM Joel Cruz Cabrera <tf.joel.work@xxxxxxxxx> wrote:
>
> Add a case where the best semi-convergent term is ULONG_MAX - 1, which
> made "2u * t" overflow before the previous patch: for 1/ULONG_MAX with
> max_denominator = ULONG_MAX - 1, the closest fraction is
> 1/(ULONG_MAX - 1), not 0/1. The case is written with ULONG_MAX so that
> it covers both 32-bit and 64-bit kernels.
>
> This test was written with the help of an AI assistant (Claude, by
> Anthropic); I reviewed it.

Your AI is finding "bugs" that will never be triggered.

This function is used to find integer ratios for the PLLs that fit
into 6, 8, 10, etc. bits. However many bits the PLL has. There is
nowhere in the kernel that a max_denominator larger than 32 bits is
ever going to be used. I doubt there's an existing callsite with a
larger than 16 bit value. The code could be kept faster and smaller
by just documenting the max_denominator should be <= UINT_MAX, a
restriction that will affect no one.

Values larger than 63 bits, like these, are even more unrealistic.
The entire point of this function, which the AI totally missed, is to
*reduce* the number of bits it takes to represent a rational fraction.
If the input is 64 bits and the output is also 64 bits, then it's
pointless to even call it.