[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 02/47] x86/tsc: Add a standalone helpers for getting TSC info from CPUID.0x15



On Mon, Jun 01, 2026, Borislav Petkov wrote:
> On Fri, May 29, 2026 at 07:43:49AM -0700, Sean Christopherson wrote:
> > +static int cpuid_get_tsc_info(struct cpuid_tsc_info *info)
> > +{
> > +   unsigned int ecx_hz, edx;
> > +
> > +   memset(info, 0, sizeof(*info));
> 
> Let's not clear this unnecessarily...
> 
> > +
> > +   if (boot_cpu_data.cpuid_level < CPUID_LEAF_TSC)
> > +           return -ENOENT;
> 
> ... just to return here...
> 
> > +
> > +   /* CPUID 15H TSC/Crystal ratio, plus optionally Crystal Hz */
> > +   cpuid(CPUID_LEAF_TSC, &info->denominator, &info->numerator, &ecx_hz, 
> > &edx);
> > +
> > +   if (!info->denominator || !info->numerator)
> > +           return -ENOENT;
> 
> ... or here.
> 
> We wanna clear it here, when we'll return success.

Actually, if we take the approach of relying on the user to check the return
code, then there's no need to zero the struct since all fields will be 
explicitly
written, especially if we drop the "tsc_khz" field.  I was zeroing the field
purely as defense in depth.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.