[PATCH 3/3] powerpc: Check only single values are passed to CPU/MMU feature checks
Michael Ellerman
mpe at ellerman.id.au
Fri May 10 16:45:37 AEST 2024
Segher Boessenkool <segher at kernel.crashing.org> writes:
> On Thu, May 09, 2024 at 10:12:48PM +1000, Michael Ellerman wrote:
>> cpu_has_feature()/mmu_has_feature() are only able to check a single
>> feature at a time, but there is no enforcement of that.
>>
>> In fact, as fixed in the previous commit, there was code that was
>> passing multiple values to cpu_has_feature().
>>
>> So add a check that only a single feature is passed using popcount.
>>
>> Note that the test allows 0 or 1 bits to be set, because some code
>> relies on cpu_has_feature(0) being false, the check with
>> CPU_FTRS_POSSIBLE ensures that. See for example CPU_FTR_PPC_LE.
>
> This btw is exactly
>
> BUILD_BUG_ON(feature & (feature - 1));
>
> but the popcount is more readable :-)
Yeah for those of us who don't see bits cascading in our sleep I think
the popcount is easier to understand ;)
cheers
More information about the Linuxppc-dev
mailing list