Hello Zhu Lingshan,

Commit 325de6bf3328 ("drm/amdkfd: expose pasid of secondary contexts
by debugfs") from Jul 1, 2026 (linux-next), leads to the following
Smatch static checker warning:

        drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_debugfs.c:215 
kfd_debugfs_add_process()
        warn: 'entry->proc_dentry' is an error pointer or valid

drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_debugfs.c
    174 int kfd_debugfs_add_process(struct kfd_process *p)
    175 {
    176         struct debugfs_proc_entry *primary_entry;
    177         char name[MAX_DEBUGFS_FILENAME_LEN];
    178         struct kfd_process *primary_process;
    179         struct debugfs_proc_entry *entry;
    180         int ret;
    181 
    182         entry = kzalloc_obj(*entry);
    183         if (!entry)
    184                 return -ENOMEM;
    185 
    186         entry->process = p;
    187         entry->pid = p->lead_thread->pid;
    188 
    189         if (p->context_id == KFD_CONTEXT_ID_PRIMARY) {
    190                 snprintf(name, MAX_DEBUGFS_FILENAME_LEN, "%d",
    191                          (int)entry->pid);
    192                 entry->proc_dentry = debugfs_create_dir(name, 
debugfs_proc);
    193         } else {
    194                 primary_process = 
kfd_lookup_process_by_mm(p->lead_thread->mm);
    195                 if (!primary_process) {
    196                         ret = -ESRCH;
    197                         goto err_free_entry;
    198                 }
    199 
    200                 primary_entry = 
kfd_debugfs_find_process_entry(primary_process);
    201                 kfd_unref_process(primary_process);
    202                 if (!primary_entry) {
    203                         pr_warn("Failed to find the primary debugfs 
entry for pid %d\n",
    204                                 entry->pid);
    205                         ret = -ENOENT;
    206                         goto err_free_entry;
    207                 }
    208 
    209                 snprintf(name, MAX_DEBUGFS_FILENAME_LEN, "context_%u",
    210                          p->context_id);
    211                 entry->proc_dentry = debugfs_create_dir(name,
    212                                                         
primary_entry->proc_dentry);
    213         }
    214         if (IS_ERR_OR_NULL(entry->proc_dentry)) {
--> 215                 ret = entry->proc_dentry ? PTR_ERR(entry->proc_dentry) 
: -ENOMEM;
    216                 goto err_free_entry;

This check should just be deleted.
https://staticthinking.wordpress.com/2023/07/24/debugfs-functions-are-not-supposed-to-be-checked/

    217         }
    218 
    219         list_add(&entry->list, &procs);
    220         kfd_debugfs_create_pasid_files(p, entry->proc_dentry);
    221 
    222         return 0;
    223 
    224 err_free_entry:
    225         kfree(entry);
    226         return ret;
    227 }

This email is a free service from the Smatch-CI project [smatch.sf.net].

regards,
dan carpenter

Reply via email to