cast to unsigned char before toupper in cache size parser#420
Conversation
|
Hi @soma0212! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
fbarchard
left a comment
There was a problem hiding this comment.
makes sense. its good there is a comment above showing (e.g. "2048K", "1M")
for context. Makes me think the default
uint32_t multiplier = 1024;
should really be '1' and check for 'K' the same way.
or just expect it to be upper case. when I check my linux workstation it says
more /sys/devices/system/cpu/cpu0/cache/index0/size
32K
pixel2 android device is
adb shell more /sys/devices/system/cpu/cpu0/cache/index0/size
32K
|
Right, the generic cacheinfo driver formats this value as "%uK" (size_show in drivers/base/cacheinfo.c), so on mainline kernels the suffix is always present and always uppercase, which lines up with what you're seeing on both your boxes. That means the KB default and the toupper only matter for vendor kernels that stray from that, and treating a bare number as KB has been this parser's behavior all along. I kept this PR to just the cast so it fixes the UB without changing behavior on any input, but happy to switch to multiplier = 1 with an explicit 'K' check in a follow-up if you'd prefer that shape. |
toupper() in cache_size_parser gets a plain char, which is signed on the ARM/Android targets this file builds for: