lkml.org 
[lkml]   [2022]   [May]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 3/3] net: mdio: mdio-thunder: support for clock-freq attribute
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...

\
 
 \ /
  Last update: 2022-06-01 05:57    [W:1.006 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site