file.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. /*
  2. * file.c - part of debugfs, a tiny little debug file system
  3. *
  4. * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
  5. * Copyright (C) 2004 IBM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version
  9. * 2 as published by the Free Software Foundation.
  10. *
  11. * debugfs is for people to use instead of /proc or /sys.
  12. * See Documentation/filesystems/ for more details.
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/fs.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/pagemap.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/io.h>
  21. #include <linux/slab.h>
  22. #include <linux/atomic.h>
  23. #include <linux/device.h>
  24. #include <asm/poll.h>
  25. #include "internal.h"
  26. struct poll_table_struct;
  27. static ssize_t default_read_file(struct file *file, char __user *buf,
  28. size_t count, loff_t *ppos)
  29. {
  30. return 0;
  31. }
  32. static ssize_t default_write_file(struct file *file, const char __user *buf,
  33. size_t count, loff_t *ppos)
  34. {
  35. return count;
  36. }
  37. const struct file_operations debugfs_noop_file_operations = {
  38. .read = default_read_file,
  39. .write = default_write_file,
  40. .open = simple_open,
  41. .llseek = noop_llseek,
  42. };
  43. #define F_DENTRY(filp) ((filp)->f_path.dentry)
  44. const struct file_operations *debugfs_real_fops(const struct file *filp)
  45. {
  46. struct debugfs_fsdata *fsd = F_DENTRY(filp)->d_fsdata;
  47. return fsd->real_fops;
  48. }
  49. EXPORT_SYMBOL_GPL(debugfs_real_fops);
  50. /**
  51. * debugfs_file_get - mark the beginning of file data access
  52. * @dentry: the dentry object whose data is being accessed.
  53. *
  54. * Up to a matching call to debugfs_file_put(), any successive call
  55. * into the file removing functions debugfs_remove() and
  56. * debugfs_remove_recursive() will block. Since associated private
  57. * file data may only get freed after a successful return of any of
  58. * the removal functions, you may safely access it after a successful
  59. * call to debugfs_file_get() without worrying about lifetime issues.
  60. *
  61. * If -%EIO is returned, the file has already been removed and thus,
  62. * it is not safe to access any of its data. If, on the other hand,
  63. * it is allowed to access the file data, zero is returned.
  64. */
  65. int debugfs_file_get(struct dentry *dentry)
  66. {
  67. struct debugfs_fsdata *fsd = dentry->d_fsdata;
  68. /* Avoid starvation of removers. */
  69. if (d_unlinked(dentry))
  70. return -EIO;
  71. if (!refcount_inc_not_zero(&fsd->active_users))
  72. return -EIO;
  73. return 0;
  74. }
  75. EXPORT_SYMBOL_GPL(debugfs_file_get);
  76. /**
  77. * debugfs_file_put - mark the end of file data access
  78. * @dentry: the dentry object formerly passed to
  79. * debugfs_file_get().
  80. *
  81. * Allow any ongoing concurrent call into debugfs_remove() or
  82. * debugfs_remove_recursive() blocked by a former call to
  83. * debugfs_file_get() to proceed and return to its caller.
  84. */
  85. void debugfs_file_put(struct dentry *dentry)
  86. {
  87. struct debugfs_fsdata *fsd = dentry->d_fsdata;
  88. if (refcount_dec_and_test(&fsd->active_users))
  89. complete(&fsd->active_users_drained);
  90. }
  91. EXPORT_SYMBOL_GPL(debugfs_file_put);
  92. static int open_proxy_open(struct inode *inode, struct file *filp)
  93. {
  94. struct dentry *dentry = F_DENTRY(filp);
  95. const struct file_operations *real_fops = NULL;
  96. int r = 0;
  97. if (debugfs_file_get(dentry))
  98. return -ENOENT;
  99. real_fops = debugfs_real_fops(filp);
  100. real_fops = fops_get(real_fops);
  101. if (!real_fops) {
  102. /* Huh? Module did not clean up after itself at exit? */
  103. WARN(1, "debugfs file owner did not clean up at exit: %pd",
  104. dentry);
  105. r = -ENXIO;
  106. goto out;
  107. }
  108. replace_fops(filp, real_fops);
  109. if (real_fops->open)
  110. r = real_fops->open(inode, filp);
  111. out:
  112. debugfs_file_put(dentry);
  113. return r;
  114. }
  115. const struct file_operations debugfs_open_proxy_file_operations = {
  116. .open = open_proxy_open,
  117. };
  118. #define PROTO(args...) args
  119. #define ARGS(args...) args
  120. #define FULL_PROXY_FUNC(name, ret_type, filp, proto, args) \
  121. static ret_type full_proxy_ ## name(proto) \
  122. { \
  123. struct dentry *dentry = F_DENTRY(filp); \
  124. const struct file_operations *real_fops = \
  125. debugfs_real_fops(filp); \
  126. ret_type r; \
  127. \
  128. r = debugfs_file_get(dentry); \
  129. if (unlikely(r)) \
  130. return r; \
  131. r = real_fops->name(args); \
  132. debugfs_file_put(dentry); \
  133. return r; \
  134. }
  135. FULL_PROXY_FUNC(llseek, loff_t, filp,
  136. PROTO(struct file *filp, loff_t offset, int whence),
  137. ARGS(filp, offset, whence));
  138. FULL_PROXY_FUNC(read, ssize_t, filp,
  139. PROTO(struct file *filp, char __user *buf, size_t size,
  140. loff_t *ppos),
  141. ARGS(filp, buf, size, ppos));
  142. FULL_PROXY_FUNC(write, ssize_t, filp,
  143. PROTO(struct file *filp, const char __user *buf, size_t size,
  144. loff_t *ppos),
  145. ARGS(filp, buf, size, ppos));
  146. FULL_PROXY_FUNC(unlocked_ioctl, long, filp,
  147. PROTO(struct file *filp, unsigned int cmd, unsigned long arg),
  148. ARGS(filp, cmd, arg));
  149. static unsigned int full_proxy_poll(struct file *filp,
  150. struct poll_table_struct *wait)
  151. {
  152. const struct file_operations *real_fops = debugfs_real_fops(filp);
  153. struct dentry *dentry = F_DENTRY(filp);
  154. unsigned int r = 0;
  155. if (debugfs_file_get(dentry))
  156. return POLLHUP;
  157. r = real_fops->poll(filp, wait);
  158. debugfs_file_put(dentry);
  159. return r;
  160. }
  161. static int full_proxy_release(struct inode *inode, struct file *filp)
  162. {
  163. const struct dentry *dentry = F_DENTRY(filp);
  164. const struct file_operations *real_fops = debugfs_real_fops(filp);
  165. const struct file_operations *proxy_fops = filp->f_op;
  166. int r = 0;
  167. /*
  168. * We must not protect this against removal races here: the
  169. * original releaser should be called unconditionally in order
  170. * not to leak any resources. Releasers must not assume that
  171. * ->i_private is still being meaningful here.
  172. */
  173. if (real_fops->release)
  174. r = real_fops->release(inode, filp);
  175. replace_fops(filp, d_inode(dentry)->i_fop);
  176. kfree((void *)proxy_fops);
  177. fops_put(real_fops);
  178. return r;
  179. }
  180. static void __full_proxy_fops_init(struct file_operations *proxy_fops,
  181. const struct file_operations *real_fops)
  182. {
  183. proxy_fops->release = full_proxy_release;
  184. if (real_fops->llseek)
  185. proxy_fops->llseek = full_proxy_llseek;
  186. if (real_fops->read)
  187. proxy_fops->read = full_proxy_read;
  188. if (real_fops->write)
  189. proxy_fops->write = full_proxy_write;
  190. if (real_fops->poll)
  191. proxy_fops->poll = full_proxy_poll;
  192. if (real_fops->unlocked_ioctl)
  193. proxy_fops->unlocked_ioctl = full_proxy_unlocked_ioctl;
  194. }
  195. static int full_proxy_open(struct inode *inode, struct file *filp)
  196. {
  197. struct dentry *dentry = F_DENTRY(filp);
  198. const struct file_operations *real_fops = NULL;
  199. struct file_operations *proxy_fops = NULL;
  200. int r = 0;
  201. if (debugfs_file_get(dentry))
  202. return -ENOENT;
  203. real_fops = debugfs_real_fops(filp);
  204. real_fops = fops_get(real_fops);
  205. if (!real_fops) {
  206. /* Huh? Module did not cleanup after itself at exit? */
  207. WARN(1, "debugfs file owner did not clean up at exit: %pd",
  208. dentry);
  209. r = -ENXIO;
  210. goto out;
  211. }
  212. proxy_fops = kzalloc(sizeof(*proxy_fops), GFP_KERNEL);
  213. if (!proxy_fops) {
  214. r = -ENOMEM;
  215. goto free_proxy;
  216. }
  217. __full_proxy_fops_init(proxy_fops, real_fops);
  218. replace_fops(filp, proxy_fops);
  219. if (real_fops->open) {
  220. r = real_fops->open(inode, filp);
  221. if (r) {
  222. replace_fops(filp, d_inode(dentry)->i_fop);
  223. goto free_proxy;
  224. } else if (filp->f_op != proxy_fops) {
  225. /* No protection against file removal anymore. */
  226. WARN(1, "debugfs file owner replaced proxy fops: %pd",
  227. dentry);
  228. goto free_proxy;
  229. }
  230. }
  231. goto out;
  232. free_proxy:
  233. kfree(proxy_fops);
  234. fops_put(real_fops);
  235. out:
  236. debugfs_file_put(dentry);
  237. return r;
  238. }
  239. const struct file_operations debugfs_full_proxy_file_operations = {
  240. .open = full_proxy_open,
  241. };
  242. ssize_t debugfs_attr_read(struct file *file, char __user *buf,
  243. size_t len, loff_t *ppos)
  244. {
  245. struct dentry *dentry = F_DENTRY(file);
  246. ssize_t ret;
  247. ret = debugfs_file_get(dentry);
  248. if (unlikely(ret))
  249. return ret;
  250. ret = simple_attr_read(file, buf, len, ppos);
  251. debugfs_file_put(dentry);
  252. return ret;
  253. }
  254. EXPORT_SYMBOL_GPL(debugfs_attr_read);
  255. ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
  256. size_t len, loff_t *ppos)
  257. {
  258. struct dentry *dentry = F_DENTRY(file);
  259. ssize_t ret;
  260. ret = debugfs_file_get(dentry);
  261. if (unlikely(ret))
  262. return ret;
  263. ret = simple_attr_write(file, buf, len, ppos);
  264. debugfs_file_put(dentry);
  265. return ret;
  266. }
  267. EXPORT_SYMBOL_GPL(debugfs_attr_write);
  268. static struct dentry *debugfs_create_mode_unsafe(const char *name, umode_t mode,
  269. struct dentry *parent, void *value,
  270. const struct file_operations *fops,
  271. const struct file_operations *fops_ro,
  272. const struct file_operations *fops_wo)
  273. {
  274. /* if there are no write bits set, make read only */
  275. if (!(mode & S_IWUGO))
  276. return debugfs_create_file_unsafe(name, mode, parent, value,
  277. fops_ro);
  278. /* if there are no read bits set, make write only */
  279. if (!(mode & S_IRUGO))
  280. return debugfs_create_file_unsafe(name, mode, parent, value,
  281. fops_wo);
  282. return debugfs_create_file_unsafe(name, mode, parent, value, fops);
  283. }
  284. static int debugfs_u8_set(void *data, u64 val)
  285. {
  286. *(u8 *)data = val;
  287. return 0;
  288. }
  289. static int debugfs_u8_get(void *data, u64 *val)
  290. {
  291. *val = *(u8 *)data;
  292. return 0;
  293. }
  294. DEFINE_DEBUGFS_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n");
  295. DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_ro, debugfs_u8_get, NULL, "%llu\n");
  296. DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_wo, NULL, debugfs_u8_set, "%llu\n");
  297. /**
  298. * debugfs_create_u8 - create a debugfs file that is used to read and write an unsigned 8-bit value
  299. * @name: a pointer to a string containing the name of the file to create.
  300. * @mode: the permission that the file should have
  301. * @parent: a pointer to the parent dentry for this file. This should be a
  302. * directory dentry if set. If this parameter is %NULL, then the
  303. * file will be created in the root of the debugfs filesystem.
  304. * @value: a pointer to the variable that the file should read to and write
  305. * from.
  306. *
  307. * This function creates a file in debugfs with the given name that
  308. * contains the value of the variable @value. If the @mode variable is so
  309. * set, it can be read from, and written to.
  310. *
  311. * This function will return a pointer to a dentry if it succeeds. This
  312. * pointer must be passed to the debugfs_remove() function when the file is
  313. * to be removed (no automatic cleanup happens if your module is unloaded,
  314. * you are responsible here.) If an error occurs, %NULL will be returned.
  315. *
  316. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  317. * returned. It is not wise to check for this value, but rather, check for
  318. * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
  319. * code.
  320. */
  321. struct dentry *debugfs_create_u8(const char *name, umode_t mode,
  322. struct dentry *parent, u8 *value)
  323. {
  324. return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u8,
  325. &fops_u8_ro, &fops_u8_wo);
  326. }
  327. EXPORT_SYMBOL_GPL(debugfs_create_u8);
  328. static int debugfs_u16_set(void *data, u64 val)
  329. {
  330. *(u16 *)data = val;
  331. return 0;
  332. }
  333. static int debugfs_u16_get(void *data, u64 *val)
  334. {
  335. *val = *(u16 *)data;
  336. return 0;
  337. }
  338. DEFINE_DEBUGFS_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n");
  339. DEFINE_DEBUGFS_ATTRIBUTE(fops_u16_ro, debugfs_u16_get, NULL, "%llu\n");
  340. DEFINE_DEBUGFS_ATTRIBUTE(fops_u16_wo, NULL, debugfs_u16_set, "%llu\n");
  341. /**
  342. * debugfs_create_u16 - create a debugfs file that is used to read and write an unsigned 16-bit value
  343. * @name: a pointer to a string containing the name of the file to create.
  344. * @mode: the permission that the file should have
  345. * @parent: a pointer to the parent dentry for this file. This should be a
  346. * directory dentry if set. If this parameter is %NULL, then the
  347. * file will be created in the root of the debugfs filesystem.
  348. * @value: a pointer to the variable that the file should read to and write
  349. * from.
  350. *
  351. * This function creates a file in debugfs with the given name that
  352. * contains the value of the variable @value. If the @mode variable is so
  353. * set, it can be read from, and written to.
  354. *
  355. * This function will return a pointer to a dentry if it succeeds. This
  356. * pointer must be passed to the debugfs_remove() function when the file is
  357. * to be removed (no automatic cleanup happens if your module is unloaded,
  358. * you are responsible here.) If an error occurs, %NULL will be returned.
  359. *
  360. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  361. * returned. It is not wise to check for this value, but rather, check for
  362. * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
  363. * code.
  364. */
  365. struct dentry *debugfs_create_u16(const char *name, umode_t mode,
  366. struct dentry *parent, u16 *value)
  367. {
  368. return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u16,
  369. &fops_u16_ro, &fops_u16_wo);
  370. }
  371. EXPORT_SYMBOL_GPL(debugfs_create_u16);
  372. static int debugfs_u32_set(void *data, u64 val)
  373. {
  374. *(u32 *)data = val;
  375. return 0;
  376. }
  377. static int debugfs_u32_get(void *data, u64 *val)
  378. {
  379. *val = *(u32 *)data;
  380. return 0;
  381. }
  382. DEFINE_DEBUGFS_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n");
  383. DEFINE_DEBUGFS_ATTRIBUTE(fops_u32_ro, debugfs_u32_get, NULL, "%llu\n");
  384. DEFINE_DEBUGFS_ATTRIBUTE(fops_u32_wo, NULL, debugfs_u32_set, "%llu\n");
  385. /**
  386. * debugfs_create_u32 - create a debugfs file that is used to read and write an unsigned 32-bit value
  387. * @name: a pointer to a string containing the name of the file to create.
  388. * @mode: the permission that the file should have
  389. * @parent: a pointer to the parent dentry for this file. This should be a
  390. * directory dentry if set. If this parameter is %NULL, then the
  391. * file will be created in the root of the debugfs filesystem.
  392. * @value: a pointer to the variable that the file should read to and write
  393. * from.
  394. *
  395. * This function creates a file in debugfs with the given name that
  396. * contains the value of the variable @value. If the @mode variable is so
  397. * set, it can be read from, and written to.
  398. *
  399. * This function will return a pointer to a dentry if it succeeds. This
  400. * pointer must be passed to the debugfs_remove() function when the file is
  401. * to be removed (no automatic cleanup happens if your module is unloaded,
  402. * you are responsible here.) If an error occurs, %NULL will be returned.
  403. *
  404. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  405. * returned. It is not wise to check for this value, but rather, check for
  406. * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
  407. * code.
  408. */
  409. struct dentry *debugfs_create_u32(const char *name, umode_t mode,
  410. struct dentry *parent, u32 *value)
  411. {
  412. return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u32,
  413. &fops_u32_ro, &fops_u32_wo);
  414. }
  415. EXPORT_SYMBOL_GPL(debugfs_create_u32);
  416. static int debugfs_u64_set(void *data, u64 val)
  417. {
  418. *(u64 *)data = val;
  419. return 0;
  420. }
  421. static int debugfs_u64_get(void *data, u64 *val)
  422. {
  423. *val = *(u64 *)data;
  424. return 0;
  425. }
  426. DEFINE_DEBUGFS_ATTRIBUTE(fops_u64, debugfs_u64_get, debugfs_u64_set, "%llu\n");
  427. DEFINE_DEBUGFS_ATTRIBUTE(fops_u64_ro, debugfs_u64_get, NULL, "%llu\n");
  428. DEFINE_DEBUGFS_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n");
  429. /**
  430. * debugfs_create_u64 - create a debugfs file that is used to read and write an unsigned 64-bit value
  431. * @name: a pointer to a string containing the name of the file to create.
  432. * @mode: the permission that the file should have
  433. * @parent: a pointer to the parent dentry for this file. This should be a
  434. * directory dentry if set. If this parameter is %NULL, then the
  435. * file will be created in the root of the debugfs filesystem.
  436. * @value: a pointer to the variable that the file should read to and write
  437. * from.
  438. *
  439. * This function creates a file in debugfs with the given name that
  440. * contains the value of the variable @value. If the @mode variable is so
  441. * set, it can be read from, and written to.
  442. *
  443. * This function will return a pointer to a dentry if it succeeds. This
  444. * pointer must be passed to the debugfs_remove() function when the file is
  445. * to be removed (no automatic cleanup happens if your module is unloaded,
  446. * you are responsible here.) If an error occurs, %NULL will be returned.
  447. *
  448. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  449. * returned. It is not wise to check for this value, but rather, check for
  450. * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
  451. * code.
  452. */
  453. struct dentry *debugfs_create_u64(const char *name, umode_t mode,
  454. struct dentry *parent, u64 *value)
  455. {
  456. return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u64,
  457. &fops_u64_ro, &fops_u64_wo);
  458. }
  459. EXPORT_SYMBOL_GPL(debugfs_create_u64);
  460. static int debugfs_ulong_set(void *data, u64 val)
  461. {
  462. *(unsigned long *)data = val;
  463. return 0;
  464. }
  465. static int debugfs_ulong_get(void *data, u64 *val)
  466. {
  467. *val = *(unsigned long *)data;
  468. return 0;
  469. }
  470. DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong, debugfs_ulong_get, debugfs_ulong_set,
  471. "%llu\n");
  472. DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong_ro, debugfs_ulong_get, NULL, "%llu\n");
  473. DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong_wo, NULL, debugfs_ulong_set, "%llu\n");
  474. /**
  475. * debugfs_create_ulong - create a debugfs file that is used to read and write
  476. * an unsigned long value.
  477. * @name: a pointer to a string containing the name of the file to create.
  478. * @mode: the permission that the file should have
  479. * @parent: a pointer to the parent dentry for this file. This should be a
  480. * directory dentry if set. If this parameter is %NULL, then the
  481. * file will be created in the root of the debugfs filesystem.
  482. * @value: a pointer to the variable that the file should read to and write
  483. * from.
  484. *
  485. * This function creates a file in debugfs with the given name that
  486. * contains the value of the variable @value. If the @mode variable is so
  487. * set, it can be read from, and written to.
  488. *
  489. * This function will return a pointer to a dentry if it succeeds. This
  490. * pointer must be passed to the debugfs_remove() function when the file is
  491. * to be removed (no automatic cleanup happens if your module is unloaded,
  492. * you are responsible here.) If an error occurs, %NULL will be returned.
  493. *
  494. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  495. * returned. It is not wise to check for this value, but rather, check for
  496. * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
  497. * code.
  498. */
  499. struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
  500. struct dentry *parent, unsigned long *value)
  501. {
  502. return debugfs_create_mode_unsafe(name, mode, parent, value,
  503. &fops_ulong, &fops_ulong_ro,
  504. &fops_ulong_wo);
  505. }
  506. EXPORT_SYMBOL_GPL(debugfs_create_ulong);
  507. DEFINE_DEBUGFS_ATTRIBUTE(fops_x8, debugfs_u8_get, debugfs_u8_set, "0x%02llx\n");
  508. DEFINE_DEBUGFS_ATTRIBUTE(fops_x8_ro, debugfs_u8_get, NULL, "0x%02llx\n");
  509. DEFINE_DEBUGFS_ATTRIBUTE(fops_x8_wo, NULL, debugfs_u8_set, "0x%02llx\n");
  510. DEFINE_DEBUGFS_ATTRIBUTE(fops_x16, debugfs_u16_get, debugfs_u16_set,
  511. "0x%04llx\n");
  512. DEFINE_DEBUGFS_ATTRIBUTE(fops_x16_ro, debugfs_u16_get, NULL, "0x%04llx\n");
  513. DEFINE_DEBUGFS_ATTRIBUTE(fops_x16_wo, NULL, debugfs_u16_set, "0x%04llx\n");
  514. DEFINE_DEBUGFS_ATTRIBUTE(fops_x32, debugfs_u32_get, debugfs_u32_set,
  515. "0x%08llx\n");
  516. DEFINE_DEBUGFS_ATTRIBUTE(fops_x32_ro, debugfs_u32_get, NULL, "0x%08llx\n");
  517. DEFINE_DEBUGFS_ATTRIBUTE(fops_x32_wo, NULL, debugfs_u32_set, "0x%08llx\n");
  518. DEFINE_DEBUGFS_ATTRIBUTE(fops_x64, debugfs_u64_get, debugfs_u64_set,
  519. "0x%016llx\n");
  520. DEFINE_DEBUGFS_ATTRIBUTE(fops_x64_ro, debugfs_u64_get, NULL, "0x%016llx\n");
  521. DEFINE_DEBUGFS_ATTRIBUTE(fops_x64_wo, NULL, debugfs_u64_set, "0x%016llx\n");
  522. /*
  523. * 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
  524. *
  525. * These functions are exactly the same as the above functions (but use a hex
  526. * output for the decimal challenged). For details look at the above unsigned
  527. * decimal functions.
  528. */
  529. /**
  530. * debugfs_create_x8 - create a debugfs file that is used to read and write an unsigned 8-bit value
  531. * @name: a pointer to a string containing the name of the file to create.
  532. * @mode: the permission that the file should have
  533. * @parent: a pointer to the parent dentry for this file. This should be a
  534. * directory dentry if set. If this parameter is %NULL, then the
  535. * file will be created in the root of the debugfs filesystem.
  536. * @value: a pointer to the variable that the file should read to and write
  537. * from.
  538. */
  539. struct dentry *debugfs_create_x8(const char *name, umode_t mode,
  540. struct dentry *parent, u8 *value)
  541. {
  542. return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x8,
  543. &fops_x8_ro, &fops_x8_wo);
  544. }
  545. EXPORT_SYMBOL_GPL(debugfs_create_x8);
  546. /**
  547. * debugfs_create_x16 - create a debugfs file that is used to read and write an unsigned 16-bit value
  548. * @name: a pointer to a string containing the name of the file to create.
  549. * @mode: the permission that the file should have
  550. * @parent: a pointer to the parent dentry for this file. This should be a
  551. * directory dentry if set. If this parameter is %NULL, then the
  552. * file will be created in the root of the debugfs filesystem.
  553. * @value: a pointer to the variable that the file should read to and write
  554. * from.
  555. */
  556. struct dentry *debugfs_create_x16(const char *name, umode_t mode,
  557. struct dentry *parent, u16 *value)
  558. {
  559. return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x16,
  560. &fops_x16_ro, &fops_x16_wo);
  561. }
  562. EXPORT_SYMBOL_GPL(debugfs_create_x16);
  563. /**
  564. * debugfs_create_x32 - create a debugfs file that is used to read and write an unsigned 32-bit value
  565. * @name: a pointer to a string containing the name of the file to create.
  566. * @mode: the permission that the file should have
  567. * @parent: a pointer to the parent dentry for this file. This should be a
  568. * directory dentry if set. If this parameter is %NULL, then the
  569. * file will be created in the root of the debugfs filesystem.
  570. * @value: a pointer to the variable that the file should read to and write
  571. * from.
  572. */
  573. struct dentry *debugfs_create_x32(const char *name, umode_t mode,
  574. struct dentry *parent, u32 *value)
  575. {
  576. return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x32,
  577. &fops_x32_ro, &fops_x32_wo);
  578. }
  579. EXPORT_SYMBOL_GPL(debugfs_create_x32);
  580. /**
  581. * debugfs_create_x64 - create a debugfs file that is used to read and write an unsigned 64-bit value
  582. * @name: a pointer to a string containing the name of the file to create.
  583. * @mode: the permission that the file should have
  584. * @parent: a pointer to the parent dentry for this file. This should be a
  585. * directory dentry if set. If this parameter is %NULL, then the
  586. * file will be created in the root of the debugfs filesystem.
  587. * @value: a pointer to the variable that the file should read to and write
  588. * from.
  589. */
  590. struct dentry *debugfs_create_x64(const char *name, umode_t mode,
  591. struct dentry *parent, u64 *value)
  592. {
  593. return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x64,
  594. &fops_x64_ro, &fops_x64_wo);
  595. }
  596. EXPORT_SYMBOL_GPL(debugfs_create_x64);
  597. static int debugfs_size_t_set(void *data, u64 val)
  598. {
  599. *(size_t *)data = val;
  600. return 0;
  601. }
  602. static int debugfs_size_t_get(void *data, u64 *val)
  603. {
  604. *val = *(size_t *)data;
  605. return 0;
  606. }
  607. DEFINE_DEBUGFS_ATTRIBUTE(fops_size_t, debugfs_size_t_get, debugfs_size_t_set,
  608. "%llu\n"); /* %llu and %zu are more or less the same */
  609. DEFINE_DEBUGFS_ATTRIBUTE(fops_size_t_ro, debugfs_size_t_get, NULL, "%llu\n");
  610. DEFINE_DEBUGFS_ATTRIBUTE(fops_size_t_wo, NULL, debugfs_size_t_set, "%llu\n");
  611. /**
  612. * debugfs_create_size_t - create a debugfs file that is used to read and write an size_t value
  613. * @name: a pointer to a string containing the name of the file to create.
  614. * @mode: the permission that the file should have
  615. * @parent: a pointer to the parent dentry for this file. This should be a
  616. * directory dentry if set. If this parameter is %NULL, then the
  617. * file will be created in the root of the debugfs filesystem.
  618. * @value: a pointer to the variable that the file should read to and write
  619. * from.
  620. */
  621. struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
  622. struct dentry *parent, size_t *value)
  623. {
  624. return debugfs_create_mode_unsafe(name, mode, parent, value,
  625. &fops_size_t, &fops_size_t_ro,
  626. &fops_size_t_wo);
  627. }
  628. EXPORT_SYMBOL_GPL(debugfs_create_size_t);
  629. static int debugfs_atomic_t_set(void *data, u64 val)
  630. {
  631. atomic_set((atomic_t *)data, val);
  632. return 0;
  633. }
  634. static int debugfs_atomic_t_get(void *data, u64 *val)
  635. {
  636. *val = atomic_read((atomic_t *)data);
  637. return 0;
  638. }
  639. DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get,
  640. debugfs_atomic_t_set, "%lld\n");
  641. DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_ro, debugfs_atomic_t_get, NULL,
  642. "%lld\n");
  643. DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set,
  644. "%lld\n");
  645. /**
  646. * debugfs_create_atomic_t - create a debugfs file that is used to read and
  647. * write an atomic_t value
  648. * @name: a pointer to a string containing the name of the file to create.
  649. * @mode: the permission that the file should have
  650. * @parent: a pointer to the parent dentry for this file. This should be a
  651. * directory dentry if set. If this parameter is %NULL, then the
  652. * file will be created in the root of the debugfs filesystem.
  653. * @value: a pointer to the variable that the file should read to and write
  654. * from.
  655. */
  656. struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
  657. struct dentry *parent, atomic_t *value)
  658. {
  659. return debugfs_create_mode_unsafe(name, mode, parent, value,
  660. &fops_atomic_t, &fops_atomic_t_ro,
  661. &fops_atomic_t_wo);
  662. }
  663. EXPORT_SYMBOL_GPL(debugfs_create_atomic_t);
  664. ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
  665. size_t count, loff_t *ppos)
  666. {
  667. char buf[3];
  668. bool val;
  669. int r;
  670. struct dentry *dentry = F_DENTRY(file);
  671. r = debugfs_file_get(dentry);
  672. if (unlikely(r))
  673. return r;
  674. val = *(bool *)file->private_data;
  675. debugfs_file_put(dentry);
  676. if (val)
  677. buf[0] = 'Y';
  678. else
  679. buf[0] = 'N';
  680. buf[1] = '\n';
  681. buf[2] = 0x00;
  682. return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
  683. }
  684. EXPORT_SYMBOL_GPL(debugfs_read_file_bool);
  685. ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
  686. size_t count, loff_t *ppos)
  687. {
  688. char buf[32];
  689. size_t buf_size;
  690. bool bv;
  691. int r;
  692. bool *val = file->private_data;
  693. struct dentry *dentry = F_DENTRY(file);
  694. buf_size = min(count, (sizeof(buf)-1));
  695. if (copy_from_user(buf, user_buf, buf_size))
  696. return -EFAULT;
  697. buf[buf_size] = '\0';
  698. if (strtobool(buf, &bv) == 0) {
  699. r = debugfs_file_get(dentry);
  700. if (unlikely(r))
  701. return r;
  702. *val = bv;
  703. debugfs_file_put(dentry);
  704. }
  705. return count;
  706. }
  707. EXPORT_SYMBOL_GPL(debugfs_write_file_bool);
  708. static const struct file_operations fops_bool = {
  709. .read = debugfs_read_file_bool,
  710. .write = debugfs_write_file_bool,
  711. .open = simple_open,
  712. .llseek = default_llseek,
  713. };
  714. static const struct file_operations fops_bool_ro = {
  715. .read = debugfs_read_file_bool,
  716. .open = simple_open,
  717. .llseek = default_llseek,
  718. };
  719. static const struct file_operations fops_bool_wo = {
  720. .write = debugfs_write_file_bool,
  721. .open = simple_open,
  722. .llseek = default_llseek,
  723. };
  724. /**
  725. * debugfs_create_bool - create a debugfs file that is used to read and write a boolean value
  726. * @name: a pointer to a string containing the name of the file to create.
  727. * @mode: the permission that the file should have
  728. * @parent: a pointer to the parent dentry for this file. This should be a
  729. * directory dentry if set. If this parameter is %NULL, then the
  730. * file will be created in the root of the debugfs filesystem.
  731. * @value: a pointer to the variable that the file should read to and write
  732. * from.
  733. *
  734. * This function creates a file in debugfs with the given name that
  735. * contains the value of the variable @value. If the @mode variable is so
  736. * set, it can be read from, and written to.
  737. *
  738. * This function will return a pointer to a dentry if it succeeds. This
  739. * pointer must be passed to the debugfs_remove() function when the file is
  740. * to be removed (no automatic cleanup happens if your module is unloaded,
  741. * you are responsible here.) If an error occurs, %NULL will be returned.
  742. *
  743. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  744. * returned. It is not wise to check for this value, but rather, check for
  745. * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
  746. * code.
  747. */
  748. struct dentry *debugfs_create_bool(const char *name, umode_t mode,
  749. struct dentry *parent, bool *value)
  750. {
  751. return debugfs_create_mode_unsafe(name, mode, parent, value, &fops_bool,
  752. &fops_bool_ro, &fops_bool_wo);
  753. }
  754. EXPORT_SYMBOL_GPL(debugfs_create_bool);
  755. static ssize_t read_file_blob(struct file *file, char __user *user_buf,
  756. size_t count, loff_t *ppos)
  757. {
  758. struct debugfs_blob_wrapper *blob = file->private_data;
  759. struct dentry *dentry = F_DENTRY(file);
  760. ssize_t r;
  761. r = debugfs_file_get(dentry);
  762. if (unlikely(r))
  763. return r;
  764. r = simple_read_from_buffer(user_buf, count, ppos, blob->data,
  765. blob->size);
  766. debugfs_file_put(dentry);
  767. return r;
  768. }
  769. static const struct file_operations fops_blob = {
  770. .read = read_file_blob,
  771. .open = simple_open,
  772. .llseek = default_llseek,
  773. };
  774. /**
  775. * debugfs_create_blob - create a debugfs file that is used to read a binary blob
  776. * @name: a pointer to a string containing the name of the file to create.
  777. * @mode: the permission that the file should have
  778. * @parent: a pointer to the parent dentry for this file. This should be a
  779. * directory dentry if set. If this parameter is %NULL, then the
  780. * file will be created in the root of the debugfs filesystem.
  781. * @blob: a pointer to a struct debugfs_blob_wrapper which contains a pointer
  782. * to the blob data and the size of the data.
  783. *
  784. * This function creates a file in debugfs with the given name that exports
  785. * @blob->data as a binary blob. If the @mode variable is so set it can be
  786. * read from. Writing is not supported.
  787. *
  788. * This function will return a pointer to a dentry if it succeeds. This
  789. * pointer must be passed to the debugfs_remove() function when the file is
  790. * to be removed (no automatic cleanup happens if your module is unloaded,
  791. * you are responsible here.) If an error occurs, %NULL will be returned.
  792. *
  793. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  794. * returned. It is not wise to check for this value, but rather, check for
  795. * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
  796. * code.
  797. */
  798. struct dentry *debugfs_create_blob(const char *name, umode_t mode,
  799. struct dentry *parent,
  800. struct debugfs_blob_wrapper *blob)
  801. {
  802. return debugfs_create_file_unsafe(name, mode, parent, blob, &fops_blob);
  803. }
  804. EXPORT_SYMBOL_GPL(debugfs_create_blob);
  805. struct array_data {
  806. void *array;
  807. u32 elements;
  808. };
  809. static size_t u32_format_array(char *buf, size_t bufsize,
  810. u32 *array, int array_size)
  811. {
  812. size_t ret = 0;
  813. while (--array_size >= 0) {
  814. size_t len;
  815. char term = array_size ? ' ' : '\n';
  816. len = snprintf(buf, bufsize, "%u%c", *array++, term);
  817. ret += len;
  818. buf += len;
  819. bufsize -= len;
  820. }
  821. return ret;
  822. }
  823. static int u32_array_open(struct inode *inode, struct file *file)
  824. {
  825. struct array_data *data = inode->i_private;
  826. int size, elements = data->elements;
  827. char *buf;
  828. /*
  829. * Max size:
  830. * - 10 digits + ' '/'\n' = 11 bytes per number
  831. * - terminating NUL character
  832. */
  833. size = elements*11;
  834. buf = kmalloc(size+1, GFP_KERNEL);
  835. if (!buf)
  836. return -ENOMEM;
  837. buf[size] = 0;
  838. file->private_data = buf;
  839. u32_format_array(buf, size, data->array, data->elements);
  840. return nonseekable_open(inode, file);
  841. }
  842. static ssize_t u32_array_read(struct file *file, char __user *buf, size_t len,
  843. loff_t *ppos)
  844. {
  845. size_t size = strlen(file->private_data);
  846. return simple_read_from_buffer(buf, len, ppos,
  847. file->private_data, size);
  848. }
  849. static int u32_array_release(struct inode *inode, struct file *file)
  850. {
  851. kfree(file->private_data);
  852. return 0;
  853. }
  854. static const struct file_operations u32_array_fops = {
  855. .owner = THIS_MODULE,
  856. .open = u32_array_open,
  857. .release = u32_array_release,
  858. .read = u32_array_read,
  859. .llseek = no_llseek,
  860. };
  861. /**
  862. * debugfs_create_u32_array - create a debugfs file that is used to read u32
  863. * array.
  864. * @name: a pointer to a string containing the name of the file to create.
  865. * @mode: the permission that the file should have.
  866. * @parent: a pointer to the parent dentry for this file. This should be a
  867. * directory dentry if set. If this parameter is %NULL, then the
  868. * file will be created in the root of the debugfs filesystem.
  869. * @array: u32 array that provides data.
  870. * @elements: total number of elements in the array.
  871. *
  872. * This function creates a file in debugfs with the given name that exports
  873. * @array as data. If the @mode variable is so set it can be read from.
  874. * Writing is not supported. Seek within the file is also not supported.
  875. * Once array is created its size can not be changed.
  876. *
  877. * The function returns a pointer to dentry on success. If debugfs is not
  878. * enabled in the kernel, the value -%ENODEV will be returned.
  879. */
  880. struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
  881. struct dentry *parent,
  882. u32 *array, u32 elements)
  883. {
  884. struct array_data *data = kmalloc(sizeof(*data), GFP_KERNEL);
  885. if (data == NULL)
  886. return NULL;
  887. data->array = array;
  888. data->elements = elements;
  889. return debugfs_create_file_unsafe(name, mode, parent, data,
  890. &u32_array_fops);
  891. }
  892. EXPORT_SYMBOL_GPL(debugfs_create_u32_array);
  893. #ifdef CONFIG_HAS_IOMEM
  894. /*
  895. * The regset32 stuff is used to print 32-bit registers using the
  896. * seq_file utilities. We offer printing a register set in an already-opened
  897. * sequential file or create a debugfs file that only prints a regset32.
  898. */
  899. /**
  900. * debugfs_print_regs32 - use seq_print to describe a set of registers
  901. * @s: the seq_file structure being used to generate output
  902. * @regs: an array if struct debugfs_reg32 structures
  903. * @nregs: the length of the above array
  904. * @base: the base address to be used in reading the registers
  905. * @prefix: a string to be prefixed to every output line
  906. *
  907. * This function outputs a text block describing the current values of
  908. * some 32-bit hardware registers. It is meant to be used within debugfs
  909. * files based on seq_file that need to show registers, intermixed with other
  910. * information. The prefix argument may be used to specify a leading string,
  911. * because some peripherals have several blocks of identical registers,
  912. * for example configuration of dma channels
  913. */
  914. void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
  915. int nregs, void __iomem *base, char *prefix)
  916. {
  917. int i;
  918. for (i = 0; i < nregs; i++, regs++) {
  919. if (prefix)
  920. seq_printf(s, "%s", prefix);
  921. seq_printf(s, "%s = 0x%08x\n", regs->name,
  922. readl(base + regs->offset));
  923. if (seq_has_overflowed(s))
  924. break;
  925. }
  926. }
  927. EXPORT_SYMBOL_GPL(debugfs_print_regs32);
  928. static int debugfs_show_regset32(struct seq_file *s, void *data)
  929. {
  930. struct debugfs_regset32 *regset = s->private;
  931. debugfs_print_regs32(s, regset->regs, regset->nregs, regset->base, "");
  932. return 0;
  933. }
  934. static int debugfs_open_regset32(struct inode *inode, struct file *file)
  935. {
  936. return single_open(file, debugfs_show_regset32, inode->i_private);
  937. }
  938. static const struct file_operations fops_regset32 = {
  939. .open = debugfs_open_regset32,
  940. .read = seq_read,
  941. .llseek = seq_lseek,
  942. .release = single_release,
  943. };
  944. /**
  945. * debugfs_create_regset32 - create a debugfs file that returns register values
  946. * @name: a pointer to a string containing the name of the file to create.
  947. * @mode: the permission that the file should have
  948. * @parent: a pointer to the parent dentry for this file. This should be a
  949. * directory dentry if set. If this parameter is %NULL, then the
  950. * file will be created in the root of the debugfs filesystem.
  951. * @regset: a pointer to a struct debugfs_regset32, which contains a pointer
  952. * to an array of register definitions, the array size and the base
  953. * address where the register bank is to be found.
  954. *
  955. * This function creates a file in debugfs with the given name that reports
  956. * the names and values of a set of 32-bit registers. If the @mode variable
  957. * is so set it can be read from. Writing is not supported.
  958. *
  959. * This function will return a pointer to a dentry if it succeeds. This
  960. * pointer must be passed to the debugfs_remove() function when the file is
  961. * to be removed (no automatic cleanup happens if your module is unloaded,
  962. * you are responsible here.) If an error occurs, %NULL will be returned.
  963. *
  964. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  965. * returned. It is not wise to check for this value, but rather, check for
  966. * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
  967. * code.
  968. */
  969. struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
  970. struct dentry *parent,
  971. struct debugfs_regset32 *regset)
  972. {
  973. return debugfs_create_file(name, mode, parent, regset, &fops_regset32);
  974. }
  975. EXPORT_SYMBOL_GPL(debugfs_create_regset32);
  976. #endif /* CONFIG_HAS_IOMEM */
  977. struct debugfs_devm_entry {
  978. int (*read)(struct seq_file *seq, void *data);
  979. struct device *dev;
  980. };
  981. static int debugfs_devm_entry_open(struct inode *inode, struct file *f)
  982. {
  983. struct debugfs_devm_entry *entry = inode->i_private;
  984. return single_open(f, entry->read, entry->dev);
  985. }
  986. static const struct file_operations debugfs_devm_entry_ops = {
  987. .owner = THIS_MODULE,
  988. .open = debugfs_devm_entry_open,
  989. .release = single_release,
  990. .read = seq_read,
  991. .llseek = seq_lseek
  992. };
  993. /**
  994. * debugfs_create_devm_seqfile - create a debugfs file that is bound to device.
  995. *
  996. * @dev: device related to this debugfs file.
  997. * @name: name of the debugfs file.
  998. * @parent: a pointer to the parent dentry for this file. This should be a
  999. * directory dentry if set. If this parameter is %NULL, then the
  1000. * file will be created in the root of the debugfs filesystem.
  1001. * @read_fn: function pointer called to print the seq_file content.
  1002. */
  1003. struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name,
  1004. struct dentry *parent,
  1005. int (*read_fn)(struct seq_file *s,
  1006. void *data))
  1007. {
  1008. struct debugfs_devm_entry *entry;
  1009. if (IS_ERR(parent))
  1010. return ERR_PTR(-ENOENT);
  1011. entry = devm_kzalloc(dev, sizeof(*entry), GFP_KERNEL);
  1012. if (!entry)
  1013. return ERR_PTR(-ENOMEM);
  1014. entry->read = read_fn;
  1015. entry->dev = dev;
  1016. return debugfs_create_file(name, S_IRUGO, parent, entry,
  1017. &debugfs_devm_entry_ops);
  1018. }
  1019. EXPORT_SYMBOL_GPL(debugfs_create_devm_seqfile);