Skip to contentSkip to conversation

drm/xe/configfs: Allow to select by class only

bug report Dan Carpenter 2 participants 2 messages Sep 23, 2025

lore
Share & tools
lore
#0 lore raw

Hello Lucas De Marchi,

Commit e2a9854d806e ("drm/xe/configfs: Allow to select by class only") from Sep 16, 2025 (linux-next), leads to the following Smatch static checker warning:

drivers/gpu/drm/xe/xe_configfs.c:331 lookup_engine_info()
error: we previously assumed 'mask' could be null (see line 327)

drivers/gpu/drm/xe/xe_configfs.c

    317 static const struct engine_info *lookup_engine_info(const char *pattern, u64 *mask)
    318 {
    319         for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) {
    320                 u8 instance;
    321                 u16 bit;
    322 
    323                 if (!str_has_prefix(pattern, engine_info[i].cls))
    324                         continue;
    325 
    326                 pattern += strlen(engine_info[i].cls);
    327                 if (!mask && !*pattern)
                                  ^^

Presumably this should be || instead of &&. If mask is NULL the function can't succeed.

    328                         return &engine_info[i];
    329 
    330                 if (!strcmp(pattern, "*")) {
--> 331                         *mask = engine_info[i].mask;
    332                         return &engine_info[i];
    333                 }
    334 
    335                 if (kstrtou8(pattern, 10, &instance))
    336                         return NULL;
    337 
    338                 bit = __ffs64(engine_info[i].mask) + instance;
    339                 if (bit >= fls64(engine_info[i].mask))
    340                         return NULL;
    341 
    342                 *mask = BIT_ULL(bit);
    343                 return &engine_info[i];
    344         }
    345 
    346         return NULL;
    347 }

regards,
dan carpenter

#1 lore raw
Quoted 22 lines · Dan Carpenter

Hello Lucas De Marchi,

Commit e2a9854d806e ("drm/xe/configfs: Allow to select by class only") from Sep 16, 2025 (linux-next), leads to the following Smatch static checker warning:

drivers/gpu/drm/xe/xe_configfs.c:331 lookup_engine_info()
error: we previously assumed 'mask' could be null (see line 327)

drivers/gpu/drm/xe/xe_configfs.c
317 static const struct engine_info *lookup_engine_info(const char *pattern, u64 *mask)

   318 {
   319         for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) {
   320                 u8 instance;
   321                 u16 bit;
   322
   323                 if (!str_has_prefix(pattern, engine_info[i].cls))
   324                         continue;
   325
   326                 pattern += strlen(engine_info[i].cls);
   327                 if (!mask && !*pattern)
                                 ^^
Quoted 2 lines

Presumably this should be || instead of &&. If mask is NULL the function can't succeed.

adding || here would create 2 other bugs, but yes, there's a bug here
fixed by https://lore.kernel.org/intel-xe/[email protected]/
I will probably merge that later today.

thanks
Lucas De Marchi

Quoted 24 lines
   328                         return &engine_info[i];
   329
   330                 if (!strcmp(pattern, "*")) {
--> 331                         *mask = engine_info[i].mask;
   332                         return &engine_info[i];
   333                 }
   334
   335                 if (kstrtou8(pattern, 10, &instance))
   336                         return NULL;
   337
   338                 bit = __ffs64(engine_info[i].mask) + instance;
   339                 if (bit >= fls64(engine_info[i].mask))
   340                         return NULL;
   341
   342                 *mask = BIT_ULL(bit);
   343                 return &engine_info[i];
   344         }
   345
   346         return NULL;
   347 }

regards,
dan carpenter