mtdcore.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. /*
  2. * Core registration and callback routines for MTD
  3. * drivers and users.
  4. *
  5. * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
  6. * Copyright © 2006 Red Hat UK Limited
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/kernel.h>
  25. #include <linux/ptrace.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/string.h>
  28. #include <linux/timer.h>
  29. #include <linux/major.h>
  30. #include <linux/fs.h>
  31. #include <linux/err.h>
  32. #include <linux/ioctl.h>
  33. #include <linux/init.h>
  34. #include <linux/proc_fs.h>
  35. #include <linux/idr.h>
  36. #include <linux/backing-dev.h>
  37. #include <linux/gfp.h>
  38. #include <linux/slab.h>
  39. #include <linux/mtd/mtd.h>
  40. #include <linux/mtd/partitions.h>
  41. #include "mtdcore.h"
  42. static struct backing_dev_info mtd_bdi = {
  43. };
  44. static int mtd_cls_suspend(struct device *dev, pm_message_t state);
  45. static int mtd_cls_resume(struct device *dev);
  46. static struct class mtd_class = {
  47. .name = "mtd",
  48. .owner = THIS_MODULE,
  49. .suspend = mtd_cls_suspend,
  50. .resume = mtd_cls_resume,
  51. };
  52. static DEFINE_IDR(mtd_idr);
  53. /* These are exported solely for the purpose of mtd_blkdevs.c. You
  54. should not use them for _anything_ else */
  55. DEFINE_MUTEX(mtd_table_mutex);
  56. EXPORT_SYMBOL_GPL(mtd_table_mutex);
  57. struct mtd_info *__mtd_next_device(int i)
  58. {
  59. return idr_get_next(&mtd_idr, &i);
  60. }
  61. EXPORT_SYMBOL_GPL(__mtd_next_device);
  62. static LIST_HEAD(mtd_notifiers);
  63. #define MTD_DEVT(index) MKDEV(MTD_CHAR_MAJOR, (index)*2)
  64. /* REVISIT once MTD uses the driver model better, whoever allocates
  65. * the mtd_info will probably want to use the release() hook...
  66. */
  67. static void mtd_release(struct device *dev)
  68. {
  69. struct mtd_info *mtd = dev_get_drvdata(dev);
  70. dev_t index = MTD_DEVT(mtd->index);
  71. /* remove /dev/mtdXro node */
  72. device_destroy(&mtd_class, index + 1);
  73. }
  74. static int mtd_cls_suspend(struct device *dev, pm_message_t state)
  75. {
  76. struct mtd_info *mtd = dev_get_drvdata(dev);
  77. return mtd ? mtd_suspend(mtd) : 0;
  78. }
  79. static int mtd_cls_resume(struct device *dev)
  80. {
  81. struct mtd_info *mtd = dev_get_drvdata(dev);
  82. if (mtd)
  83. mtd_resume(mtd);
  84. return 0;
  85. }
  86. static ssize_t mtd_type_show(struct device *dev,
  87. struct device_attribute *attr, char *buf)
  88. {
  89. struct mtd_info *mtd = dev_get_drvdata(dev);
  90. char *type;
  91. switch (mtd->type) {
  92. case MTD_ABSENT:
  93. type = "absent";
  94. break;
  95. case MTD_RAM:
  96. type = "ram";
  97. break;
  98. case MTD_ROM:
  99. type = "rom";
  100. break;
  101. case MTD_NORFLASH:
  102. type = "nor";
  103. break;
  104. case MTD_NANDFLASH:
  105. type = "nand";
  106. break;
  107. case MTD_DATAFLASH:
  108. type = "dataflash";
  109. break;
  110. case MTD_UBIVOLUME:
  111. type = "ubi";
  112. break;
  113. case MTD_MLCNANDFLASH:
  114. type = "mlc-nand";
  115. break;
  116. default:
  117. type = "unknown";
  118. }
  119. return snprintf(buf, PAGE_SIZE, "%s\n", type);
  120. }
  121. static DEVICE_ATTR(type, S_IRUGO, mtd_type_show, NULL);
  122. static ssize_t mtd_flags_show(struct device *dev,
  123. struct device_attribute *attr, char *buf)
  124. {
  125. struct mtd_info *mtd = dev_get_drvdata(dev);
  126. return snprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)mtd->flags);
  127. }
  128. static DEVICE_ATTR(flags, S_IRUGO, mtd_flags_show, NULL);
  129. static ssize_t mtd_size_show(struct device *dev,
  130. struct device_attribute *attr, char *buf)
  131. {
  132. struct mtd_info *mtd = dev_get_drvdata(dev);
  133. return snprintf(buf, PAGE_SIZE, "%llu\n",
  134. (unsigned long long)mtd->size);
  135. }
  136. static DEVICE_ATTR(size, S_IRUGO, mtd_size_show, NULL);
  137. static ssize_t mtd_erasesize_show(struct device *dev,
  138. struct device_attribute *attr, char *buf)
  139. {
  140. struct mtd_info *mtd = dev_get_drvdata(dev);
  141. return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->erasesize);
  142. }
  143. static DEVICE_ATTR(erasesize, S_IRUGO, mtd_erasesize_show, NULL);
  144. static ssize_t mtd_writesize_show(struct device *dev,
  145. struct device_attribute *attr, char *buf)
  146. {
  147. struct mtd_info *mtd = dev_get_drvdata(dev);
  148. return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->writesize);
  149. }
  150. static DEVICE_ATTR(writesize, S_IRUGO, mtd_writesize_show, NULL);
  151. static ssize_t mtd_subpagesize_show(struct device *dev,
  152. struct device_attribute *attr, char *buf)
  153. {
  154. struct mtd_info *mtd = dev_get_drvdata(dev);
  155. unsigned int subpagesize = mtd->writesize >> mtd->subpage_sft;
  156. return snprintf(buf, PAGE_SIZE, "%u\n", subpagesize);
  157. }
  158. static DEVICE_ATTR(subpagesize, S_IRUGO, mtd_subpagesize_show, NULL);
  159. static ssize_t mtd_oobsize_show(struct device *dev,
  160. struct device_attribute *attr, char *buf)
  161. {
  162. struct mtd_info *mtd = dev_get_drvdata(dev);
  163. return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->oobsize);
  164. }
  165. static DEVICE_ATTR(oobsize, S_IRUGO, mtd_oobsize_show, NULL);
  166. static ssize_t mtd_numeraseregions_show(struct device *dev,
  167. struct device_attribute *attr, char *buf)
  168. {
  169. struct mtd_info *mtd = dev_get_drvdata(dev);
  170. return snprintf(buf, PAGE_SIZE, "%u\n", mtd->numeraseregions);
  171. }
  172. static DEVICE_ATTR(numeraseregions, S_IRUGO, mtd_numeraseregions_show,
  173. NULL);
  174. static ssize_t mtd_name_show(struct device *dev,
  175. struct device_attribute *attr, char *buf)
  176. {
  177. struct mtd_info *mtd = dev_get_drvdata(dev);
  178. return snprintf(buf, PAGE_SIZE, "%s\n", mtd->name);
  179. }
  180. static DEVICE_ATTR(name, S_IRUGO, mtd_name_show, NULL);
  181. static ssize_t mtd_ecc_strength_show(struct device *dev,
  182. struct device_attribute *attr, char *buf)
  183. {
  184. struct mtd_info *mtd = dev_get_drvdata(dev);
  185. return snprintf(buf, PAGE_SIZE, "%u\n", mtd->ecc_strength);
  186. }
  187. static DEVICE_ATTR(ecc_strength, S_IRUGO, mtd_ecc_strength_show, NULL);
  188. static ssize_t mtd_bitflip_threshold_show(struct device *dev,
  189. struct device_attribute *attr,
  190. char *buf)
  191. {
  192. struct mtd_info *mtd = dev_get_drvdata(dev);
  193. return snprintf(buf, PAGE_SIZE, "%u\n", mtd->bitflip_threshold);
  194. }
  195. static ssize_t mtd_bitflip_threshold_store(struct device *dev,
  196. struct device_attribute *attr,
  197. const char *buf, size_t count)
  198. {
  199. struct mtd_info *mtd = dev_get_drvdata(dev);
  200. unsigned int bitflip_threshold;
  201. int retval;
  202. retval = kstrtouint(buf, 0, &bitflip_threshold);
  203. if (retval)
  204. return retval;
  205. mtd->bitflip_threshold = bitflip_threshold;
  206. return count;
  207. }
  208. static DEVICE_ATTR(bitflip_threshold, S_IRUGO | S_IWUSR,
  209. mtd_bitflip_threshold_show,
  210. mtd_bitflip_threshold_store);
  211. static ssize_t mtd_ecc_step_size_show(struct device *dev,
  212. struct device_attribute *attr, char *buf)
  213. {
  214. struct mtd_info *mtd = dev_get_drvdata(dev);
  215. return snprintf(buf, PAGE_SIZE, "%u\n", mtd->ecc_step_size);
  216. }
  217. static DEVICE_ATTR(ecc_step_size, S_IRUGO, mtd_ecc_step_size_show, NULL);
  218. static ssize_t mtd_ecc_stats_corrected_show(struct device *dev,
  219. struct device_attribute *attr, char *buf)
  220. {
  221. struct mtd_info *mtd = dev_get_drvdata(dev);
  222. struct mtd_ecc_stats *ecc_stats = &mtd->ecc_stats;
  223. return snprintf(buf, PAGE_SIZE, "%u\n", ecc_stats->corrected);
  224. }
  225. static DEVICE_ATTR(corrected_bits, S_IRUGO,
  226. mtd_ecc_stats_corrected_show, NULL);
  227. static ssize_t mtd_ecc_stats_errors_show(struct device *dev,
  228. struct device_attribute *attr, char *buf)
  229. {
  230. struct mtd_info *mtd = dev_get_drvdata(dev);
  231. struct mtd_ecc_stats *ecc_stats = &mtd->ecc_stats;
  232. return snprintf(buf, PAGE_SIZE, "%u\n", ecc_stats->failed);
  233. }
  234. static DEVICE_ATTR(ecc_failures, S_IRUGO, mtd_ecc_stats_errors_show, NULL);
  235. static ssize_t mtd_badblocks_show(struct device *dev,
  236. struct device_attribute *attr, char *buf)
  237. {
  238. struct mtd_info *mtd = dev_get_drvdata(dev);
  239. struct mtd_ecc_stats *ecc_stats = &mtd->ecc_stats;
  240. return snprintf(buf, PAGE_SIZE, "%u\n", ecc_stats->badblocks);
  241. }
  242. static DEVICE_ATTR(bad_blocks, S_IRUGO, mtd_badblocks_show, NULL);
  243. static ssize_t mtd_bbtblocks_show(struct device *dev,
  244. struct device_attribute *attr, char *buf)
  245. {
  246. struct mtd_info *mtd = dev_get_drvdata(dev);
  247. struct mtd_ecc_stats *ecc_stats = &mtd->ecc_stats;
  248. return snprintf(buf, PAGE_SIZE, "%u\n", ecc_stats->bbtblocks);
  249. }
  250. static DEVICE_ATTR(bbt_blocks, S_IRUGO, mtd_bbtblocks_show, NULL);
  251. static struct attribute *mtd_attrs[] = {
  252. &dev_attr_type.attr,
  253. &dev_attr_flags.attr,
  254. &dev_attr_size.attr,
  255. &dev_attr_erasesize.attr,
  256. &dev_attr_writesize.attr,
  257. &dev_attr_subpagesize.attr,
  258. &dev_attr_oobsize.attr,
  259. &dev_attr_numeraseregions.attr,
  260. &dev_attr_name.attr,
  261. &dev_attr_ecc_strength.attr,
  262. &dev_attr_ecc_step_size.attr,
  263. &dev_attr_corrected_bits.attr,
  264. &dev_attr_ecc_failures.attr,
  265. &dev_attr_bad_blocks.attr,
  266. &dev_attr_bbt_blocks.attr,
  267. &dev_attr_bitflip_threshold.attr,
  268. NULL,
  269. };
  270. ATTRIBUTE_GROUPS(mtd);
  271. static struct device_type mtd_devtype = {
  272. .name = "mtd",
  273. .groups = mtd_groups,
  274. .release = mtd_release,
  275. };
  276. #ifndef CONFIG_MMU
  277. unsigned mtd_mmap_capabilities(struct mtd_info *mtd)
  278. {
  279. switch (mtd->type) {
  280. case MTD_RAM:
  281. return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC |
  282. NOMMU_MAP_READ | NOMMU_MAP_WRITE;
  283. case MTD_ROM:
  284. return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC |
  285. NOMMU_MAP_READ;
  286. default:
  287. return NOMMU_MAP_COPY;
  288. }
  289. }
  290. #endif
  291. /**
  292. * add_mtd_device - register an MTD device
  293. * @mtd: pointer to new MTD device info structure
  294. *
  295. * Add a device to the list of MTD devices present in the system, and
  296. * notify each currently active MTD 'user' of its arrival. Returns
  297. * zero on success or 1 on failure, which currently will only happen
  298. * if there is insufficient memory or a sysfs error.
  299. */
  300. int add_mtd_device(struct mtd_info *mtd)
  301. {
  302. struct mtd_notifier *not;
  303. int i, error;
  304. mtd->backing_dev_info = &mtd_bdi;
  305. BUG_ON(mtd->writesize == 0);
  306. mutex_lock(&mtd_table_mutex);
  307. i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
  308. if (i < 0)
  309. goto fail_locked;
  310. mtd->index = i;
  311. mtd->usecount = 0;
  312. /* default value if not set by driver */
  313. if (mtd->bitflip_threshold == 0)
  314. mtd->bitflip_threshold = mtd->ecc_strength;
  315. if (is_power_of_2(mtd->erasesize))
  316. mtd->erasesize_shift = ffs(mtd->erasesize) - 1;
  317. else
  318. mtd->erasesize_shift = 0;
  319. if (is_power_of_2(mtd->writesize))
  320. mtd->writesize_shift = ffs(mtd->writesize) - 1;
  321. else
  322. mtd->writesize_shift = 0;
  323. mtd->erasesize_mask = (1 << mtd->erasesize_shift) - 1;
  324. mtd->writesize_mask = (1 << mtd->writesize_shift) - 1;
  325. /* Some chips always power up locked. Unlock them now */
  326. if ((mtd->flags & MTD_WRITEABLE) && (mtd->flags & MTD_POWERUP_LOCK)) {
  327. error = mtd_unlock(mtd, 0, mtd->size);
  328. if (error && error != -EOPNOTSUPP)
  329. printk(KERN_WARNING
  330. "%s: unlock failed, writes may not work\n",
  331. mtd->name);
  332. }
  333. /* Caller should have set dev.parent to match the
  334. * physical device.
  335. */
  336. mtd->dev.type = &mtd_devtype;
  337. mtd->dev.class = &mtd_class;
  338. mtd->dev.devt = MTD_DEVT(i);
  339. dev_set_name(&mtd->dev, "mtd%d", i);
  340. dev_set_drvdata(&mtd->dev, mtd);
  341. if (device_register(&mtd->dev) != 0)
  342. goto fail_added;
  343. device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL,
  344. "mtd%dro", i);
  345. pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name);
  346. /* No need to get a refcount on the module containing
  347. the notifier, since we hold the mtd_table_mutex */
  348. list_for_each_entry(not, &mtd_notifiers, list)
  349. not->add(mtd);
  350. mutex_unlock(&mtd_table_mutex);
  351. /* We _know_ we aren't being removed, because
  352. our caller is still holding us here. So none
  353. of this try_ nonsense, and no bitching about it
  354. either. :) */
  355. __module_get(THIS_MODULE);
  356. return 0;
  357. fail_added:
  358. idr_remove(&mtd_idr, i);
  359. fail_locked:
  360. mutex_unlock(&mtd_table_mutex);
  361. return 1;
  362. }
  363. /**
  364. * del_mtd_device - unregister an MTD device
  365. * @mtd: pointer to MTD device info structure
  366. *
  367. * Remove a device from the list of MTD devices present in the system,
  368. * and notify each currently active MTD 'user' of its departure.
  369. * Returns zero on success or 1 on failure, which currently will happen
  370. * if the requested device does not appear to be present in the list.
  371. */
  372. int del_mtd_device(struct mtd_info *mtd)
  373. {
  374. int ret;
  375. struct mtd_notifier *not;
  376. mutex_lock(&mtd_table_mutex);
  377. if (idr_find(&mtd_idr, mtd->index) != mtd) {
  378. ret = -ENODEV;
  379. goto out_error;
  380. }
  381. /* No need to get a refcount on the module containing
  382. the notifier, since we hold the mtd_table_mutex */
  383. list_for_each_entry(not, &mtd_notifiers, list)
  384. not->remove(mtd);
  385. if (mtd->usecount) {
  386. printk(KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n",
  387. mtd->index, mtd->name, mtd->usecount);
  388. ret = -EBUSY;
  389. } else {
  390. device_unregister(&mtd->dev);
  391. idr_remove(&mtd_idr, mtd->index);
  392. module_put(THIS_MODULE);
  393. ret = 0;
  394. }
  395. out_error:
  396. mutex_unlock(&mtd_table_mutex);
  397. return ret;
  398. }
  399. /**
  400. * mtd_device_parse_register - parse partitions and register an MTD device.
  401. *
  402. * @mtd: the MTD device to register
  403. * @types: the list of MTD partition probes to try, see
  404. * 'parse_mtd_partitions()' for more information
  405. * @parser_data: MTD partition parser-specific data
  406. * @parts: fallback partition information to register, if parsing fails;
  407. * only valid if %nr_parts > %0
  408. * @nr_parts: the number of partitions in parts, if zero then the full
  409. * MTD device is registered if no partition info is found
  410. *
  411. * This function aggregates MTD partitions parsing (done by
  412. * 'parse_mtd_partitions()') and MTD device and partitions registering. It
  413. * basically follows the most common pattern found in many MTD drivers:
  414. *
  415. * * It first tries to probe partitions on MTD device @mtd using parsers
  416. * specified in @types (if @types is %NULL, then the default list of parsers
  417. * is used, see 'parse_mtd_partitions()' for more information). If none are
  418. * found this functions tries to fallback to information specified in
  419. * @parts/@nr_parts.
  420. * * If any partitioning info was found, this function registers the found
  421. * partitions.
  422. * * If no partitions were found this function just registers the MTD device
  423. * @mtd and exits.
  424. *
  425. * Returns zero in case of success and a negative error code in case of failure.
  426. */
  427. int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
  428. struct mtd_part_parser_data *parser_data,
  429. const struct mtd_partition *parts,
  430. int nr_parts)
  431. {
  432. int err;
  433. struct mtd_partition *real_parts;
  434. err = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
  435. if (err <= 0 && nr_parts && parts) {
  436. real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
  437. GFP_KERNEL);
  438. if (!real_parts)
  439. err = -ENOMEM;
  440. else
  441. err = nr_parts;
  442. }
  443. if (err > 0) {
  444. err = add_mtd_partitions(mtd, real_parts, err);
  445. kfree(real_parts);
  446. } else if (err == 0) {
  447. err = add_mtd_device(mtd);
  448. if (err == 1)
  449. err = -ENODEV;
  450. }
  451. return err;
  452. }
  453. EXPORT_SYMBOL_GPL(mtd_device_parse_register);
  454. /**
  455. * mtd_device_unregister - unregister an existing MTD device.
  456. *
  457. * @master: the MTD device to unregister. This will unregister both the master
  458. * and any partitions if registered.
  459. */
  460. int mtd_device_unregister(struct mtd_info *master)
  461. {
  462. int err;
  463. err = del_mtd_partitions(master);
  464. if (err)
  465. return err;
  466. if (!device_is_registered(&master->dev))
  467. return 0;
  468. return del_mtd_device(master);
  469. }
  470. EXPORT_SYMBOL_GPL(mtd_device_unregister);
  471. /**
  472. * register_mtd_user - register a 'user' of MTD devices.
  473. * @new: pointer to notifier info structure
  474. *
  475. * Registers a pair of callbacks function to be called upon addition
  476. * or removal of MTD devices. Causes the 'add' callback to be immediately
  477. * invoked for each MTD device currently present in the system.
  478. */
  479. void register_mtd_user (struct mtd_notifier *new)
  480. {
  481. struct mtd_info *mtd;
  482. mutex_lock(&mtd_table_mutex);
  483. list_add(&new->list, &mtd_notifiers);
  484. __module_get(THIS_MODULE);
  485. mtd_for_each_device(mtd)
  486. new->add(mtd);
  487. mutex_unlock(&mtd_table_mutex);
  488. }
  489. EXPORT_SYMBOL_GPL(register_mtd_user);
  490. /**
  491. * unregister_mtd_user - unregister a 'user' of MTD devices.
  492. * @old: pointer to notifier info structure
  493. *
  494. * Removes a callback function pair from the list of 'users' to be
  495. * notified upon addition or removal of MTD devices. Causes the
  496. * 'remove' callback to be immediately invoked for each MTD device
  497. * currently present in the system.
  498. */
  499. int unregister_mtd_user (struct mtd_notifier *old)
  500. {
  501. struct mtd_info *mtd;
  502. mutex_lock(&mtd_table_mutex);
  503. module_put(THIS_MODULE);
  504. mtd_for_each_device(mtd)
  505. old->remove(mtd);
  506. list_del(&old->list);
  507. mutex_unlock(&mtd_table_mutex);
  508. return 0;
  509. }
  510. EXPORT_SYMBOL_GPL(unregister_mtd_user);
  511. /**
  512. * get_mtd_device - obtain a validated handle for an MTD device
  513. * @mtd: last known address of the required MTD device
  514. * @num: internal device number of the required MTD device
  515. *
  516. * Given a number and NULL address, return the num'th entry in the device
  517. * table, if any. Given an address and num == -1, search the device table
  518. * for a device with that address and return if it's still present. Given
  519. * both, return the num'th driver only if its address matches. Return
  520. * error code if not.
  521. */
  522. struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
  523. {
  524. struct mtd_info *ret = NULL, *other;
  525. int err = -ENODEV;
  526. mutex_lock(&mtd_table_mutex);
  527. if (num == -1) {
  528. mtd_for_each_device(other) {
  529. if (other == mtd) {
  530. ret = mtd;
  531. break;
  532. }
  533. }
  534. } else if (num >= 0) {
  535. ret = idr_find(&mtd_idr, num);
  536. if (mtd && mtd != ret)
  537. ret = NULL;
  538. }
  539. if (!ret) {
  540. ret = ERR_PTR(err);
  541. goto out;
  542. }
  543. err = __get_mtd_device(ret);
  544. if (err)
  545. ret = ERR_PTR(err);
  546. out:
  547. mutex_unlock(&mtd_table_mutex);
  548. return ret;
  549. }
  550. EXPORT_SYMBOL_GPL(get_mtd_device);
  551. int __get_mtd_device(struct mtd_info *mtd)
  552. {
  553. int err;
  554. if (!try_module_get(mtd->owner))
  555. return -ENODEV;
  556. if (mtd->_get_device) {
  557. err = mtd->_get_device(mtd);
  558. if (err) {
  559. module_put(mtd->owner);
  560. return err;
  561. }
  562. }
  563. mtd->usecount++;
  564. return 0;
  565. }
  566. EXPORT_SYMBOL_GPL(__get_mtd_device);
  567. /**
  568. * get_mtd_device_nm - obtain a validated handle for an MTD device by
  569. * device name
  570. * @name: MTD device name to open
  571. *
  572. * This function returns MTD device description structure in case of
  573. * success and an error code in case of failure.
  574. */
  575. struct mtd_info *get_mtd_device_nm(const char *name)
  576. {
  577. int err = -ENODEV;
  578. struct mtd_info *mtd = NULL, *other;
  579. mutex_lock(&mtd_table_mutex);
  580. mtd_for_each_device(other) {
  581. if (!strcmp(name, other->name)) {
  582. mtd = other;
  583. break;
  584. }
  585. }
  586. if (!mtd)
  587. goto out_unlock;
  588. err = __get_mtd_device(mtd);
  589. if (err)
  590. goto out_unlock;
  591. mutex_unlock(&mtd_table_mutex);
  592. return mtd;
  593. out_unlock:
  594. mutex_unlock(&mtd_table_mutex);
  595. return ERR_PTR(err);
  596. }
  597. EXPORT_SYMBOL_GPL(get_mtd_device_nm);
  598. void put_mtd_device(struct mtd_info *mtd)
  599. {
  600. mutex_lock(&mtd_table_mutex);
  601. __put_mtd_device(mtd);
  602. mutex_unlock(&mtd_table_mutex);
  603. }
  604. EXPORT_SYMBOL_GPL(put_mtd_device);
  605. void __put_mtd_device(struct mtd_info *mtd)
  606. {
  607. --mtd->usecount;
  608. BUG_ON(mtd->usecount < 0);
  609. if (mtd->_put_device)
  610. mtd->_put_device(mtd);
  611. module_put(mtd->owner);
  612. }
  613. EXPORT_SYMBOL_GPL(__put_mtd_device);
  614. /*
  615. * Erase is an asynchronous operation. Device drivers are supposed
  616. * to call instr->callback() whenever the operation completes, even
  617. * if it completes with a failure.
  618. * Callers are supposed to pass a callback function and wait for it
  619. * to be called before writing to the block.
  620. */
  621. int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
  622. {
  623. if (instr->addr >= mtd->size || instr->len > mtd->size - instr->addr)
  624. return -EINVAL;
  625. if (!(mtd->flags & MTD_WRITEABLE))
  626. return -EROFS;
  627. instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
  628. if (!instr->len) {
  629. instr->state = MTD_ERASE_DONE;
  630. mtd_erase_callback(instr);
  631. return 0;
  632. }
  633. return mtd->_erase(mtd, instr);
  634. }
  635. EXPORT_SYMBOL_GPL(mtd_erase);
  636. /*
  637. * This stuff for eXecute-In-Place. phys is optional and may be set to NULL.
  638. */
  639. int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
  640. void **virt, resource_size_t *phys)
  641. {
  642. *retlen = 0;
  643. *virt = NULL;
  644. if (phys)
  645. *phys = 0;
  646. if (!mtd->_point)
  647. return -EOPNOTSUPP;
  648. if (from < 0 || from >= mtd->size || len > mtd->size - from)
  649. return -EINVAL;
  650. if (!len)
  651. return 0;
  652. return mtd->_point(mtd, from, len, retlen, virt, phys);
  653. }
  654. EXPORT_SYMBOL_GPL(mtd_point);
  655. /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
  656. int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
  657. {
  658. if (!mtd->_point)
  659. return -EOPNOTSUPP;
  660. if (from < 0 || from >= mtd->size || len > mtd->size - from)
  661. return -EINVAL;
  662. if (!len)
  663. return 0;
  664. return mtd->_unpoint(mtd, from, len);
  665. }
  666. EXPORT_SYMBOL_GPL(mtd_unpoint);
  667. /*
  668. * Allow NOMMU mmap() to directly map the device (if not NULL)
  669. * - return the address to which the offset maps
  670. * - return -ENOSYS to indicate refusal to do the mapping
  671. */
  672. unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len,
  673. unsigned long offset, unsigned long flags)
  674. {
  675. if (!mtd->_get_unmapped_area)
  676. return -EOPNOTSUPP;
  677. if (offset >= mtd->size || len > mtd->size - offset)
  678. return -EINVAL;
  679. return mtd->_get_unmapped_area(mtd, len, offset, flags);
  680. }
  681. EXPORT_SYMBOL_GPL(mtd_get_unmapped_area);
  682. int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
  683. u_char *buf)
  684. {
  685. int ret_code;
  686. *retlen = 0;
  687. if (from < 0 || from >= mtd->size || len > mtd->size - from)
  688. return -EINVAL;
  689. if (!len)
  690. return 0;
  691. /*
  692. * In the absence of an error, drivers return a non-negative integer
  693. * representing the maximum number of bitflips that were corrected on
  694. * any one ecc region (if applicable; zero otherwise).
  695. */
  696. ret_code = mtd->_read(mtd, from, len, retlen, buf);
  697. if (unlikely(ret_code < 0))
  698. return ret_code;
  699. if (mtd->ecc_strength == 0)
  700. return 0; /* device lacks ecc */
  701. return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0;
  702. }
  703. EXPORT_SYMBOL_GPL(mtd_read);
  704. int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
  705. const u_char *buf)
  706. {
  707. *retlen = 0;
  708. if (to < 0 || to >= mtd->size || len > mtd->size - to)
  709. return -EINVAL;
  710. if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
  711. return -EROFS;
  712. if (!len)
  713. return 0;
  714. return mtd->_write(mtd, to, len, retlen, buf);
  715. }
  716. EXPORT_SYMBOL_GPL(mtd_write);
  717. /*
  718. * In blackbox flight recorder like scenarios we want to make successful writes
  719. * in interrupt context. panic_write() is only intended to be called when its
  720. * known the kernel is about to panic and we need the write to succeed. Since
  721. * the kernel is not going to be running for much longer, this function can
  722. * break locks and delay to ensure the write succeeds (but not sleep).
  723. */
  724. int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
  725. const u_char *buf)
  726. {
  727. *retlen = 0;
  728. if (!mtd->_panic_write)
  729. return -EOPNOTSUPP;
  730. if (to < 0 || to >= mtd->size || len > mtd->size - to)
  731. return -EINVAL;
  732. if (!(mtd->flags & MTD_WRITEABLE))
  733. return -EROFS;
  734. if (!len)
  735. return 0;
  736. return mtd->_panic_write(mtd, to, len, retlen, buf);
  737. }
  738. EXPORT_SYMBOL_GPL(mtd_panic_write);
  739. int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
  740. {
  741. int ret_code;
  742. ops->retlen = ops->oobretlen = 0;
  743. if (!mtd->_read_oob)
  744. return -EOPNOTSUPP;
  745. /*
  746. * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics
  747. * similar to mtd->_read(), returning a non-negative integer
  748. * representing max bitflips. In other cases, mtd->_read_oob() may
  749. * return -EUCLEAN. In all cases, perform similar logic to mtd_read().
  750. */
  751. ret_code = mtd->_read_oob(mtd, from, ops);
  752. if (unlikely(ret_code < 0))
  753. return ret_code;
  754. if (mtd->ecc_strength == 0)
  755. return 0; /* device lacks ecc */
  756. return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0;
  757. }
  758. EXPORT_SYMBOL_GPL(mtd_read_oob);
  759. /*
  760. * Method to access the protection register area, present in some flash
  761. * devices. The user data is one time programmable but the factory data is read
  762. * only.
  763. */
  764. int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
  765. struct otp_info *buf)
  766. {
  767. if (!mtd->_get_fact_prot_info)
  768. return -EOPNOTSUPP;
  769. if (!len)
  770. return 0;
  771. return mtd->_get_fact_prot_info(mtd, len, retlen, buf);
  772. }
  773. EXPORT_SYMBOL_GPL(mtd_get_fact_prot_info);
  774. int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
  775. size_t *retlen, u_char *buf)
  776. {
  777. *retlen = 0;
  778. if (!mtd->_read_fact_prot_reg)
  779. return -EOPNOTSUPP;
  780. if (!len)
  781. return 0;
  782. return mtd->_read_fact_prot_reg(mtd, from, len, retlen, buf);
  783. }
  784. EXPORT_SYMBOL_GPL(mtd_read_fact_prot_reg);
  785. int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
  786. struct otp_info *buf)
  787. {
  788. if (!mtd->_get_user_prot_info)
  789. return -EOPNOTSUPP;
  790. if (!len)
  791. return 0;
  792. return mtd->_get_user_prot_info(mtd, len, retlen, buf);
  793. }
  794. EXPORT_SYMBOL_GPL(mtd_get_user_prot_info);
  795. int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
  796. size_t *retlen, u_char *buf)
  797. {
  798. *retlen = 0;
  799. if (!mtd->_read_user_prot_reg)
  800. return -EOPNOTSUPP;
  801. if (!len)
  802. return 0;
  803. return mtd->_read_user_prot_reg(mtd, from, len, retlen, buf);
  804. }
  805. EXPORT_SYMBOL_GPL(mtd_read_user_prot_reg);
  806. int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
  807. size_t *retlen, u_char *buf)
  808. {
  809. int ret;
  810. *retlen = 0;
  811. if (!mtd->_write_user_prot_reg)
  812. return -EOPNOTSUPP;
  813. if (!len)
  814. return 0;
  815. ret = mtd->_write_user_prot_reg(mtd, to, len, retlen, buf);
  816. if (ret)
  817. return ret;
  818. /*
  819. * If no data could be written at all, we are out of memory and
  820. * must return -ENOSPC.
  821. */
  822. return (*retlen) ? 0 : -ENOSPC;
  823. }
  824. EXPORT_SYMBOL_GPL(mtd_write_user_prot_reg);
  825. int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len)
  826. {
  827. if (!mtd->_lock_user_prot_reg)
  828. return -EOPNOTSUPP;
  829. if (!len)
  830. return 0;
  831. return mtd->_lock_user_prot_reg(mtd, from, len);
  832. }
  833. EXPORT_SYMBOL_GPL(mtd_lock_user_prot_reg);
  834. /* Chip-supported device locking */
  835. int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
  836. {
  837. if (!mtd->_lock)
  838. return -EOPNOTSUPP;
  839. if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
  840. return -EINVAL;
  841. if (!len)
  842. return 0;
  843. return mtd->_lock(mtd, ofs, len);
  844. }
  845. EXPORT_SYMBOL_GPL(mtd_lock);
  846. int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
  847. {
  848. if (!mtd->_unlock)
  849. return -EOPNOTSUPP;
  850. if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
  851. return -EINVAL;
  852. if (!len)
  853. return 0;
  854. return mtd->_unlock(mtd, ofs, len);
  855. }
  856. EXPORT_SYMBOL_GPL(mtd_unlock);
  857. int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
  858. {
  859. if (!mtd->_is_locked)
  860. return -EOPNOTSUPP;
  861. if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
  862. return -EINVAL;
  863. if (!len)
  864. return 0;
  865. return mtd->_is_locked(mtd, ofs, len);
  866. }
  867. EXPORT_SYMBOL_GPL(mtd_is_locked);
  868. int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs)
  869. {
  870. if (ofs < 0 || ofs >= mtd->size)
  871. return -EINVAL;
  872. if (!mtd->_block_isreserved)
  873. return 0;
  874. return mtd->_block_isreserved(mtd, ofs);
  875. }
  876. EXPORT_SYMBOL_GPL(mtd_block_isreserved);
  877. int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
  878. {
  879. if (ofs < 0 || ofs >= mtd->size)
  880. return -EINVAL;
  881. if (!mtd->_block_isbad)
  882. return 0;
  883. return mtd->_block_isbad(mtd, ofs);
  884. }
  885. EXPORT_SYMBOL_GPL(mtd_block_isbad);
  886. int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
  887. {
  888. if (!mtd->_block_markbad)
  889. return -EOPNOTSUPP;
  890. if (ofs < 0 || ofs >= mtd->size)
  891. return -EINVAL;
  892. if (!(mtd->flags & MTD_WRITEABLE))
  893. return -EROFS;
  894. return mtd->_block_markbad(mtd, ofs);
  895. }
  896. EXPORT_SYMBOL_GPL(mtd_block_markbad);
  897. /*
  898. * default_mtd_writev - the default writev method
  899. * @mtd: mtd device description object pointer
  900. * @vecs: the vectors to write
  901. * @count: count of vectors in @vecs
  902. * @to: the MTD device offset to write to
  903. * @retlen: on exit contains the count of bytes written to the MTD device.
  904. *
  905. * This function returns zero in case of success and a negative error code in
  906. * case of failure.
  907. */
  908. static int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
  909. unsigned long count, loff_t to, size_t *retlen)
  910. {
  911. unsigned long i;
  912. size_t totlen = 0, thislen;
  913. int ret = 0;
  914. for (i = 0; i < count; i++) {
  915. if (!vecs[i].iov_len)
  916. continue;
  917. ret = mtd_write(mtd, to, vecs[i].iov_len, &thislen,
  918. vecs[i].iov_base);
  919. totlen += thislen;
  920. if (ret || thislen != vecs[i].iov_len)
  921. break;
  922. to += vecs[i].iov_len;
  923. }
  924. *retlen = totlen;
  925. return ret;
  926. }
  927. /*
  928. * mtd_writev - the vector-based MTD write method
  929. * @mtd: mtd device description object pointer
  930. * @vecs: the vectors to write
  931. * @count: count of vectors in @vecs
  932. * @to: the MTD device offset to write to
  933. * @retlen: on exit contains the count of bytes written to the MTD device.
  934. *
  935. * This function returns zero in case of success and a negative error code in
  936. * case of failure.
  937. */
  938. int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
  939. unsigned long count, loff_t to, size_t *retlen)
  940. {
  941. *retlen = 0;
  942. if (!(mtd->flags & MTD_WRITEABLE))
  943. return -EROFS;
  944. if (!mtd->_writev)
  945. return default_mtd_writev(mtd, vecs, count, to, retlen);
  946. return mtd->_writev(mtd, vecs, count, to, retlen);
  947. }
  948. EXPORT_SYMBOL_GPL(mtd_writev);
  949. /**
  950. * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size
  951. * @mtd: mtd device description object pointer
  952. * @size: a pointer to the ideal or maximum size of the allocation, points
  953. * to the actual allocation size on success.
  954. *
  955. * This routine attempts to allocate a contiguous kernel buffer up to
  956. * the specified size, backing off the size of the request exponentially
  957. * until the request succeeds or until the allocation size falls below
  958. * the system page size. This attempts to make sure it does not adversely
  959. * impact system performance, so when allocating more than one page, we
  960. * ask the memory allocator to avoid re-trying, swapping, writing back
  961. * or performing I/O.
  962. *
  963. * Note, this function also makes sure that the allocated buffer is aligned to
  964. * the MTD device's min. I/O unit, i.e. the "mtd->writesize" value.
  965. *
  966. * This is called, for example by mtd_{read,write} and jffs2_scan_medium,
  967. * to handle smaller (i.e. degraded) buffer allocations under low- or
  968. * fragmented-memory situations where such reduced allocations, from a
  969. * requested ideal, are allowed.
  970. *
  971. * Returns a pointer to the allocated buffer on success; otherwise, NULL.
  972. */
  973. void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size)
  974. {
  975. gfp_t flags = __GFP_NOWARN | __GFP_WAIT |
  976. __GFP_NORETRY | __GFP_NO_KSWAPD;
  977. size_t min_alloc = max_t(size_t, mtd->writesize, PAGE_SIZE);
  978. void *kbuf;
  979. *size = min_t(size_t, *size, KMALLOC_MAX_SIZE);
  980. while (*size > min_alloc) {
  981. kbuf = kmalloc(*size, flags);
  982. if (kbuf)
  983. return kbuf;
  984. *size >>= 1;
  985. *size = ALIGN(*size, mtd->writesize);
  986. }
  987. /*
  988. * For the last resort allocation allow 'kmalloc()' to do all sorts of
  989. * things (write-back, dropping caches, etc) by using GFP_KERNEL.
  990. */
  991. return kmalloc(*size, GFP_KERNEL);
  992. }
  993. EXPORT_SYMBOL_GPL(mtd_kmalloc_up_to);
  994. #ifdef CONFIG_PROC_FS
  995. /*====================================================================*/
  996. /* Support for /proc/mtd */
  997. static int mtd_proc_show(struct seq_file *m, void *v)
  998. {
  999. struct mtd_info *mtd;
  1000. seq_puts(m, "dev: size erasesize name\n");
  1001. mutex_lock(&mtd_table_mutex);
  1002. mtd_for_each_device(mtd) {
  1003. seq_printf(m, "mtd%d: %8.8llx %8.8x \"%s\"\n",
  1004. mtd->index, (unsigned long long)mtd->size,
  1005. mtd->erasesize, mtd->name);
  1006. }
  1007. mutex_unlock(&mtd_table_mutex);
  1008. return 0;
  1009. }
  1010. static int mtd_proc_open(struct inode *inode, struct file *file)
  1011. {
  1012. return single_open(file, mtd_proc_show, NULL);
  1013. }
  1014. static const struct file_operations mtd_proc_ops = {
  1015. .open = mtd_proc_open,
  1016. .read = seq_read,
  1017. .llseek = seq_lseek,
  1018. .release = single_release,
  1019. };
  1020. #endif /* CONFIG_PROC_FS */
  1021. /*====================================================================*/
  1022. /* Init code */
  1023. static int __init mtd_bdi_init(struct backing_dev_info *bdi, const char *name)
  1024. {
  1025. int ret;
  1026. ret = bdi_init(bdi);
  1027. if (!ret)
  1028. ret = bdi_register(bdi, NULL, "%s", name);
  1029. if (ret)
  1030. bdi_destroy(bdi);
  1031. return ret;
  1032. }
  1033. static struct proc_dir_entry *proc_mtd;
  1034. static int __init init_mtd(void)
  1035. {
  1036. int ret;
  1037. ret = class_register(&mtd_class);
  1038. if (ret)
  1039. goto err_reg;
  1040. ret = mtd_bdi_init(&mtd_bdi, "mtd");
  1041. if (ret)
  1042. goto err_bdi;
  1043. proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
  1044. ret = init_mtdchar();
  1045. if (ret)
  1046. goto out_procfs;
  1047. return 0;
  1048. out_procfs:
  1049. if (proc_mtd)
  1050. remove_proc_entry("mtd", NULL);
  1051. err_bdi:
  1052. class_unregister(&mtd_class);
  1053. err_reg:
  1054. pr_err("Error registering mtd class or bdi: %d\n", ret);
  1055. return ret;
  1056. }
  1057. static void __exit cleanup_mtd(void)
  1058. {
  1059. cleanup_mtdchar();
  1060. if (proc_mtd)
  1061. remove_proc_entry("mtd", NULL);
  1062. class_unregister(&mtd_class);
  1063. bdi_destroy(&mtd_bdi);
  1064. }
  1065. module_init(init_mtd);
  1066. module_exit(cleanup_mtd);
  1067. MODULE_LICENSE("GPL");
  1068. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  1069. MODULE_DESCRIPTION("Core MTD registration and access routines");