lkml.org 
[lkml]   [2024]   [Apr]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 1/4] x86/cpu: Add and use new CPUID region helper
Date
On Tue, 2024-04-02 at 10:13 -0700, Dave Hansen wrote:
> On 3/25/24 05:24, Huang, Kai wrote:
> >
> > Nit:
> >
> > > +
> > > +/* Returns true if the leaf exists and @value was populated */
> >
> > ^ is ?
>
> It's a subtle difference, but I think it's better as I wrote it.
> Returning true happens *after* the value _was_ populated.
>
> > > +static inline bool get_cpuid_region_leaf(u32 leaf, enum cpuid_regs_idx reg,
> > > + u32 *value)
> > > +{
> > > + u16 region = leaf >> 16;
> > > + u32 regs[4];
> > > +
> > > + if (cpuid_region_max_leaf(region) < leaf)
> > > + return false;
> > > +
> > > + cpuid(leaf, &regs[CPUID_EAX], &regs[CPUID_EBX],
> > > + &regs[CPUID_ECX], &regs[CPUID_EDX]);
> > > +
> > > + *value = regs[reg];
> > > +
> > > + return true;
> > > +}
> >
> > I found despite the get_cpuid_region_leaf() returns true/false, the return value
> > is never used in this series. Instead, this series uses below pattern:
> >
> > u32 data = 0; /* explicit initialization */
> >
> > get_cpuid_region_leaf(leaf, ..., &data);
> >
> > Which kinda implies the 'data' won't be touched if the requested leaf isn't
> > supported I suppose?
> >
> > Since the return value is never used, should we consider just making this
> > function void?
>
> I certainly considered it.
>
> But I do think that get_cpuid_region_leaf() looks a lot more obviously
> correct and useful when it explicitly returns what it did, even if the
> existing callers don't take advantage of it.
>
> I suspect it generates the same code either way.

Agreed:

Reviewed-by: Kai Huang <kai.huang@intel.com>
\
 
 \ /
  Last update: 2024-05-27 16:20    [W:0.057 / U:0.304 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site