aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdcore.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r--drivers/mtd/mtdcore.c62
1 files changed, 35 insertions, 27 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index d172195fbd15..8bbbb751bf45 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -48,14 +48,34 @@
48static struct backing_dev_info mtd_bdi = { 48static struct backing_dev_info mtd_bdi = {
49}; 49};
50 50
51static int mtd_cls_suspend(struct device *dev, pm_message_t state); 51#ifdef CONFIG_PM_SLEEP
52static int mtd_cls_resume(struct device *dev); 52
53static int mtd_cls_suspend(struct device *dev)
54{
55 struct mtd_info *mtd = dev_get_drvdata(dev);
56
57 return mtd ? mtd_suspend(mtd) : 0;
58}
59
60static int mtd_cls_resume(struct device *dev)
61{
62 struct mtd_info *mtd = dev_get_drvdata(dev);
63
64 if (mtd)
65 mtd_resume(mtd);
66 return 0;
67}
68
69static SIMPLE_DEV_PM_OPS(mtd_cls_pm_ops, mtd_cls_suspend, mtd_cls_resume);
70#define MTD_CLS_PM_OPS (&mtd_cls_pm_ops)
71#else
72#define MTD_CLS_PM_OPS NULL
73#endif
53 74
54static struct class mtd_class = { 75static struct class mtd_class = {
55 .name = "mtd", 76 .name = "mtd",
56 .owner = THIS_MODULE, 77 .owner = THIS_MODULE,
57 .suspend = mtd_cls_suspend, 78 .pm = MTD_CLS_PM_OPS,
58 .resume = mtd_cls_resume,
59}; 79};
60 80
61static DEFINE_IDR(mtd_idr); 81static DEFINE_IDR(mtd_idr);
@@ -88,22 +108,6 @@ static void mtd_release(struct device *dev)
88 device_destroy(&mtd_class, index + 1); 108 device_destroy(&mtd_class, index + 1);
89} 109}
90 110
91static int mtd_cls_suspend(struct device *dev, pm_message_t state)
92{
93 struct mtd_info *mtd = dev_get_drvdata(dev);
94
95 return mtd ? mtd_suspend(mtd) : 0;
96}
97
98static int mtd_cls_resume(struct device *dev)
99{
100 struct mtd_info *mtd = dev_get_drvdata(dev);
101
102 if (mtd)
103 mtd_resume(mtd);
104 return 0;
105}
106
107static ssize_t mtd_type_show(struct device *dev, 111static ssize_t mtd_type_show(struct device *dev,
108 struct device_attribute *attr, char *buf) 112 struct device_attribute *attr, char *buf)
109{ 113{
@@ -375,8 +379,7 @@ static int mtd_reboot_notifier(struct notifier_block *n, unsigned long state,
375 * 379 *
376 * Add a device to the list of MTD devices present in the system, and 380 * Add a device to the list of MTD devices present in the system, and
377 * notify each currently active MTD 'user' of its arrival. Returns 381 * notify each currently active MTD 'user' of its arrival. Returns
378 * zero on success or 1 on failure, which currently will only happen 382 * zero on success or non-zero on failure.
379 * if there is insufficient memory or a sysfs error.
380 */ 383 */
381 384
382int add_mtd_device(struct mtd_info *mtd) 385int add_mtd_device(struct mtd_info *mtd)
@@ -390,8 +393,10 @@ int add_mtd_device(struct mtd_info *mtd)
390 mutex_lock(&mtd_table_mutex); 393 mutex_lock(&mtd_table_mutex);
391 394
392 i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL); 395 i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
393 if (i < 0) 396 if (i < 0) {
397 error = i;
394 goto fail_locked; 398 goto fail_locked;
399 }
395 400
396 mtd->index = i; 401 mtd->index = i;
397 mtd->usecount = 0; 402 mtd->usecount = 0;
@@ -420,6 +425,8 @@ int add_mtd_device(struct mtd_info *mtd)
420 printk(KERN_WARNING 425 printk(KERN_WARNING
421 "%s: unlock failed, writes may not work\n", 426 "%s: unlock failed, writes may not work\n",
422 mtd->name); 427 mtd->name);
428 /* Ignore unlock failures? */
429 error = 0;
423 } 430 }
424 431
425 /* Caller should have set dev.parent to match the 432 /* Caller should have set dev.parent to match the
@@ -430,7 +437,8 @@ int add_mtd_device(struct mtd_info *mtd)
430 mtd->dev.devt = MTD_DEVT(i); 437 mtd->dev.devt = MTD_DEVT(i);
431 dev_set_name(&mtd->dev, "mtd%d", i); 438 dev_set_name(&mtd->dev, "mtd%d", i);
432 dev_set_drvdata(&mtd->dev, mtd); 439 dev_set_drvdata(&mtd->dev, mtd);
433 if (device_register(&mtd->dev) != 0) 440 error = device_register(&mtd->dev);
441 if (error)
434 goto fail_added; 442 goto fail_added;
435 443
436 device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL, 444 device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL,
@@ -454,7 +462,7 @@ fail_added:
454 idr_remove(&mtd_idr, i); 462 idr_remove(&mtd_idr, i);
455fail_locked: 463fail_locked:
456 mutex_unlock(&mtd_table_mutex); 464 mutex_unlock(&mtd_table_mutex);
457 return 1; 465 return error;
458} 466}
459 467
460/** 468/**
@@ -510,8 +518,8 @@ static int mtd_add_device_partitions(struct mtd_info *mtd,
510 518
511 if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) { 519 if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
512 ret = add_mtd_device(mtd); 520 ret = add_mtd_device(mtd);
513 if (ret == 1) 521 if (ret)
514 return -ENODEV; 522 return ret;
515 } 523 }
516 524
517 if (nbparts > 0) { 525 if (nbparts > 0) {