[LTP] [PATCH v6] high_freq_hwp_cap_cppc.c: new test
Kubaj, Piotr
piotr.kubaj@intel.com
Mon Mar 30 13:58:39 CEST 2026
2026-03-25 (水) の 12:24 +0000 に Andrea Cervesato さんは書きました:
> Hi Piotr,
>
> Thanks for the new test. A few issues below.
>
> > +/*
> > + * Copyright (C) 2026 Intel - http://www.intel.com/
> > + */
>
> The copyright line should include an author name and email, e.g.:
>
> Copyright (c) 2026 Piotr Kubaj <piotr.kubaj@intel.com>
>
> > + if (i)
> > + SAFE_FILE_SCANF(path, "%d", &online);
>
> SAFE_FILE_SCANF with "%d" expects a pointer to int, but `online` is
> bool (typically 1 byte). This is undefined behavior and will likely
> corrupt the stack on little-endian. Please use `int online = 1;`
> instead.
>
> This should be spotted by any static analyzer or clangd..and even
> gcc shows this error.
For the record:
GCC does NOT print a warning while compiling that code. At least with
the default set of options when building on Debian 13 with stock GCC
14.2.0.
>
> > + snprintf(path, sizeof(path), "/dev/cpu/%d/msr",
> > i);
> > + int fd = SAFE_OPEN(path, O_RDONLY);
> > +
> > + SAFE_PREAD(1, fd, &msr_highest_perf,
> > sizeof(msr_highest_perf), 0x771);
>
> SAFE_CLOSE(fd) right after it has been used. There's no need to keep
> it
> open after pread().
>
> > + msr_highest_perf &= (1ULL << 8) - 1;
>
> 0x771 and the 8-bit mask are magic numbers. Named defines would
> help readability, e.g.:
>
> #define MSR_HWP_CAPABILITIES 0x771
> #define HIGHEST_PERF_MASK 0xFF
>
> The test fails because msr device is not available, so you need:
>
> .needs_drivers = (const char *const [])
> {
>
>
> "msr",
>
>
>
> NULL
>
>
> },
>
> And probably the CONFIG_X86_MSR=y check as well.
>
> Regards,
> --
> Andrea Cervesato
> SUSE QE Automation Engineer Linux
> andrea.cervesato@suse.com
---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.
Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
More information about the ltp
mailing list