Hi Reinette,
On 12/10/2025 7:02 AM, Reinette Chatre wrote:
I suggest this be simplified to not have the vendor ID be used both as a value and as a state. Here is some pseudo-code that should be able to accomplish this:
unsigned int detect_vendor(void) { static bool initialized = false; static unsigned int vendor_id; ... FILE *inf;
if (initialized) return vendor_id; inf = fopen("/proc/cpuinfo", "r"); if (!inf) { vendor_id = 0; initialized = true; return vendor_id; } /* initialize vendor_id from /proc/cpuinfo */ initialized = true; return vendor_id;}
unsigned int get_vendor(void) { unsigned int vendor; vendor = detect_vendor();
if (vendor == 0) ksft_print_msg(...); return vendor;}
Reinette
Thank you very much! I will make the change in v3 patch series.
Could you help review the revised patch description for the change? -------------------------------- ... and makes it obvious when adding new vendor IDs.
Accordingly, update the return types of detect_vendor() and get_vendor() from 'int' to 'unsigned int' to align with their usage as bitmask values and to prevent potentially risky type conversions.
Furthermore, introduce a bool flag 'initialized' to simplify the get_vendor() -> detect_vendor() logic. This ensures the vendor ID is detected only once and resolves the ambiguity of using the same variable 'vendor' both as a value and as a state.
--------------------------------
Thank you!
Best regards, Xiaochen Shen