aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxim Levitsky <maximlevitsky@gmail.com>2010-02-22 13:39:28 -0500
committerDavid Woodhouse <David.Woodhouse@intel.com>2010-02-26 12:03:15 -0500
commit3bd456576f22acd55fb6c3d3d4261131821f5a3b (patch)
treeedad5546c2bacf2d54cd04840f5e1eda676d5661
parentbb315f749f8c800cb8bf8d7dabc4b5fbab97b328 (diff)
mtd: create unlocked versions of {get,put}_mtd_device
Use these only if you know that you already hold mtd_table_mutex Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
-rw-r--r--drivers/mtd/mtdcore.c60
-rw-r--r--include/linux/mtd/mtd.h3
2 files changed, 41 insertions, 22 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index b3b98d1fffc3..67669a76eaf5 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -463,27 +463,38 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
463 ret = NULL; 463 ret = NULL;
464 } 464 }
465 465
466 if (!ret) 466 if (!ret) {
467 goto out_unlock; 467 ret = ERR_PTR(err);
468 468 goto out;
469 if (!try_module_get(ret->owner))
470 goto out_unlock;
471
472 if (ret->get_device) {
473 err = ret->get_device(ret);
474 if (err)
475 goto out_put;
476 } 469 }
477 470
478 ret->usecount++; 471 err = __get_mtd_device(ret);
472 if (err)
473 ret = ERR_PTR(err);
474out:
479 mutex_unlock(&mtd_table_mutex); 475 mutex_unlock(&mtd_table_mutex);
480 return ret; 476 return ret;
477}
481 478
482out_put: 479
483 module_put(ret->owner); 480int __get_mtd_device(struct mtd_info *mtd)
484out_unlock: 481{
485 mutex_unlock(&mtd_table_mutex); 482 int err;
486 return ERR_PTR(err); 483
484 if (!try_module_get(mtd->owner))
485 return -ENODEV;
486
487 if (mtd->get_device) {
488
489 err = mtd->get_device(mtd);
490
491 if (err) {
492 module_put(mtd->owner);
493 return err;
494 }
495 }
496 mtd->usecount++;
497 return 0;
487} 498}
488 499
489/** 500/**
@@ -534,14 +545,19 @@ out_unlock:
534 545
535void put_mtd_device(struct mtd_info *mtd) 546void put_mtd_device(struct mtd_info *mtd)
536{ 547{
537 int c;
538
539 mutex_lock(&mtd_table_mutex); 548 mutex_lock(&mtd_table_mutex);
540 c = --mtd->usecount; 549 __put_mtd_device(mtd);
550 mutex_unlock(&mtd_table_mutex);
551
552}
553
554void __put_mtd_device(struct mtd_info *mtd)
555{
556 --mtd->usecount;
557 BUG_ON(mtd->usecount < 0);
558
541 if (mtd->put_device) 559 if (mtd->put_device)
542 mtd->put_device(mtd); 560 mtd->put_device(mtd);
543 mutex_unlock(&mtd_table_mutex);
544 BUG_ON(c < 0);
545 561
546 module_put(mtd->owner); 562 module_put(mtd->owner);
547} 563}
@@ -579,7 +595,9 @@ EXPORT_SYMBOL_GPL(add_mtd_device);
579EXPORT_SYMBOL_GPL(del_mtd_device); 595EXPORT_SYMBOL_GPL(del_mtd_device);
580EXPORT_SYMBOL_GPL(get_mtd_device); 596EXPORT_SYMBOL_GPL(get_mtd_device);
581EXPORT_SYMBOL_GPL(get_mtd_device_nm); 597EXPORT_SYMBOL_GPL(get_mtd_device_nm);
598EXPORT_SYMBOL_GPL(__get_mtd_device);
582EXPORT_SYMBOL_GPL(put_mtd_device); 599EXPORT_SYMBOL_GPL(put_mtd_device);
600EXPORT_SYMBOL_GPL(__put_mtd_device);
583EXPORT_SYMBOL_GPL(register_mtd_user); 601EXPORT_SYMBOL_GPL(register_mtd_user);
584EXPORT_SYMBOL_GPL(unregister_mtd_user); 602EXPORT_SYMBOL_GPL(unregister_mtd_user);
585EXPORT_SYMBOL_GPL(default_mtd_writev); 603EXPORT_SYMBOL_GPL(default_mtd_writev);
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index ba53ecca107c..11d8e68d17c0 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -289,8 +289,9 @@ extern int add_mtd_device(struct mtd_info *mtd);
289extern int del_mtd_device (struct mtd_info *mtd); 289extern int del_mtd_device (struct mtd_info *mtd);
290 290
291extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); 291extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
292extern int __get_mtd_device(struct mtd_info *mtd);
293extern void __put_mtd_device(struct mtd_info *mtd);
292extern struct mtd_info *get_mtd_device_nm(const char *name); 294extern struct mtd_info *get_mtd_device_nm(const char *name);
293
294extern void put_mtd_device(struct mtd_info *mtd); 295extern void put_mtd_device(struct mtd_info *mtd);
295 296
296 297