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.
This commit is contained in:
Gleb Chesnokov
2023-10-01 20:16:17 +03:00
parent 6552b55c22
commit 12fd0ea93e

View File

@@ -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)