Thanks for the review,

On 2024-07-01 at 18:04:00 +0200, Luck, Tony wrote:
>+static bool cpus_offline_empty(void)
>+{
>+      char offline_cpus_str[64];
>+      FILE *fp;
>+
>+      fp = fopen("/sys/devices/system/cpu/offline", "r");
>
>Check for fp == NULL before using it.

Thanks, will add it.

>
>+      if (fscanf(fp, "%s", offline_cpus_str) < 0) {
>
>fscanf() seems like a heavy hammer.
>
>       if (fgets(offline_cpus_str, sizeof(offline_cpus_str), fp) == NULL) {
>+              if (!errno) {
>
>Don't need an errno check (seems dubious mixing errno with stdio).

fscanf() returns "-1" when nothing was read as well as if there was an error.
But when nothing was read the errno is "0" instead of some error code so I could
differentiate the cases that way. The fgetc() you settled on shouldn't have this
problem.

>
>+                      fclose(fp);
>+                      return 1;
>
>                       return true;
>
>+              }
>+              ksft_perror("Could not read offline CPUs file!");
>+      }
>+
>+      fclose(fp);
>+
>+      return 0;
>
>       return false;
>+}
>

-- 
Kind regards
Maciej Wieczór-Retman

Reply via email to