Subject: Re: [PATCH v2 3/3] net: mdio: mdio-thunder: support for clock-freq attribute

From: Jakub Kicinski <[email-masked]>
Date: Tue, 31 May 2022 20:56:22 -0700

On Mon, 30 May 2022 05:53:28 -0700 Piyush Malgujar wrote:
> +static inline u32 clk_freq(u32 phase)
> +{
> +	return (100000000U / (2 * (phase)));
> +}
> +
> +static inline u32 calc_sample(u32 phase)

Please drop the inline keyword, the compiler will inline this anyway
and static inline prevents unused code warnings.

> +{
> +	return (2 * (phase) - 3);

No need to wrap arguments to a static inline in brackets.

> +}
> +
> +static u32 _config_clk(u32 req_freq, u32 *phase, u32 *sample)
> +{
> +	unsigned int p;
> +	u32 freq = 0, freq_prev;

It's customary in networking to order variable decl lines longest
to shortest.

> +	for (p = PHASE_MIN; p < PHASE_DFLT; p++) {
> +		freq_prev = freq;
> +		freq = clk_freq(p);
> +
> +		if (req_freq >= freq)
> +			break;
> +	}
> +
> +	if (p == PHASE_DFLT)
> +		freq = clk_freq(PHASE_DFLT);
> +
> +	if (p == PHASE_MIN || p == PHASE_DFLT)
> +		goto out;
> +
> +	/* Check which clock value from the identified range
> +	 * is closer to the requested value
> +	 */
> +	if ((freq_prev - req_freq) < (req_freq - freq)) {

No need for brackets around the arithmetic, assume basic operator
precedence is not broken in the compiler...