Ticket #9780: 067-wait_for_blockdevice_mtd2block.patch

File 067-wait_for_blockdevice_mtd2block.patch, 3.2 KB (added by crissi99@…, 5 years ago)

patch for waiting for the block device (target/linux/generic-2.6/patches-2.6.32/)

  • drivers/mtd/devices/block2mtd.c

    old new  
    1818#include <linux/buffer_head.h> 
    1919#include <linux/mutex.h> 
    2020#include <linux/mount.h> 
     21#include <linux/delay.h> 
     22#include <linux/kthread.h> 
    2123 
    2224#define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args) 
    2325#define INFO(fmt, args...) printk(KERN_INFO "block2mtd: " fmt "\n" , ## args) 
     
    475477#endif 
    476478 
    477479 
    478 static int block2mtd_setup2(const char *val) 
     480struct block2mtd_setupasync_params { 
     481       char *name; 
     482       int erase_size; 
     483       char *mtdname; 
     484}; 
     485 
     486static int block2mtd_setupasync(void *p) 
     487{ 
     488       struct block2mtd_setupasync_params *params = p; 
     489       int i; 
     490 
     491       printk(KERN_WARNING "block2mtd: spawned kernel thread for async waiting on '%s'\n", params->name); 
     492       for (i=0; i<20; i++) { 
     493               msleep(1000); 
     494 
     495                if (add_device(params->name, params->erase_size, params->mtdname) != NULL) 
     496                       break; 
     497       } 
     498       kfree(params->name); 
     499       kfree(params); 
     500 
     501       return 0; 
     502} 
     503 
     504static int block2mtd_setup2(const char *val, int async) 
    479505{ 
    480506        char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */ 
    481507        char *str = buf; 
     
    483509        char *name; 
    484510        size_t erase_size = PAGE_SIZE; 
    485511        int i, ret; 
     512        struct block2mtd_setupasync_params *params; 
    486513 
    487514        if (strnlen(val, sizeof(buf)) >= sizeof(buf)) 
    488515                parse_err("parameter too long"); 
     
    512539        if (token[2] && (strlen(token[2]) + 1 > 80)) 
    513540                parse_err("mtd device name too long"); 
    514541 
    515         add_device(name, erase_size, token[2]); 
     542       if (add_device(name, erase_size, token[2]) != NULL) 
     543               return 0; 
     544 
     545       params = kzalloc(sizeof(struct block2mtd_setupasync_params), GFP_KERNEL); 
     546       if (!params) 
     547               return 0; 
     548 
     549       params->name = kmalloc(strlen(name)+1, GFP_KERNEL); 
     550       params->erase_size = erase_size; 
     551       if (!params->name) { 
     552               kfree(params); 
     553               return 0; 
     554       } 
     555 
     556       memcpy(params->name, name, strlen(name)+1); 
     557 
     558       params->mtdname = kmalloc(strlen(token[2])+1, GFP_KERNEL); 
     559        
     560       if (!params->mtdname) { 
     561               kfree(params); 
     562               return 0; 
     563       } 
     564 
     565       memcpy(params->mtdname, token[2], strlen(token[2])+1); 
     566 
     567       if (async) 
     568               kthread_run(block2mtd_setupasync, params, "block2mtd/setupasync"); 
    516569 
    517570        return 0; 
    518571} 
     
    521574static int block2mtd_setup(const char *val, struct kernel_param *kp) 
    522575{ 
    523576#ifdef MODULE 
    524         return block2mtd_setup2(val); 
     577        return block2mtd_setup2(val, 0); 
    525578#else 
    526579        /* If more parameters are later passed in via 
    527580           /sys/module/block2mtd/parameters/block2mtd 
     
    529582           we can parse the argument now. */ 
    530583 
    531584        if (block2mtd_init_called) 
    532                 return block2mtd_setup2(val); 
     585                return block2mtd_setup2(val, 0); 
    533586 
    534587        /* During early boot stage, we only save the parameters 
    535588           here. We must parse them later: if the param passed 
     
    554607 
    555608#ifndef MODULE 
    556609        if (strlen(block2mtd_paramline)) 
    557                 ret = block2mtd_setup2(block2mtd_paramline); 
     610                 ret = block2mtd_setup2(block2mtd_paramline, 1); 
    558611        block2mtd_init_called = 1; 
    559612#endif 
    560613