dynamic_debug.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * lib/dynamic_debug.c
  3. *
  4. * make pr_debug()/dev_dbg() calls runtime configurable based upon their
  5. * source module.
  6. *
  7. * Copyright (C) 2008 Jason Baron <jbaron@redhat.com>
  8. * By Greg Banks <gnb@melbourne.sgi.com>
  9. * Copyright (c) 2008 Silicon Graphics Inc. All Rights Reserved.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/kallsyms.h>
  15. #include <linux/version.h>
  16. #include <linux/types.h>
  17. #include <linux/mutex.h>
  18. #include <linux/proc_fs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/list.h>
  21. #include <linux/sysctl.h>
  22. #include <linux/ctype.h>
  23. #include <linux/string.h>
  24. #include <linux/uaccess.h>
  25. #include <linux/dynamic_debug.h>
  26. #include <linux/debugfs.h>
  27. #include <linux/slab.h>
  28. #include <linux/jump_label.h>
  29. extern struct _ddebug __start___verbose[];
  30. extern struct _ddebug __stop___verbose[];
  31. struct ddebug_table {
  32. struct list_head link;
  33. char *mod_name;
  34. unsigned int num_ddebugs;
  35. unsigned int num_enabled;
  36. struct _ddebug *ddebugs;
  37. };
  38. struct ddebug_query {
  39. const char *filename;
  40. const char *module;
  41. const char *function;
  42. const char *format;
  43. unsigned int first_lineno, last_lineno;
  44. };
  45. struct ddebug_iter {
  46. struct ddebug_table *table;
  47. unsigned int idx;
  48. };
  49. static DEFINE_MUTEX(ddebug_lock);
  50. static LIST_HEAD(ddebug_tables);
  51. static int verbose = 0;
  52. /* Return the last part of a pathname */
  53. static inline const char *basename(const char *path)
  54. {
  55. const char *tail = strrchr(path, '/');
  56. return tail ? tail+1 : path;
  57. }
  58. /* format a string into buf[] which describes the _ddebug's flags */
  59. static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
  60. size_t maxlen)
  61. {
  62. char *p = buf;
  63. BUG_ON(maxlen < 4);
  64. if (dp->flags & _DPRINTK_FLAGS_PRINT)
  65. *p++ = 'p';
  66. if (p == buf)
  67. *p++ = '-';
  68. *p = '\0';
  69. return buf;
  70. }
  71. /*
  72. * Search the tables for _ddebug's which match the given
  73. * `query' and apply the `flags' and `mask' to them. Tells
  74. * the user which ddebug's were changed, or whether none
  75. * were matched.
  76. */
  77. static void ddebug_change(const struct ddebug_query *query,
  78. unsigned int flags, unsigned int mask)
  79. {
  80. int i;
  81. struct ddebug_table *dt;
  82. unsigned int newflags;
  83. unsigned int nfound = 0;
  84. char flagbuf[8];
  85. /* search for matching ddebugs */
  86. mutex_lock(&ddebug_lock);
  87. list_for_each_entry(dt, &ddebug_tables, link) {
  88. /* match against the module name */
  89. if (query->module != NULL &&
  90. strcmp(query->module, dt->mod_name))
  91. continue;
  92. for (i = 0 ; i < dt->num_ddebugs ; i++) {
  93. struct _ddebug *dp = &dt->ddebugs[i];
  94. /* match against the source filename */
  95. if (query->filename != NULL &&
  96. strcmp(query->filename, dp->filename) &&
  97. strcmp(query->filename, basename(dp->filename)))
  98. continue;
  99. /* match against the function */
  100. if (query->function != NULL &&
  101. strcmp(query->function, dp->function))
  102. continue;
  103. /* match against the format */
  104. if (query->format != NULL &&
  105. strstr(dp->format, query->format) == NULL)
  106. continue;
  107. /* match against the line number range */
  108. if (query->first_lineno &&
  109. dp->lineno < query->first_lineno)
  110. continue;
  111. if (query->last_lineno &&
  112. dp->lineno > query->last_lineno)
  113. continue;
  114. nfound++;
  115. newflags = (dp->flags & mask) | flags;
  116. if (newflags == dp->flags)
  117. continue;
  118. if (!newflags)
  119. dt->num_enabled--;
  120. else if (!dp->flags)
  121. dt->num_enabled++;
  122. dp->flags = newflags;
  123. if (newflags) {
  124. enable_jump_label(&dp->enabled);
  125. } else {
  126. disable_jump_label(&dp->enabled);
  127. }
  128. if (verbose)
  129. printk(KERN_INFO
  130. "ddebug: changed %s:%d [%s]%s %s\n",
  131. dp->filename, dp->lineno,
  132. dt->mod_name, dp->function,
  133. ddebug_describe_flags(dp, flagbuf,
  134. sizeof(flagbuf)));
  135. }
  136. }
  137. mutex_unlock(&ddebug_lock);
  138. if (!nfound && verbose)
  139. printk(KERN_INFO "ddebug: no matches for query\n");
  140. }
  141. /*
  142. * Split the buffer `buf' into space-separated words.
  143. * Handles simple " and ' quoting, i.e. without nested,
  144. * embedded or escaped \". Return the number of words
  145. * or <0 on error.
  146. */
  147. static int ddebug_tokenize(char *buf, char *words[], int maxwords)
  148. {
  149. int nwords = 0;
  150. while (*buf) {
  151. char *end;
  152. /* Skip leading whitespace */
  153. buf = skip_spaces(buf);
  154. if (!*buf)
  155. break; /* oh, it was trailing whitespace */
  156. /* Run `end' over a word, either whitespace separated or quoted */
  157. if (*buf == '"' || *buf == '\'') {
  158. int quote = *buf++;
  159. for (end = buf ; *end && *end != quote ; end++)
  160. ;
  161. if (!*end)
  162. return -EINVAL; /* unclosed quote */
  163. } else {
  164. for (end = buf ; *end && !isspace(*end) ; end++)
  165. ;
  166. BUG_ON(end == buf);
  167. }
  168. /* Here `buf' is the start of the word, `end' is one past the end */
  169. if (nwords == maxwords)
  170. return -EINVAL; /* ran out of words[] before bytes */
  171. if (*end)
  172. *end++ = '\0'; /* terminate the word */
  173. words[nwords++] = buf;
  174. buf = end;
  175. }
  176. if (verbose) {
  177. int i;
  178. printk(KERN_INFO "%s: split into words:", __func__);
  179. for (i = 0 ; i < nwords ; i++)
  180. printk(" \"%s\"", words[i]);
  181. printk("\n");
  182. }
  183. return nwords;
  184. }
  185. /*
  186. * Parse a single line number. Note that the empty string ""
  187. * is treated as a special case and converted to zero, which
  188. * is later treated as a "don't care" value.
  189. */
  190. static inline int parse_lineno(const char *str, unsigned int *val)
  191. {
  192. char *end = NULL;
  193. BUG_ON(str == NULL);
  194. if (*str == '\0') {
  195. *val = 0;
  196. return 0;
  197. }
  198. *val = simple_strtoul(str, &end, 10);
  199. return end == NULL || end == str || *end != '\0' ? -EINVAL : 0;
  200. }
  201. /*
  202. * Undo octal escaping in a string, inplace. This is useful to
  203. * allow the user to express a query which matches a format
  204. * containing embedded spaces.
  205. */
  206. #define isodigit(c) ((c) >= '0' && (c) <= '7')
  207. static char *unescape(char *str)
  208. {
  209. char *in = str;
  210. char *out = str;
  211. while (*in) {
  212. if (*in == '\\') {
  213. if (in[1] == '\\') {
  214. *out++ = '\\';
  215. in += 2;
  216. continue;
  217. } else if (in[1] == 't') {
  218. *out++ = '\t';
  219. in += 2;
  220. continue;
  221. } else if (in[1] == 'n') {
  222. *out++ = '\n';
  223. in += 2;
  224. continue;
  225. } else if (isodigit(in[1]) &&
  226. isodigit(in[2]) &&
  227. isodigit(in[3])) {
  228. *out++ = ((in[1] - '0')<<6) |
  229. ((in[2] - '0')<<3) |
  230. (in[3] - '0');
  231. in += 4;
  232. continue;
  233. }
  234. }
  235. *out++ = *in++;
  236. }
  237. *out = '\0';
  238. return str;
  239. }
  240. /*
  241. * Parse words[] as a ddebug query specification, which is a series
  242. * of (keyword, value) pairs chosen from these possibilities:
  243. *
  244. * func <function-name>
  245. * file <full-pathname>
  246. * file <base-filename>
  247. * module <module-name>
  248. * format <escaped-string-to-find-in-format>
  249. * line <lineno>
  250. * line <first-lineno>-<last-lineno> // where either may be empty
  251. */
  252. static int ddebug_parse_query(char *words[], int nwords,
  253. struct ddebug_query *query)
  254. {
  255. unsigned int i;
  256. /* check we have an even number of words */
  257. if (nwords % 2 != 0)
  258. return -EINVAL;
  259. memset(query, 0, sizeof(*query));
  260. for (i = 0 ; i < nwords ; i += 2) {
  261. if (!strcmp(words[i], "func"))
  262. query->function = words[i+1];
  263. else if (!strcmp(words[i], "file"))
  264. query->filename = words[i+1];
  265. else if (!strcmp(words[i], "module"))
  266. query->module = words[i+1];
  267. else if (!strcmp(words[i], "format"))
  268. query->format = unescape(words[i+1]);
  269. else if (!strcmp(words[i], "line")) {
  270. char *first = words[i+1];
  271. char *last = strchr(first, '-');
  272. if (last)
  273. *last++ = '\0';
  274. if (parse_lineno(first, &query->first_lineno) < 0)
  275. return -EINVAL;
  276. if (last != NULL) {
  277. /* range <first>-<last> */
  278. if (parse_lineno(last, &query->last_lineno) < 0)
  279. return -EINVAL;
  280. } else {
  281. query->last_lineno = query->first_lineno;
  282. }
  283. } else {
  284. if (verbose)
  285. printk(KERN_ERR "%s: unknown keyword \"%s\"\n",
  286. __func__, words[i]);
  287. return -EINVAL;
  288. }
  289. }
  290. if (verbose)
  291. printk(KERN_INFO "%s: q->function=\"%s\" q->filename=\"%s\" "
  292. "q->module=\"%s\" q->format=\"%s\" q->lineno=%u-%u\n",
  293. __func__, query->function, query->filename,
  294. query->module, query->format, query->first_lineno,
  295. query->last_lineno);
  296. return 0;
  297. }
  298. /*
  299. * Parse `str' as a flags specification, format [-+=][p]+.
  300. * Sets up *maskp and *flagsp to be used when changing the
  301. * flags fields of matched _ddebug's. Returns 0 on success
  302. * or <0 on error.
  303. */
  304. static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
  305. unsigned int *maskp)
  306. {
  307. unsigned flags = 0;
  308. int op = '=';
  309. switch (*str) {
  310. case '+':
  311. case '-':
  312. case '=':
  313. op = *str++;
  314. break;
  315. default:
  316. return -EINVAL;
  317. }
  318. if (verbose)
  319. printk(KERN_INFO "%s: op='%c'\n", __func__, op);
  320. for ( ; *str ; ++str) {
  321. switch (*str) {
  322. case 'p':
  323. flags |= _DPRINTK_FLAGS_PRINT;
  324. break;
  325. default:
  326. return -EINVAL;
  327. }
  328. }
  329. if (flags == 0)
  330. return -EINVAL;
  331. if (verbose)
  332. printk(KERN_INFO "%s: flags=0x%x\n", __func__, flags);
  333. /* calculate final *flagsp, *maskp according to mask and op */
  334. switch (op) {
  335. case '=':
  336. *maskp = 0;
  337. *flagsp = flags;
  338. break;
  339. case '+':
  340. *maskp = ~0U;
  341. *flagsp = flags;
  342. break;
  343. case '-':
  344. *maskp = ~flags;
  345. *flagsp = 0;
  346. break;
  347. }
  348. if (verbose)
  349. printk(KERN_INFO "%s: *flagsp=0x%x *maskp=0x%x\n",
  350. __func__, *flagsp, *maskp);
  351. return 0;
  352. }
  353. /*
  354. * File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the
  355. * command text from userspace, parses and executes it.
  356. */
  357. static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
  358. size_t len, loff_t *offp)
  359. {
  360. unsigned int flags = 0, mask = 0;
  361. struct ddebug_query query;
  362. #define MAXWORDS 9
  363. int nwords;
  364. char *words[MAXWORDS];
  365. char tmpbuf[256];
  366. if (len == 0)
  367. return 0;
  368. /* we don't check *offp -- multiple writes() are allowed */
  369. if (len > sizeof(tmpbuf)-1)
  370. return -E2BIG;
  371. if (copy_from_user(tmpbuf, ubuf, len))
  372. return -EFAULT;
  373. tmpbuf[len] = '\0';
  374. if (verbose)
  375. printk(KERN_INFO "%s: read %d bytes from userspace\n",
  376. __func__, (int)len);
  377. nwords = ddebug_tokenize(tmpbuf, words, MAXWORDS);
  378. if (nwords <= 0)
  379. return -EINVAL;
  380. if (ddebug_parse_query(words, nwords-1, &query))
  381. return -EINVAL;
  382. if (ddebug_parse_flags(words[nwords-1], &flags, &mask))
  383. return -EINVAL;
  384. /* actually go and implement the change */
  385. ddebug_change(&query, flags, mask);
  386. *offp += len;
  387. return len;
  388. }
  389. /*
  390. * Set the iterator to point to the first _ddebug object
  391. * and return a pointer to that first object. Returns
  392. * NULL if there are no _ddebugs at all.
  393. */
  394. static struct _ddebug *ddebug_iter_first(struct ddebug_iter *iter)
  395. {
  396. if (list_empty(&ddebug_tables)) {
  397. iter->table = NULL;
  398. iter->idx = 0;
  399. return NULL;
  400. }
  401. iter->table = list_entry(ddebug_tables.next,
  402. struct ddebug_table, link);
  403. iter->idx = 0;
  404. return &iter->table->ddebugs[iter->idx];
  405. }
  406. /*
  407. * Advance the iterator to point to the next _ddebug
  408. * object from the one the iterator currently points at,
  409. * and returns a pointer to the new _ddebug. Returns
  410. * NULL if the iterator has seen all the _ddebugs.
  411. */
  412. static struct _ddebug *ddebug_iter_next(struct ddebug_iter *iter)
  413. {
  414. if (iter->table == NULL)
  415. return NULL;
  416. if (++iter->idx == iter->table->num_ddebugs) {
  417. /* iterate to next table */
  418. iter->idx = 0;
  419. if (list_is_last(&iter->table->link, &ddebug_tables)) {
  420. iter->table = NULL;
  421. return NULL;
  422. }
  423. iter->table = list_entry(iter->table->link.next,
  424. struct ddebug_table, link);
  425. }
  426. return &iter->table->ddebugs[iter->idx];
  427. }
  428. /*
  429. * Seq_ops start method. Called at the start of every
  430. * read() call from userspace. Takes the ddebug_lock and
  431. * seeks the seq_file's iterator to the given position.
  432. */
  433. static void *ddebug_proc_start(struct seq_file *m, loff_t *pos)
  434. {
  435. struct ddebug_iter *iter = m->private;
  436. struct _ddebug *dp;
  437. int n = *pos;
  438. if (verbose)
  439. printk(KERN_INFO "%s: called m=%p *pos=%lld\n",
  440. __func__, m, (unsigned long long)*pos);
  441. mutex_lock(&ddebug_lock);
  442. if (!n)
  443. return SEQ_START_TOKEN;
  444. if (n < 0)
  445. return NULL;
  446. dp = ddebug_iter_first(iter);
  447. while (dp != NULL && --n > 0)
  448. dp = ddebug_iter_next(iter);
  449. return dp;
  450. }
  451. /*
  452. * Seq_ops next method. Called several times within a read()
  453. * call from userspace, with ddebug_lock held. Walks to the
  454. * next _ddebug object with a special case for the header line.
  455. */
  456. static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
  457. {
  458. struct ddebug_iter *iter = m->private;
  459. struct _ddebug *dp;
  460. if (verbose)
  461. printk(KERN_INFO "%s: called m=%p p=%p *pos=%lld\n",
  462. __func__, m, p, (unsigned long long)*pos);
  463. if (p == SEQ_START_TOKEN)
  464. dp = ddebug_iter_first(iter);
  465. else
  466. dp = ddebug_iter_next(iter);
  467. ++*pos;
  468. return dp;
  469. }
  470. /*
  471. * Seq_ops show method. Called several times within a read()
  472. * call from userspace, with ddebug_lock held. Formats the
  473. * current _ddebug as a single human-readable line, with a
  474. * special case for the header line.
  475. */
  476. static int ddebug_proc_show(struct seq_file *m, void *p)
  477. {
  478. struct ddebug_iter *iter = m->private;
  479. struct _ddebug *dp = p;
  480. char flagsbuf[8];
  481. if (verbose)
  482. printk(KERN_INFO "%s: called m=%p p=%p\n",
  483. __func__, m, p);
  484. if (p == SEQ_START_TOKEN) {
  485. seq_puts(m,
  486. "# filename:lineno [module]function flags format\n");
  487. return 0;
  488. }
  489. seq_printf(m, "%s:%u [%s]%s %s \"",
  490. dp->filename, dp->lineno,
  491. iter->table->mod_name, dp->function,
  492. ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf)));
  493. seq_escape(m, dp->format, "\t\r\n\"");
  494. seq_puts(m, "\"\n");
  495. return 0;
  496. }
  497. /*
  498. * Seq_ops stop method. Called at the end of each read()
  499. * call from userspace. Drops ddebug_lock.
  500. */
  501. static void ddebug_proc_stop(struct seq_file *m, void *p)
  502. {
  503. if (verbose)
  504. printk(KERN_INFO "%s: called m=%p p=%p\n",
  505. __func__, m, p);
  506. mutex_unlock(&ddebug_lock);
  507. }
  508. static const struct seq_operations ddebug_proc_seqops = {
  509. .start = ddebug_proc_start,
  510. .next = ddebug_proc_next,
  511. .show = ddebug_proc_show,
  512. .stop = ddebug_proc_stop
  513. };
  514. /*
  515. * File_ops->open method for <debugfs>/dynamic_debug/control. Does the seq_file
  516. * setup dance, and also creates an iterator to walk the _ddebugs.
  517. * Note that we create a seq_file always, even for O_WRONLY files
  518. * where it's not needed, as doing so simplifies the ->release method.
  519. */
  520. static int ddebug_proc_open(struct inode *inode, struct file *file)
  521. {
  522. struct ddebug_iter *iter;
  523. int err;
  524. if (verbose)
  525. printk(KERN_INFO "%s: called\n", __func__);
  526. iter = kzalloc(sizeof(*iter), GFP_KERNEL);
  527. if (iter == NULL)
  528. return -ENOMEM;
  529. err = seq_open(file, &ddebug_proc_seqops);
  530. if (err) {
  531. kfree(iter);
  532. return err;
  533. }
  534. ((struct seq_file *) file->private_data)->private = iter;
  535. return 0;
  536. }
  537. static const struct file_operations ddebug_proc_fops = {
  538. .owner = THIS_MODULE,
  539. .open = ddebug_proc_open,
  540. .read = seq_read,
  541. .llseek = seq_lseek,
  542. .release = seq_release_private,
  543. .write = ddebug_proc_write
  544. };
  545. /*
  546. * Allocate a new ddebug_table for the given module
  547. * and add it to the global list.
  548. */
  549. int ddebug_add_module(struct _ddebug *tab, unsigned int n,
  550. const char *name)
  551. {
  552. struct ddebug_table *dt;
  553. char *new_name;
  554. dt = kzalloc(sizeof(*dt), GFP_KERNEL);
  555. if (dt == NULL)
  556. return -ENOMEM;
  557. new_name = kstrdup(name, GFP_KERNEL);
  558. if (new_name == NULL) {
  559. kfree(dt);
  560. return -ENOMEM;
  561. }
  562. dt->mod_name = new_name;
  563. dt->num_ddebugs = n;
  564. dt->num_enabled = 0;
  565. dt->ddebugs = tab;
  566. mutex_lock(&ddebug_lock);
  567. list_add_tail(&dt->link, &ddebug_tables);
  568. mutex_unlock(&ddebug_lock);
  569. if (verbose)
  570. printk(KERN_INFO "%u debug prints in module %s\n",
  571. n, dt->mod_name);
  572. return 0;
  573. }
  574. EXPORT_SYMBOL_GPL(ddebug_add_module);
  575. static void ddebug_table_free(struct ddebug_table *dt)
  576. {
  577. list_del_init(&dt->link);
  578. kfree(dt->mod_name);
  579. kfree(dt);
  580. }
  581. /*
  582. * Called in response to a module being unloaded. Removes
  583. * any ddebug_table's which point at the module.
  584. */
  585. int ddebug_remove_module(const char *mod_name)
  586. {
  587. struct ddebug_table *dt, *nextdt;
  588. int ret = -ENOENT;
  589. if (verbose)
  590. printk(KERN_INFO "%s: removing module \"%s\"\n",
  591. __func__, mod_name);
  592. mutex_lock(&ddebug_lock);
  593. list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) {
  594. if (!strcmp(dt->mod_name, mod_name)) {
  595. ddebug_table_free(dt);
  596. ret = 0;
  597. }
  598. }
  599. mutex_unlock(&ddebug_lock);
  600. return ret;
  601. }
  602. EXPORT_SYMBOL_GPL(ddebug_remove_module);
  603. static void ddebug_remove_all_tables(void)
  604. {
  605. mutex_lock(&ddebug_lock);
  606. while (!list_empty(&ddebug_tables)) {
  607. struct ddebug_table *dt = list_entry(ddebug_tables.next,
  608. struct ddebug_table,
  609. link);
  610. ddebug_table_free(dt);
  611. }
  612. mutex_unlock(&ddebug_lock);
  613. }
  614. static int __init dynamic_debug_init(void)
  615. {
  616. struct dentry *dir, *file;
  617. struct _ddebug *iter, *iter_start;
  618. const char *modname = NULL;
  619. int ret = 0;
  620. int n = 0;
  621. dir = debugfs_create_dir("dynamic_debug", NULL);
  622. if (!dir)
  623. return -ENOMEM;
  624. file = debugfs_create_file("control", 0644, dir, NULL,
  625. &ddebug_proc_fops);
  626. if (!file) {
  627. debugfs_remove(dir);
  628. return -ENOMEM;
  629. }
  630. if (__start___verbose != __stop___verbose) {
  631. iter = __start___verbose;
  632. modname = iter->modname;
  633. iter_start = iter;
  634. for (; iter < __stop___verbose; iter++) {
  635. if (strcmp(modname, iter->modname)) {
  636. ret = ddebug_add_module(iter_start, n, modname);
  637. if (ret)
  638. goto out_free;
  639. n = 0;
  640. modname = iter->modname;
  641. iter_start = iter;
  642. }
  643. n++;
  644. }
  645. ret = ddebug_add_module(iter_start, n, modname);
  646. }
  647. out_free:
  648. if (ret) {
  649. ddebug_remove_all_tables();
  650. debugfs_remove(dir);
  651. debugfs_remove(file);
  652. }
  653. return 0;
  654. }
  655. module_init(dynamic_debug_init);