From: Gleb C. <lna...@ya...> - 2023-10-10 12:11:26
|
Commit: 12fd0ea GitHub URL: https://github.com/SCST-project/scst/commit/12fd0ea93e3164d21aba5e5abe1a2596cacbfd0b Author: Gleb Chesnokov Date: 2023-10-10T15:10:02+03:00 Log Message: ----------- 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. Modified Paths: -------------- scst/include/backport.h | 34 +++++++++++++++ 1 file changed, 34 insertions(+) =================================================================== diff --git a/scst/include/backport.h b/scst/include/backport.h index 9691bdd..56d25e4 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -31,6 +31,7 @@ #include <linux/blk-mq.h> #endif #include <linux/bsg-lib.h> /* struct bsg_job */ +#include <linux/debugfs.h> #include <linux/dmapool.h> #include <linux/eventpoll.h> #include <linux/iocontext.h> @@ -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 + /* <linux/device.h> */ #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) |