@@ -381,17 +381,16 @@ int del_mtd_device (struct mtd_info *mtd)
381381
382382void register_mtd_user (struct mtd_notifier * new )
383383{
384- int i ;
384+ struct mtd_info * mtd ;
385385
386386 mutex_lock (& mtd_table_mutex );
387387
388388 list_add (& new -> list , & mtd_notifiers );
389389
390390 __module_get (THIS_MODULE );
391391
392- for (i = 0 ; i < MAX_MTD_DEVICES ; i ++ )
393- if (mtd_table [i ])
394- new -> add (mtd_table [i ]);
392+ mtd_for_each_device (mtd )
393+ new -> add (mtd );
395394
396395 mutex_unlock (& mtd_table_mutex );
397396}
@@ -408,15 +407,14 @@ void register_mtd_user (struct mtd_notifier *new)
408407
409408int unregister_mtd_user (struct mtd_notifier * old )
410409{
411- int i ;
410+ struct mtd_info * mtd ;
412411
413412 mutex_lock (& mtd_table_mutex );
414413
415414 module_put (THIS_MODULE );
416415
417- for (i = 0 ; i < MAX_MTD_DEVICES ; i ++ )
418- if (mtd_table [i ])
419- old -> remove (mtd_table [i ]);
416+ mtd_for_each_device (mtd )
417+ old -> remove (mtd );
420418
421419 list_del (& old -> list );
422420 mutex_unlock (& mtd_table_mutex );
@@ -438,15 +436,18 @@ int unregister_mtd_user (struct mtd_notifier *old)
438436
439437struct mtd_info * get_mtd_device (struct mtd_info * mtd , int num )
440438{
441- struct mtd_info * ret = NULL ;
442- int i , err = - ENODEV ;
439+ struct mtd_info * ret = NULL , * other ;
440+ int err = - ENODEV ;
443441
444442 mutex_lock (& mtd_table_mutex );
445443
446444 if (num == -1 ) {
447- for (i = 0 ; i < MAX_MTD_DEVICES ; i ++ )
448- if (mtd_table [i ] == mtd )
449- ret = mtd_table [i ];
445+ mtd_for_each_device (other ) {
446+ if (other == mtd ) {
447+ ret = mtd ;
448+ break ;
449+ }
450+ }
450451 } else if (num >= 0 && num < MAX_MTD_DEVICES ) {
451452 ret = mtd_table [num ];
452453 if (mtd && mtd != ret )
@@ -487,14 +488,14 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
487488
488489struct mtd_info * get_mtd_device_nm (const char * name )
489490{
490- int i , err = - ENODEV ;
491- struct mtd_info * mtd = NULL ;
491+ int err = - ENODEV ;
492+ struct mtd_info * mtd = NULL , * other ;
492493
493494 mutex_lock (& mtd_table_mutex );
494495
495- for ( i = 0 ; i < MAX_MTD_DEVICES ; i ++ ) {
496- if (mtd_table [ i ] && !strcmp (name , mtd_table [ i ] -> name )) {
497- mtd = mtd_table [ i ] ;
496+ mtd_for_each_device ( other ) {
497+ if (!strcmp (name , other -> name )) {
498+ mtd = other ;
498499 break ;
499500 }
500501 }
@@ -581,30 +582,25 @@ EXPORT_SYMBOL_GPL(default_mtd_writev);
581582
582583static struct proc_dir_entry * proc_mtd ;
583584
584- static inline int mtd_proc_info (char * buf , int i )
585+ static inline int mtd_proc_info (char * buf , struct mtd_info * this )
585586{
586- struct mtd_info * this = mtd_table [i ];
587-
588- if (!this )
589- return 0 ;
590-
591- return sprintf (buf , "mtd%d: %8.8llx %8.8x \"%s\"\n" , i ,
587+ return sprintf (buf , "mtd%d: %8.8llx %8.8x \"%s\"\n" , this -> index ,
592588 (unsigned long long )this -> size ,
593589 this -> erasesize , this -> name );
594590}
595591
596592static int mtd_read_proc (char * page , char * * start , off_t off , int count ,
597593 int * eof , void * data_unused )
598594{
599- int len , l , i ;
595+ struct mtd_info * mtd ;
596+ int len , l ;
600597 off_t begin = 0 ;
601598
602599 mutex_lock (& mtd_table_mutex );
603600
604601 len = sprintf (page , "dev: size erasesize name\n" );
605- for (i = 0 ; i < MAX_MTD_DEVICES ; i ++ ) {
606-
607- l = mtd_proc_info (page + len , i );
602+ mtd_for_each_device (mtd ) {
603+ l = mtd_proc_info (page + len , mtd );
608604 len += l ;
609605 if (len + begin > off + count )
610606 goto done ;
0 commit comments