Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  file.c - part of debugfs, a tiny little debug file system
0004  *
0005  *  Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
0006  *  Copyright (C) 2004 IBM Inc.
0007  *
0008  *  debugfs is for people to use instead of /proc or /sys.
0009  *  See Documentation/filesystems/ for more details.
0010  */
0011 
0012 #include <linux/module.h>
0013 #include <linux/fs.h>
0014 #include <linux/seq_file.h>
0015 #include <linux/pagemap.h>
0016 #include <linux/debugfs.h>
0017 #include <linux/io.h>
0018 #include <linux/slab.h>
0019 #include <linux/atomic.h>
0020 #include <linux/device.h>
0021 #include <linux/pm_runtime.h>
0022 #include <linux/poll.h>
0023 #include <linux/security.h>
0024 
0025 #include "internal.h"
0026 
0027 struct poll_table_struct;
0028 
0029 static ssize_t default_read_file(struct file *file, char __user *buf,
0030                  size_t count, loff_t *ppos)
0031 {
0032     return 0;
0033 }
0034 
0035 static ssize_t default_write_file(struct file *file, const char __user *buf,
0036                    size_t count, loff_t *ppos)
0037 {
0038     return count;
0039 }
0040 
0041 const struct file_operations debugfs_noop_file_operations = {
0042     .read =     default_read_file,
0043     .write =    default_write_file,
0044     .open =     simple_open,
0045     .llseek =   noop_llseek,
0046 };
0047 
0048 #define F_DENTRY(filp) ((filp)->f_path.dentry)
0049 
0050 const struct file_operations *debugfs_real_fops(const struct file *filp)
0051 {
0052     struct debugfs_fsdata *fsd = F_DENTRY(filp)->d_fsdata;
0053 
0054     if ((unsigned long)fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT) {
0055         /*
0056          * Urgh, we've been called w/o a protecting
0057          * debugfs_file_get().
0058          */
0059         WARN_ON(1);
0060         return NULL;
0061     }
0062 
0063     return fsd->real_fops;
0064 }
0065 EXPORT_SYMBOL_GPL(debugfs_real_fops);
0066 
0067 /**
0068  * debugfs_file_get - mark the beginning of file data access
0069  * @dentry: the dentry object whose data is being accessed.
0070  *
0071  * Up to a matching call to debugfs_file_put(), any successive call
0072  * into the file removing functions debugfs_remove() and
0073  * debugfs_remove_recursive() will block. Since associated private
0074  * file data may only get freed after a successful return of any of
0075  * the removal functions, you may safely access it after a successful
0076  * call to debugfs_file_get() without worrying about lifetime issues.
0077  *
0078  * If -%EIO is returned, the file has already been removed and thus,
0079  * it is not safe to access any of its data. If, on the other hand,
0080  * it is allowed to access the file data, zero is returned.
0081  */
0082 int debugfs_file_get(struct dentry *dentry)
0083 {
0084     struct debugfs_fsdata *fsd;
0085     void *d_fsd;
0086 
0087     d_fsd = READ_ONCE(dentry->d_fsdata);
0088     if (!((unsigned long)d_fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT)) {
0089         fsd = d_fsd;
0090     } else {
0091         fsd = kmalloc(sizeof(*fsd), GFP_KERNEL);
0092         if (!fsd)
0093             return -ENOMEM;
0094 
0095         fsd->real_fops = (void *)((unsigned long)d_fsd &
0096                     ~DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
0097         refcount_set(&fsd->active_users, 1);
0098         init_completion(&fsd->active_users_drained);
0099         if (cmpxchg(&dentry->d_fsdata, d_fsd, fsd) != d_fsd) {
0100             kfree(fsd);
0101             fsd = READ_ONCE(dentry->d_fsdata);
0102         }
0103     }
0104 
0105     /*
0106      * In case of a successful cmpxchg() above, this check is
0107      * strictly necessary and must follow it, see the comment in
0108      * __debugfs_remove_file().
0109      * OTOH, if the cmpxchg() hasn't been executed or wasn't
0110      * successful, this serves the purpose of not starving
0111      * removers.
0112      */
0113     if (d_unlinked(dentry))
0114         return -EIO;
0115 
0116     if (!refcount_inc_not_zero(&fsd->active_users))
0117         return -EIO;
0118 
0119     return 0;
0120 }
0121 EXPORT_SYMBOL_GPL(debugfs_file_get);
0122 
0123 /**
0124  * debugfs_file_put - mark the end of file data access
0125  * @dentry: the dentry object formerly passed to
0126  *          debugfs_file_get().
0127  *
0128  * Allow any ongoing concurrent call into debugfs_remove() or
0129  * debugfs_remove_recursive() blocked by a former call to
0130  * debugfs_file_get() to proceed and return to its caller.
0131  */
0132 void debugfs_file_put(struct dentry *dentry)
0133 {
0134     struct debugfs_fsdata *fsd = READ_ONCE(dentry->d_fsdata);
0135 
0136     if (refcount_dec_and_test(&fsd->active_users))
0137         complete(&fsd->active_users_drained);
0138 }
0139 EXPORT_SYMBOL_GPL(debugfs_file_put);
0140 
0141 /*
0142  * Only permit access to world-readable files when the kernel is locked down.
0143  * We also need to exclude any file that has ways to write or alter it as root
0144  * can bypass the permissions check.
0145  */
0146 static int debugfs_locked_down(struct inode *inode,
0147                    struct file *filp,
0148                    const struct file_operations *real_fops)
0149 {
0150     if ((inode->i_mode & 07777 & ~0444) == 0 &&
0151         !(filp->f_mode & FMODE_WRITE) &&
0152         !real_fops->unlocked_ioctl &&
0153         !real_fops->compat_ioctl &&
0154         !real_fops->mmap)
0155         return 0;
0156 
0157     if (security_locked_down(LOCKDOWN_DEBUGFS))
0158         return -EPERM;
0159 
0160     return 0;
0161 }
0162 
0163 static int open_proxy_open(struct inode *inode, struct file *filp)
0164 {
0165     struct dentry *dentry = F_DENTRY(filp);
0166     const struct file_operations *real_fops = NULL;
0167     int r;
0168 
0169     r = debugfs_file_get(dentry);
0170     if (r)
0171         return r == -EIO ? -ENOENT : r;
0172 
0173     real_fops = debugfs_real_fops(filp);
0174 
0175     r = debugfs_locked_down(inode, filp, real_fops);
0176     if (r)
0177         goto out;
0178 
0179     if (!fops_get(real_fops)) {
0180 #ifdef CONFIG_MODULES
0181         if (real_fops->owner &&
0182             real_fops->owner->state == MODULE_STATE_GOING) {
0183             r = -ENXIO;
0184             goto out;
0185         }
0186 #endif
0187 
0188         /* Huh? Module did not clean up after itself at exit? */
0189         WARN(1, "debugfs file owner did not clean up at exit: %pd",
0190             dentry);
0191         r = -ENXIO;
0192         goto out;
0193     }
0194     replace_fops(filp, real_fops);
0195 
0196     if (real_fops->open)
0197         r = real_fops->open(inode, filp);
0198 
0199 out:
0200     debugfs_file_put(dentry);
0201     return r;
0202 }
0203 
0204 const struct file_operations debugfs_open_proxy_file_operations = {
0205     .open = open_proxy_open,
0206 };
0207 
0208 #define PROTO(args...) args
0209 #define ARGS(args...) args
0210 
0211 #define FULL_PROXY_FUNC(name, ret_type, filp, proto, args)      \
0212 static ret_type full_proxy_ ## name(proto)              \
0213 {                                   \
0214     struct dentry *dentry = F_DENTRY(filp);         \
0215     const struct file_operations *real_fops;            \
0216     ret_type r;                         \
0217                                     \
0218     r = debugfs_file_get(dentry);                   \
0219     if (unlikely(r))                        \
0220         return r;                       \
0221     real_fops = debugfs_real_fops(filp);                \
0222     r = real_fops->name(args);                  \
0223     debugfs_file_put(dentry);                   \
0224     return r;                           \
0225 }
0226 
0227 FULL_PROXY_FUNC(llseek, loff_t, filp,
0228         PROTO(struct file *filp, loff_t offset, int whence),
0229         ARGS(filp, offset, whence));
0230 
0231 FULL_PROXY_FUNC(read, ssize_t, filp,
0232         PROTO(struct file *filp, char __user *buf, size_t size,
0233             loff_t *ppos),
0234         ARGS(filp, buf, size, ppos));
0235 
0236 FULL_PROXY_FUNC(write, ssize_t, filp,
0237         PROTO(struct file *filp, const char __user *buf, size_t size,
0238             loff_t *ppos),
0239         ARGS(filp, buf, size, ppos));
0240 
0241 FULL_PROXY_FUNC(unlocked_ioctl, long, filp,
0242         PROTO(struct file *filp, unsigned int cmd, unsigned long arg),
0243         ARGS(filp, cmd, arg));
0244 
0245 static __poll_t full_proxy_poll(struct file *filp,
0246                 struct poll_table_struct *wait)
0247 {
0248     struct dentry *dentry = F_DENTRY(filp);
0249     __poll_t r = 0;
0250     const struct file_operations *real_fops;
0251 
0252     if (debugfs_file_get(dentry))
0253         return EPOLLHUP;
0254 
0255     real_fops = debugfs_real_fops(filp);
0256     r = real_fops->poll(filp, wait);
0257     debugfs_file_put(dentry);
0258     return r;
0259 }
0260 
0261 static int full_proxy_release(struct inode *inode, struct file *filp)
0262 {
0263     const struct dentry *dentry = F_DENTRY(filp);
0264     const struct file_operations *real_fops = debugfs_real_fops(filp);
0265     const struct file_operations *proxy_fops = filp->f_op;
0266     int r = 0;
0267 
0268     /*
0269      * We must not protect this against removal races here: the
0270      * original releaser should be called unconditionally in order
0271      * not to leak any resources. Releasers must not assume that
0272      * ->i_private is still being meaningful here.
0273      */
0274     if (real_fops->release)
0275         r = real_fops->release(inode, filp);
0276 
0277     replace_fops(filp, d_inode(dentry)->i_fop);
0278     kfree(proxy_fops);
0279     fops_put(real_fops);
0280     return r;
0281 }
0282 
0283 static void __full_proxy_fops_init(struct file_operations *proxy_fops,
0284                 const struct file_operations *real_fops)
0285 {
0286     proxy_fops->release = full_proxy_release;
0287     if (real_fops->llseek)
0288         proxy_fops->llseek = full_proxy_llseek;
0289     if (real_fops->read)
0290         proxy_fops->read = full_proxy_read;
0291     if (real_fops->write)
0292         proxy_fops->write = full_proxy_write;
0293     if (real_fops->poll)
0294         proxy_fops->poll = full_proxy_poll;
0295     if (real_fops->unlocked_ioctl)
0296         proxy_fops->unlocked_ioctl = full_proxy_unlocked_ioctl;
0297 }
0298 
0299 static int full_proxy_open(struct inode *inode, struct file *filp)
0300 {
0301     struct dentry *dentry = F_DENTRY(filp);
0302     const struct file_operations *real_fops = NULL;
0303     struct file_operations *proxy_fops = NULL;
0304     int r;
0305 
0306     r = debugfs_file_get(dentry);
0307     if (r)
0308         return r == -EIO ? -ENOENT : r;
0309 
0310     real_fops = debugfs_real_fops(filp);
0311 
0312     r = debugfs_locked_down(inode, filp, real_fops);
0313     if (r)
0314         goto out;
0315 
0316     if (!fops_get(real_fops)) {
0317 #ifdef CONFIG_MODULES
0318         if (real_fops->owner &&
0319             real_fops->owner->state == MODULE_STATE_GOING) {
0320             r = -ENXIO;
0321             goto out;
0322         }
0323 #endif
0324 
0325         /* Huh? Module did not cleanup after itself at exit? */
0326         WARN(1, "debugfs file owner did not clean up at exit: %pd",
0327             dentry);
0328         r = -ENXIO;
0329         goto out;
0330     }
0331 
0332     proxy_fops = kzalloc(sizeof(*proxy_fops), GFP_KERNEL);
0333     if (!proxy_fops) {
0334         r = -ENOMEM;
0335         goto free_proxy;
0336     }
0337     __full_proxy_fops_init(proxy_fops, real_fops);
0338     replace_fops(filp, proxy_fops);
0339 
0340     if (real_fops->open) {
0341         r = real_fops->open(inode, filp);
0342         if (r) {
0343             replace_fops(filp, d_inode(dentry)->i_fop);
0344             goto free_proxy;
0345         } else if (filp->f_op != proxy_fops) {
0346             /* No protection against file removal anymore. */
0347             WARN(1, "debugfs file owner replaced proxy fops: %pd",
0348                 dentry);
0349             goto free_proxy;
0350         }
0351     }
0352 
0353     goto out;
0354 free_proxy:
0355     kfree(proxy_fops);
0356     fops_put(real_fops);
0357 out:
0358     debugfs_file_put(dentry);
0359     return r;
0360 }
0361 
0362 const struct file_operations debugfs_full_proxy_file_operations = {
0363     .open = full_proxy_open,
0364 };
0365 
0366 ssize_t debugfs_attr_read(struct file *file, char __user *buf,
0367             size_t len, loff_t *ppos)
0368 {
0369     struct dentry *dentry = F_DENTRY(file);
0370     ssize_t ret;
0371 
0372     ret = debugfs_file_get(dentry);
0373     if (unlikely(ret))
0374         return ret;
0375     ret = simple_attr_read(file, buf, len, ppos);
0376     debugfs_file_put(dentry);
0377     return ret;
0378 }
0379 EXPORT_SYMBOL_GPL(debugfs_attr_read);
0380 
0381 ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
0382              size_t len, loff_t *ppos)
0383 {
0384     struct dentry *dentry = F_DENTRY(file);
0385     ssize_t ret;
0386 
0387     ret = debugfs_file_get(dentry);
0388     if (unlikely(ret))
0389         return ret;
0390     ret = simple_attr_write(file, buf, len, ppos);
0391     debugfs_file_put(dentry);
0392     return ret;
0393 }
0394 EXPORT_SYMBOL_GPL(debugfs_attr_write);
0395 
0396 static struct dentry *debugfs_create_mode_unsafe(const char *name, umode_t mode,
0397                     struct dentry *parent, void *value,
0398                     const struct file_operations *fops,
0399                     const struct file_operations *fops_ro,
0400                     const struct file_operations *fops_wo)
0401 {
0402     /* if there are no write bits set, make read only */
0403     if (!(mode & S_IWUGO))
0404         return debugfs_create_file_unsafe(name, mode, parent, value,
0405                         fops_ro);
0406     /* if there are no read bits set, make write only */
0407     if (!(mode & S_IRUGO))
0408         return debugfs_create_file_unsafe(name, mode, parent, value,
0409                         fops_wo);
0410 
0411     return debugfs_create_file_unsafe(name, mode, parent, value, fops);
0412 }
0413 
0414 static int debugfs_u8_set(void *data, u64 val)
0415 {
0416     *(u8 *)data = val;
0417     return 0;
0418 }
0419 static int debugfs_u8_get(void *data, u64 *val)
0420 {
0421     *val = *(u8 *)data;
0422     return 0;
0423 }
0424 DEFINE_DEBUGFS_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n");
0425 DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_ro, debugfs_u8_get, NULL, "%llu\n");
0426 DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_wo, NULL, debugfs_u8_set, "%llu\n");
0427 
0428 /**
0429  * debugfs_create_u8 - create a debugfs file that is used to read and write an unsigned 8-bit value
0430  * @name: a pointer to a string containing the name of the file to create.
0431  * @mode: the permission that the file should have
0432  * @parent: a pointer to the parent dentry for this file.  This should be a
0433  *          directory dentry if set.  If this parameter is %NULL, then the
0434  *          file will be created in the root of the debugfs filesystem.
0435  * @value: a pointer to the variable that the file should read to and write
0436  *         from.
0437  *
0438  * This function creates a file in debugfs with the given name that
0439  * contains the value of the variable @value.  If the @mode variable is so
0440  * set, it can be read from, and written to.
0441  */
0442 void debugfs_create_u8(const char *name, umode_t mode, struct dentry *parent,
0443                u8 *value)
0444 {
0445     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u8,
0446                    &fops_u8_ro, &fops_u8_wo);
0447 }
0448 EXPORT_SYMBOL_GPL(debugfs_create_u8);
0449 
0450 static int debugfs_u16_set(void *data, u64 val)
0451 {
0452     *(u16 *)data = val;
0453     return 0;
0454 }
0455 static int debugfs_u16_get(void *data, u64 *val)
0456 {
0457     *val = *(u16 *)data;
0458     return 0;
0459 }
0460 DEFINE_DEBUGFS_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n");
0461 DEFINE_DEBUGFS_ATTRIBUTE(fops_u16_ro, debugfs_u16_get, NULL, "%llu\n");
0462 DEFINE_DEBUGFS_ATTRIBUTE(fops_u16_wo, NULL, debugfs_u16_set, "%llu\n");
0463 
0464 /**
0465  * debugfs_create_u16 - create a debugfs file that is used to read and write an unsigned 16-bit value
0466  * @name: a pointer to a string containing the name of the file to create.
0467  * @mode: the permission that the file should have
0468  * @parent: a pointer to the parent dentry for this file.  This should be a
0469  *          directory dentry if set.  If this parameter is %NULL, then the
0470  *          file will be created in the root of the debugfs filesystem.
0471  * @value: a pointer to the variable that the file should read to and write
0472  *         from.
0473  *
0474  * This function creates a file in debugfs with the given name that
0475  * contains the value of the variable @value.  If the @mode variable is so
0476  * set, it can be read from, and written to.
0477  */
0478 void debugfs_create_u16(const char *name, umode_t mode, struct dentry *parent,
0479             u16 *value)
0480 {
0481     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u16,
0482                    &fops_u16_ro, &fops_u16_wo);
0483 }
0484 EXPORT_SYMBOL_GPL(debugfs_create_u16);
0485 
0486 static int debugfs_u32_set(void *data, u64 val)
0487 {
0488     *(u32 *)data = val;
0489     return 0;
0490 }
0491 static int debugfs_u32_get(void *data, u64 *val)
0492 {
0493     *val = *(u32 *)data;
0494     return 0;
0495 }
0496 DEFINE_DEBUGFS_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n");
0497 DEFINE_DEBUGFS_ATTRIBUTE(fops_u32_ro, debugfs_u32_get, NULL, "%llu\n");
0498 DEFINE_DEBUGFS_ATTRIBUTE(fops_u32_wo, NULL, debugfs_u32_set, "%llu\n");
0499 
0500 /**
0501  * debugfs_create_u32 - create a debugfs file that is used to read and write an unsigned 32-bit value
0502  * @name: a pointer to a string containing the name of the file to create.
0503  * @mode: the permission that the file should have
0504  * @parent: a pointer to the parent dentry for this file.  This should be a
0505  *          directory dentry if set.  If this parameter is %NULL, then the
0506  *          file will be created in the root of the debugfs filesystem.
0507  * @value: a pointer to the variable that the file should read to and write
0508  *         from.
0509  *
0510  * This function creates a file in debugfs with the given name that
0511  * contains the value of the variable @value.  If the @mode variable is so
0512  * set, it can be read from, and written to.
0513  */
0514 void debugfs_create_u32(const char *name, umode_t mode, struct dentry *parent,
0515             u32 *value)
0516 {
0517     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u32,
0518                    &fops_u32_ro, &fops_u32_wo);
0519 }
0520 EXPORT_SYMBOL_GPL(debugfs_create_u32);
0521 
0522 static int debugfs_u64_set(void *data, u64 val)
0523 {
0524     *(u64 *)data = val;
0525     return 0;
0526 }
0527 
0528 static int debugfs_u64_get(void *data, u64 *val)
0529 {
0530     *val = *(u64 *)data;
0531     return 0;
0532 }
0533 DEFINE_DEBUGFS_ATTRIBUTE(fops_u64, debugfs_u64_get, debugfs_u64_set, "%llu\n");
0534 DEFINE_DEBUGFS_ATTRIBUTE(fops_u64_ro, debugfs_u64_get, NULL, "%llu\n");
0535 DEFINE_DEBUGFS_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n");
0536 
0537 /**
0538  * debugfs_create_u64 - create a debugfs file that is used to read and write an unsigned 64-bit value
0539  * @name: a pointer to a string containing the name of the file to create.
0540  * @mode: the permission that the file should have
0541  * @parent: a pointer to the parent dentry for this file.  This should be a
0542  *          directory dentry if set.  If this parameter is %NULL, then the
0543  *          file will be created in the root of the debugfs filesystem.
0544  * @value: a pointer to the variable that the file should read to and write
0545  *         from.
0546  *
0547  * This function creates a file in debugfs with the given name that
0548  * contains the value of the variable @value.  If the @mode variable is so
0549  * set, it can be read from, and written to.
0550  */
0551 void debugfs_create_u64(const char *name, umode_t mode, struct dentry *parent,
0552             u64 *value)
0553 {
0554     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u64,
0555                    &fops_u64_ro, &fops_u64_wo);
0556 }
0557 EXPORT_SYMBOL_GPL(debugfs_create_u64);
0558 
0559 static int debugfs_ulong_set(void *data, u64 val)
0560 {
0561     *(unsigned long *)data = val;
0562     return 0;
0563 }
0564 
0565 static int debugfs_ulong_get(void *data, u64 *val)
0566 {
0567     *val = *(unsigned long *)data;
0568     return 0;
0569 }
0570 DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong, debugfs_ulong_get, debugfs_ulong_set,
0571             "%llu\n");
0572 DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong_ro, debugfs_ulong_get, NULL, "%llu\n");
0573 DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong_wo, NULL, debugfs_ulong_set, "%llu\n");
0574 
0575 /**
0576  * debugfs_create_ulong - create a debugfs file that is used to read and write
0577  * an unsigned long value.
0578  * @name: a pointer to a string containing the name of the file to create.
0579  * @mode: the permission that the file should have
0580  * @parent: a pointer to the parent dentry for this file.  This should be a
0581  *          directory dentry if set.  If this parameter is %NULL, then the
0582  *          file will be created in the root of the debugfs filesystem.
0583  * @value: a pointer to the variable that the file should read to and write
0584  *         from.
0585  *
0586  * This function creates a file in debugfs with the given name that
0587  * contains the value of the variable @value.  If the @mode variable is so
0588  * set, it can be read from, and written to.
0589  */
0590 void debugfs_create_ulong(const char *name, umode_t mode, struct dentry *parent,
0591               unsigned long *value)
0592 {
0593     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_ulong,
0594                    &fops_ulong_ro, &fops_ulong_wo);
0595 }
0596 EXPORT_SYMBOL_GPL(debugfs_create_ulong);
0597 
0598 DEFINE_DEBUGFS_ATTRIBUTE(fops_x8, debugfs_u8_get, debugfs_u8_set, "0x%02llx\n");
0599 DEFINE_DEBUGFS_ATTRIBUTE(fops_x8_ro, debugfs_u8_get, NULL, "0x%02llx\n");
0600 DEFINE_DEBUGFS_ATTRIBUTE(fops_x8_wo, NULL, debugfs_u8_set, "0x%02llx\n");
0601 
0602 DEFINE_DEBUGFS_ATTRIBUTE(fops_x16, debugfs_u16_get, debugfs_u16_set,
0603             "0x%04llx\n");
0604 DEFINE_DEBUGFS_ATTRIBUTE(fops_x16_ro, debugfs_u16_get, NULL, "0x%04llx\n");
0605 DEFINE_DEBUGFS_ATTRIBUTE(fops_x16_wo, NULL, debugfs_u16_set, "0x%04llx\n");
0606 
0607 DEFINE_DEBUGFS_ATTRIBUTE(fops_x32, debugfs_u32_get, debugfs_u32_set,
0608             "0x%08llx\n");
0609 DEFINE_DEBUGFS_ATTRIBUTE(fops_x32_ro, debugfs_u32_get, NULL, "0x%08llx\n");
0610 DEFINE_DEBUGFS_ATTRIBUTE(fops_x32_wo, NULL, debugfs_u32_set, "0x%08llx\n");
0611 
0612 DEFINE_DEBUGFS_ATTRIBUTE(fops_x64, debugfs_u64_get, debugfs_u64_set,
0613             "0x%016llx\n");
0614 DEFINE_DEBUGFS_ATTRIBUTE(fops_x64_ro, debugfs_u64_get, NULL, "0x%016llx\n");
0615 DEFINE_DEBUGFS_ATTRIBUTE(fops_x64_wo, NULL, debugfs_u64_set, "0x%016llx\n");
0616 
0617 /*
0618  * debugfs_create_x{8,16,32,64} - create a debugfs file that is used to read and write an unsigned {8,16,32,64}-bit value
0619  *
0620  * These functions are exactly the same as the above functions (but use a hex
0621  * output for the decimal challenged). For details look at the above unsigned
0622  * decimal functions.
0623  */
0624 
0625 /**
0626  * debugfs_create_x8 - create a debugfs file that is used to read and write an unsigned 8-bit value
0627  * @name: a pointer to a string containing the name of the file to create.
0628  * @mode: the permission that the file should have
0629  * @parent: a pointer to the parent dentry for this file.  This should be a
0630  *          directory dentry if set.  If this parameter is %NULL, then the
0631  *          file will be created in the root of the debugfs filesystem.
0632  * @value: a pointer to the variable that the file should read to and write
0633  *         from.
0634  */
0635 void debugfs_create_x8(const char *name, umode_t mode, struct dentry *parent,
0636                u8 *value)
0637 {
0638     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x8,
0639                    &fops_x8_ro, &fops_x8_wo);
0640 }
0641 EXPORT_SYMBOL_GPL(debugfs_create_x8);
0642 
0643 /**
0644  * debugfs_create_x16 - create a debugfs file that is used to read and write an unsigned 16-bit value
0645  * @name: a pointer to a string containing the name of the file to create.
0646  * @mode: the permission that the file should have
0647  * @parent: a pointer to the parent dentry for this file.  This should be a
0648  *          directory dentry if set.  If this parameter is %NULL, then the
0649  *          file will be created in the root of the debugfs filesystem.
0650  * @value: a pointer to the variable that the file should read to and write
0651  *         from.
0652  */
0653 void debugfs_create_x16(const char *name, umode_t mode, struct dentry *parent,
0654             u16 *value)
0655 {
0656     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x16,
0657                    &fops_x16_ro, &fops_x16_wo);
0658 }
0659 EXPORT_SYMBOL_GPL(debugfs_create_x16);
0660 
0661 /**
0662  * debugfs_create_x32 - create a debugfs file that is used to read and write an unsigned 32-bit value
0663  * @name: a pointer to a string containing the name of the file to create.
0664  * @mode: the permission that the file should have
0665  * @parent: a pointer to the parent dentry for this file.  This should be a
0666  *          directory dentry if set.  If this parameter is %NULL, then the
0667  *          file will be created in the root of the debugfs filesystem.
0668  * @value: a pointer to the variable that the file should read to and write
0669  *         from.
0670  */
0671 void debugfs_create_x32(const char *name, umode_t mode, struct dentry *parent,
0672             u32 *value)
0673 {
0674     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x32,
0675                    &fops_x32_ro, &fops_x32_wo);
0676 }
0677 EXPORT_SYMBOL_GPL(debugfs_create_x32);
0678 
0679 /**
0680  * debugfs_create_x64 - create a debugfs file that is used to read and write an unsigned 64-bit value
0681  * @name: a pointer to a string containing the name of the file to create.
0682  * @mode: the permission that the file should have
0683  * @parent: a pointer to the parent dentry for this file.  This should be a
0684  *          directory dentry if set.  If this parameter is %NULL, then the
0685  *          file will be created in the root of the debugfs filesystem.
0686  * @value: a pointer to the variable that the file should read to and write
0687  *         from.
0688  */
0689 void debugfs_create_x64(const char *name, umode_t mode, struct dentry *parent,
0690             u64 *value)
0691 {
0692     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x64,
0693                    &fops_x64_ro, &fops_x64_wo);
0694 }
0695 EXPORT_SYMBOL_GPL(debugfs_create_x64);
0696 
0697 
0698 static int debugfs_size_t_set(void *data, u64 val)
0699 {
0700     *(size_t *)data = val;
0701     return 0;
0702 }
0703 static int debugfs_size_t_get(void *data, u64 *val)
0704 {
0705     *val = *(size_t *)data;
0706     return 0;
0707 }
0708 DEFINE_DEBUGFS_ATTRIBUTE(fops_size_t, debugfs_size_t_get, debugfs_size_t_set,
0709             "%llu\n"); /* %llu and %zu are more or less the same */
0710 DEFINE_DEBUGFS_ATTRIBUTE(fops_size_t_ro, debugfs_size_t_get, NULL, "%llu\n");
0711 DEFINE_DEBUGFS_ATTRIBUTE(fops_size_t_wo, NULL, debugfs_size_t_set, "%llu\n");
0712 
0713 /**
0714  * debugfs_create_size_t - create a debugfs file that is used to read and write an size_t value
0715  * @name: a pointer to a string containing the name of the file to create.
0716  * @mode: the permission that the file should have
0717  * @parent: a pointer to the parent dentry for this file.  This should be a
0718  *          directory dentry if set.  If this parameter is %NULL, then the
0719  *          file will be created in the root of the debugfs filesystem.
0720  * @value: a pointer to the variable that the file should read to and write
0721  *         from.
0722  */
0723 void debugfs_create_size_t(const char *name, umode_t mode,
0724                struct dentry *parent, size_t *value)
0725 {
0726     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_size_t,
0727                    &fops_size_t_ro, &fops_size_t_wo);
0728 }
0729 EXPORT_SYMBOL_GPL(debugfs_create_size_t);
0730 
0731 static int debugfs_atomic_t_set(void *data, u64 val)
0732 {
0733     atomic_set((atomic_t *)data, val);
0734     return 0;
0735 }
0736 static int debugfs_atomic_t_get(void *data, u64 *val)
0737 {
0738     *val = atomic_read((atomic_t *)data);
0739     return 0;
0740 }
0741 DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get,
0742             debugfs_atomic_t_set, "%lld\n");
0743 DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_ro, debugfs_atomic_t_get, NULL,
0744             "%lld\n");
0745 DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set,
0746             "%lld\n");
0747 
0748 /**
0749  * debugfs_create_atomic_t - create a debugfs file that is used to read and
0750  * write an atomic_t value
0751  * @name: a pointer to a string containing the name of the file to create.
0752  * @mode: the permission that the file should have
0753  * @parent: a pointer to the parent dentry for this file.  This should be a
0754  *          directory dentry if set.  If this parameter is %NULL, then the
0755  *          file will be created in the root of the debugfs filesystem.
0756  * @value: a pointer to the variable that the file should read to and write
0757  *         from.
0758  */
0759 void debugfs_create_atomic_t(const char *name, umode_t mode,
0760                  struct dentry *parent, atomic_t *value)
0761 {
0762     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_atomic_t,
0763                    &fops_atomic_t_ro, &fops_atomic_t_wo);
0764 }
0765 EXPORT_SYMBOL_GPL(debugfs_create_atomic_t);
0766 
0767 ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
0768                    size_t count, loff_t *ppos)
0769 {
0770     char buf[2];
0771     bool val;
0772     int r;
0773     struct dentry *dentry = F_DENTRY(file);
0774 
0775     r = debugfs_file_get(dentry);
0776     if (unlikely(r))
0777         return r;
0778     val = *(bool *)file->private_data;
0779     debugfs_file_put(dentry);
0780 
0781     if (val)
0782         buf[0] = 'Y';
0783     else
0784         buf[0] = 'N';
0785     buf[1] = '\n';
0786     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
0787 }
0788 EXPORT_SYMBOL_GPL(debugfs_read_file_bool);
0789 
0790 ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
0791                 size_t count, loff_t *ppos)
0792 {
0793     bool bv;
0794     int r;
0795     bool *val = file->private_data;
0796     struct dentry *dentry = F_DENTRY(file);
0797 
0798     r = kstrtobool_from_user(user_buf, count, &bv);
0799     if (!r) {
0800         r = debugfs_file_get(dentry);
0801         if (unlikely(r))
0802             return r;
0803         *val = bv;
0804         debugfs_file_put(dentry);
0805     }
0806 
0807     return count;
0808 }
0809 EXPORT_SYMBOL_GPL(debugfs_write_file_bool);
0810 
0811 static const struct file_operations fops_bool = {
0812     .read =     debugfs_read_file_bool,
0813     .write =    debugfs_write_file_bool,
0814     .open =     simple_open,
0815     .llseek =   default_llseek,
0816 };
0817 
0818 static const struct file_operations fops_bool_ro = {
0819     .read =     debugfs_read_file_bool,
0820     .open =     simple_open,
0821     .llseek =   default_llseek,
0822 };
0823 
0824 static const struct file_operations fops_bool_wo = {
0825     .write =    debugfs_write_file_bool,
0826     .open =     simple_open,
0827     .llseek =   default_llseek,
0828 };
0829 
0830 /**
0831  * debugfs_create_bool - create a debugfs file that is used to read and write a boolean value
0832  * @name: a pointer to a string containing the name of the file to create.
0833  * @mode: the permission that the file should have
0834  * @parent: a pointer to the parent dentry for this file.  This should be a
0835  *          directory dentry if set.  If this parameter is %NULL, then the
0836  *          file will be created in the root of the debugfs filesystem.
0837  * @value: a pointer to the variable that the file should read to and write
0838  *         from.
0839  *
0840  * This function creates a file in debugfs with the given name that
0841  * contains the value of the variable @value.  If the @mode variable is so
0842  * set, it can be read from, and written to.
0843  */
0844 void debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent,
0845              bool *value)
0846 {
0847     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_bool,
0848                    &fops_bool_ro, &fops_bool_wo);
0849 }
0850 EXPORT_SYMBOL_GPL(debugfs_create_bool);
0851 
0852 ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,
0853                   size_t count, loff_t *ppos)
0854 {
0855     struct dentry *dentry = F_DENTRY(file);
0856     char *str, *copy = NULL;
0857     int copy_len, len;
0858     ssize_t ret;
0859 
0860     ret = debugfs_file_get(dentry);
0861     if (unlikely(ret))
0862         return ret;
0863 
0864     str = *(char **)file->private_data;
0865     len = strlen(str) + 1;
0866     copy = kmalloc(len, GFP_KERNEL);
0867     if (!copy) {
0868         debugfs_file_put(dentry);
0869         return -ENOMEM;
0870     }
0871 
0872     copy_len = strscpy(copy, str, len);
0873     debugfs_file_put(dentry);
0874     if (copy_len < 0) {
0875         kfree(copy);
0876         return copy_len;
0877     }
0878 
0879     copy[copy_len] = '\n';
0880 
0881     ret = simple_read_from_buffer(user_buf, count, ppos, copy, len);
0882     kfree(copy);
0883 
0884     return ret;
0885 }
0886 
0887 static ssize_t debugfs_write_file_str(struct file *file, const char __user *user_buf,
0888                       size_t count, loff_t *ppos)
0889 {
0890     /* This is really only for read-only strings */
0891     return -EINVAL;
0892 }
0893 
0894 static const struct file_operations fops_str = {
0895     .read =     debugfs_read_file_str,
0896     .write =    debugfs_write_file_str,
0897     .open =     simple_open,
0898     .llseek =   default_llseek,
0899 };
0900 
0901 static const struct file_operations fops_str_ro = {
0902     .read =     debugfs_read_file_str,
0903     .open =     simple_open,
0904     .llseek =   default_llseek,
0905 };
0906 
0907 static const struct file_operations fops_str_wo = {
0908     .write =    debugfs_write_file_str,
0909     .open =     simple_open,
0910     .llseek =   default_llseek,
0911 };
0912 
0913 /**
0914  * debugfs_create_str - create a debugfs file that is used to read and write a string value
0915  * @name: a pointer to a string containing the name of the file to create.
0916  * @mode: the permission that the file should have
0917  * @parent: a pointer to the parent dentry for this file.  This should be a
0918  *          directory dentry if set.  If this parameter is %NULL, then the
0919  *          file will be created in the root of the debugfs filesystem.
0920  * @value: a pointer to the variable that the file should read to and write
0921  *         from.
0922  *
0923  * This function creates a file in debugfs with the given name that
0924  * contains the value of the variable @value.  If the @mode variable is so
0925  * set, it can be read from, and written to.
0926  *
0927  * This function will return a pointer to a dentry if it succeeds.  This
0928  * pointer must be passed to the debugfs_remove() function when the file is
0929  * to be removed (no automatic cleanup happens if your module is unloaded,
0930  * you are responsible here.)  If an error occurs, ERR_PTR(-ERROR) will be
0931  * returned.
0932  *
0933  * If debugfs is not enabled in the kernel, the value ERR_PTR(-ENODEV) will
0934  * be returned.
0935  */
0936 void debugfs_create_str(const char *name, umode_t mode,
0937             struct dentry *parent, char **value)
0938 {
0939     debugfs_create_mode_unsafe(name, mode, parent, value, &fops_str,
0940                    &fops_str_ro, &fops_str_wo);
0941 }
0942 
0943 static ssize_t read_file_blob(struct file *file, char __user *user_buf,
0944                   size_t count, loff_t *ppos)
0945 {
0946     struct debugfs_blob_wrapper *blob = file->private_data;
0947     struct dentry *dentry = F_DENTRY(file);
0948     ssize_t r;
0949 
0950     r = debugfs_file_get(dentry);
0951     if (unlikely(r))
0952         return r;
0953     r = simple_read_from_buffer(user_buf, count, ppos, blob->data,
0954                 blob->size);
0955     debugfs_file_put(dentry);
0956     return r;
0957 }
0958 
0959 static const struct file_operations fops_blob = {
0960     .read =     read_file_blob,
0961     .open =     simple_open,
0962     .llseek =   default_llseek,
0963 };
0964 
0965 /**
0966  * debugfs_create_blob - create a debugfs file that is used to read a binary blob
0967  * @name: a pointer to a string containing the name of the file to create.
0968  * @mode: the read permission that the file should have (other permissions are
0969  *    masked out)
0970  * @parent: a pointer to the parent dentry for this file.  This should be a
0971  *          directory dentry if set.  If this parameter is %NULL, then the
0972  *          file will be created in the root of the debugfs filesystem.
0973  * @blob: a pointer to a struct debugfs_blob_wrapper which contains a pointer
0974  *        to the blob data and the size of the data.
0975  *
0976  * This function creates a file in debugfs with the given name that exports
0977  * @blob->data as a binary blob. If the @mode variable is so set it can be
0978  * read from. Writing is not supported.
0979  *
0980  * This function will return a pointer to a dentry if it succeeds.  This
0981  * pointer must be passed to the debugfs_remove() function when the file is
0982  * to be removed (no automatic cleanup happens if your module is unloaded,
0983  * you are responsible here.)  If an error occurs, ERR_PTR(-ERROR) will be
0984  * returned.
0985  *
0986  * If debugfs is not enabled in the kernel, the value ERR_PTR(-ENODEV) will
0987  * be returned.
0988  */
0989 struct dentry *debugfs_create_blob(const char *name, umode_t mode,
0990                    struct dentry *parent,
0991                    struct debugfs_blob_wrapper *blob)
0992 {
0993     return debugfs_create_file_unsafe(name, mode & 0444, parent, blob, &fops_blob);
0994 }
0995 EXPORT_SYMBOL_GPL(debugfs_create_blob);
0996 
0997 static size_t u32_format_array(char *buf, size_t bufsize,
0998                    u32 *array, int array_size)
0999 {
1000     size_t ret = 0;
1001 
1002     while (--array_size >= 0) {
1003         size_t len;
1004         char term = array_size ? ' ' : '\n';
1005 
1006         len = snprintf(buf, bufsize, "%u%c", *array++, term);
1007         ret += len;
1008 
1009         buf += len;
1010         bufsize -= len;
1011     }
1012     return ret;
1013 }
1014 
1015 static int u32_array_open(struct inode *inode, struct file *file)
1016 {
1017     struct debugfs_u32_array *data = inode->i_private;
1018     int size, elements = data->n_elements;
1019     char *buf;
1020 
1021     /*
1022      * Max size:
1023      *  - 10 digits + ' '/'\n' = 11 bytes per number
1024      *  - terminating NUL character
1025      */
1026     size = elements*11;
1027     buf = kmalloc(size+1, GFP_KERNEL);
1028     if (!buf)
1029         return -ENOMEM;
1030     buf[size] = 0;
1031 
1032     file->private_data = buf;
1033     u32_format_array(buf, size, data->array, data->n_elements);
1034 
1035     return nonseekable_open(inode, file);
1036 }
1037 
1038 static ssize_t u32_array_read(struct file *file, char __user *buf, size_t len,
1039                   loff_t *ppos)
1040 {
1041     size_t size = strlen(file->private_data);
1042 
1043     return simple_read_from_buffer(buf, len, ppos,
1044                     file->private_data, size);
1045 }
1046 
1047 static int u32_array_release(struct inode *inode, struct file *file)
1048 {
1049     kfree(file->private_data);
1050 
1051     return 0;
1052 }
1053 
1054 static const struct file_operations u32_array_fops = {
1055     .owner   = THIS_MODULE,
1056     .open    = u32_array_open,
1057     .release = u32_array_release,
1058     .read    = u32_array_read,
1059     .llseek  = no_llseek,
1060 };
1061 
1062 /**
1063  * debugfs_create_u32_array - create a debugfs file that is used to read u32
1064  * array.
1065  * @name: a pointer to a string containing the name of the file to create.
1066  * @mode: the permission that the file should have.
1067  * @parent: a pointer to the parent dentry for this file.  This should be a
1068  *          directory dentry if set.  If this parameter is %NULL, then the
1069  *          file will be created in the root of the debugfs filesystem.
1070  * @array: wrapper struct containing data pointer and size of the array.
1071  *
1072  * This function creates a file in debugfs with the given name that exports
1073  * @array as data. If the @mode variable is so set it can be read from.
1074  * Writing is not supported. Seek within the file is also not supported.
1075  * Once array is created its size can not be changed.
1076  */
1077 void debugfs_create_u32_array(const char *name, umode_t mode,
1078                   struct dentry *parent,
1079                   struct debugfs_u32_array *array)
1080 {
1081     debugfs_create_file_unsafe(name, mode, parent, array, &u32_array_fops);
1082 }
1083 EXPORT_SYMBOL_GPL(debugfs_create_u32_array);
1084 
1085 #ifdef CONFIG_HAS_IOMEM
1086 
1087 /*
1088  * The regset32 stuff is used to print 32-bit registers using the
1089  * seq_file utilities. We offer printing a register set in an already-opened
1090  * sequential file or create a debugfs file that only prints a regset32.
1091  */
1092 
1093 /**
1094  * debugfs_print_regs32 - use seq_print to describe a set of registers
1095  * @s: the seq_file structure being used to generate output
1096  * @regs: an array if struct debugfs_reg32 structures
1097  * @nregs: the length of the above array
1098  * @base: the base address to be used in reading the registers
1099  * @prefix: a string to be prefixed to every output line
1100  *
1101  * This function outputs a text block describing the current values of
1102  * some 32-bit hardware registers. It is meant to be used within debugfs
1103  * files based on seq_file that need to show registers, intermixed with other
1104  * information. The prefix argument may be used to specify a leading string,
1105  * because some peripherals have several blocks of identical registers,
1106  * for example configuration of dma channels
1107  */
1108 void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
1109               int nregs, void __iomem *base, char *prefix)
1110 {
1111     int i;
1112 
1113     for (i = 0; i < nregs; i++, regs++) {
1114         if (prefix)
1115             seq_printf(s, "%s", prefix);
1116         seq_printf(s, "%s = 0x%08x\n", regs->name,
1117                readl(base + regs->offset));
1118         if (seq_has_overflowed(s))
1119             break;
1120     }
1121 }
1122 EXPORT_SYMBOL_GPL(debugfs_print_regs32);
1123 
1124 static int debugfs_show_regset32(struct seq_file *s, void *data)
1125 {
1126     struct debugfs_regset32 *regset = s->private;
1127 
1128     if (regset->dev)
1129         pm_runtime_get_sync(regset->dev);
1130 
1131     debugfs_print_regs32(s, regset->regs, regset->nregs, regset->base, "");
1132 
1133     if (regset->dev)
1134         pm_runtime_put(regset->dev);
1135 
1136     return 0;
1137 }
1138 
1139 static int debugfs_open_regset32(struct inode *inode, struct file *file)
1140 {
1141     return single_open(file, debugfs_show_regset32, inode->i_private);
1142 }
1143 
1144 static const struct file_operations fops_regset32 = {
1145     .open =     debugfs_open_regset32,
1146     .read =     seq_read,
1147     .llseek =   seq_lseek,
1148     .release =  single_release,
1149 };
1150 
1151 /**
1152  * debugfs_create_regset32 - create a debugfs file that returns register values
1153  * @name: a pointer to a string containing the name of the file to create.
1154  * @mode: the permission that the file should have
1155  * @parent: a pointer to the parent dentry for this file.  This should be a
1156  *          directory dentry if set.  If this parameter is %NULL, then the
1157  *          file will be created in the root of the debugfs filesystem.
1158  * @regset: a pointer to a struct debugfs_regset32, which contains a pointer
1159  *          to an array of register definitions, the array size and the base
1160  *          address where the register bank is to be found.
1161  *
1162  * This function creates a file in debugfs with the given name that reports
1163  * the names and values of a set of 32-bit registers. If the @mode variable
1164  * is so set it can be read from. Writing is not supported.
1165  */
1166 void debugfs_create_regset32(const char *name, umode_t mode,
1167                  struct dentry *parent,
1168                  struct debugfs_regset32 *regset)
1169 {
1170     debugfs_create_file(name, mode, parent, regset, &fops_regset32);
1171 }
1172 EXPORT_SYMBOL_GPL(debugfs_create_regset32);
1173 
1174 #endif /* CONFIG_HAS_IOMEM */
1175 
1176 struct debugfs_devm_entry {
1177     int (*read)(struct seq_file *seq, void *data);
1178     struct device *dev;
1179 };
1180 
1181 static int debugfs_devm_entry_open(struct inode *inode, struct file *f)
1182 {
1183     struct debugfs_devm_entry *entry = inode->i_private;
1184 
1185     return single_open(f, entry->read, entry->dev);
1186 }
1187 
1188 static const struct file_operations debugfs_devm_entry_ops = {
1189     .owner = THIS_MODULE,
1190     .open = debugfs_devm_entry_open,
1191     .release = single_release,
1192     .read = seq_read,
1193     .llseek = seq_lseek
1194 };
1195 
1196 /**
1197  * debugfs_create_devm_seqfile - create a debugfs file that is bound to device.
1198  *
1199  * @dev: device related to this debugfs file.
1200  * @name: name of the debugfs file.
1201  * @parent: a pointer to the parent dentry for this file.  This should be a
1202  *  directory dentry if set.  If this parameter is %NULL, then the
1203  *  file will be created in the root of the debugfs filesystem.
1204  * @read_fn: function pointer called to print the seq_file content.
1205  */
1206 void debugfs_create_devm_seqfile(struct device *dev, const char *name,
1207                  struct dentry *parent,
1208                  int (*read_fn)(struct seq_file *s, void *data))
1209 {
1210     struct debugfs_devm_entry *entry;
1211 
1212     if (IS_ERR(parent))
1213         return;
1214 
1215     entry = devm_kzalloc(dev, sizeof(*entry), GFP_KERNEL);
1216     if (!entry)
1217         return;
1218 
1219     entry->read = read_fn;
1220     entry->dev = dev;
1221 
1222     debugfs_create_file(name, S_IRUGO, parent, entry,
1223                 &debugfs_devm_entry_ops);
1224 }
1225 EXPORT_SYMBOL_GPL(debugfs_create_devm_seqfile);