crypto: hisilicon/debugfs - Fix the processing logic issue in the debugfs creation
authorChenghai Huang <huangchenghai2@huawei.com>
Sun, 7 Apr 2024 07:59:55 +0000 (15:59 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 12 Apr 2024 07:07:52 +0000 (15:07 +0800)
There is a scenario where the file directory is created but the
file attribute is not set. In this case, if a user accesses the
file, an error occurs.

So adjust the processing logic in the debugfs creation to
prevent the file from being accessed before the file attributes
such as the index are set.

Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/hisilicon/debugfs.c

index 6351a452878ddd567a3cbdda963df9766b471cfe..e9fa42381242ef0f993b528507be72f5cc719f4d 100644 (file)
@@ -1090,12 +1090,12 @@ static void qm_create_debugfs_file(struct hisi_qm *qm, struct dentry *dir,
 {
        struct debugfs_file *file = qm->debug.files + index;
 
-       debugfs_create_file(qm_debug_file_name[index], 0600, dir, file,
-                           &qm_debug_fops);
-
        file->index = index;
        mutex_init(&file->lock);
        file->debug = &qm->debug;
+
+       debugfs_create_file(qm_debug_file_name[index], 0600, dir, file,
+                           &qm_debug_fops);
 }
 
 static int qm_debugfs_atomic64_set(void *data, u64 val)