From 12fd0ea93e3164d21aba5e5abe1a2596cacbfd0b Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Sun, 1 Oct 2023 20:16:17 +0300 Subject: [PATCH] scst/include/backport.h: Backport some debugfs functions Support the previous commit against kernel versions before v5.0. See also commit ff9fb72bc077 ("debugfs: return error values, not NULL") # v5.0. --- scst/include/backport.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/scst/include/backport.h b/scst/include/backport.h index 9691bddfd..56d25e4ee 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -31,6 +31,7 @@ #include #endif #include /* struct bsg_job */ +#include #include #include #include @@ -385,6 +386,39 @@ static inline ssize_t debugfs_attr_write(struct file *file, } #endif +/* + * See also commit ff9fb72bc077 ("debugfs: return error values, + * not NULL") # v5.0. + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0) +static inline struct dentry *debugfs_create_dir_backport(const char *name, struct dentry *parent) +{ + struct dentry *dentry; + + dentry = debugfs_create_dir(name, parent); + if (!dentry) + return ERR_PTR(-ENOMEM); + + return dentry; +} + +static inline struct dentry *debugfs_create_file_backport(const char *name, umode_t mode, + struct dentry *parent, void *data, + const struct file_operations *fops) +{ + struct dentry *dentry; + + dentry = debugfs_create_file(name, mode, parent, data, fops); + if (!dentry) + return ERR_PTR(-ENOMEM); + + return dentry; +} + +#define debugfs_create_dir debugfs_create_dir_backport +#define debugfs_create_file debugfs_create_file_backport +#endif + /* */ #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)