Updated upstream Git repositories
[opendreambox.git] / meta-dreambox / recipes-kernel / linux / linux-dreambox-3.4 / 0002-block2mtd-add-possibility-to-remove-block2mtd-device.patch
1 From c4a0416ce010ea01f05eaa9d97d2d1e3dc06103d Mon Sep 17 00:00:00 2001
2 From: Andreas Monzner <andreas.monzner@dream-property.net>
3 Date: Mon, 11 Mar 2013 16:25:45 +0100
4 Subject: [PATCH 2/4] block2mtd: add possibility to remove block2mtd devices
5  when block2mtd is compiled in kernel
6
7 (cherry picked from commit acd9ad53e8eb4c88d2fe245f4bda83538fe8c4ea)
8 ---
9  drivers/mtd/devices/block2mtd.c | 30 ++++++++++++++++++++++++++++++
10  1 file changed, 30 insertions(+)
11
12 diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
13 index 56e559b..401f7fd 100644
14 --- a/drivers/mtd/devices/block2mtd.c
15 +++ b/drivers/mtd/devices/block2mtd.c
16 @@ -21,6 +21,7 @@
17  #define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args)
18  #define INFO(fmt, args...) printk(KERN_INFO "block2mtd: " fmt "\n" , ## args)
19  
20 +extern int del_mtd_device(struct mtd_info *mtd);
21  
22  /* Info for the block device */
23  struct block2mtd_dev {
24 @@ -354,6 +355,31 @@ static int block2mtd_init_called = 0;
25  static char block2mtd_paramline[80 + 12 + 12]; /* 80 for device, 12 for erase size, 12 for writesize */
26  #endif
27  
28 +static void remove_device_by_name(const char *name)
29 +{
30 +       struct list_head *pos, *next;
31 +       int name_offset = strlen("block2mtd: ");
32 +
33 +       list_for_each_safe(pos, next, &blkmtd_device_list) {
34 +               struct block2mtd_dev *dev = list_entry(pos, typeof(*dev), list);
35 +               if (!strcmp(name, dev->mtd.name + name_offset)) {
36 +                       int err;
37 +                       block2mtd_sync(&dev->mtd);
38 +                       err = del_mtd_device(&dev->mtd);
39 +                       if (err == 0) {
40 +                               INFO("mtd%d: [%s] removed",
41 +                                               dev->mtd.index, name);
42 +                               list_del(&dev->list);
43 +                               block2mtd_free_device(dev);
44 +                       } else
45 +                               ERROR("mtd%d: [%s] cannot remove: %d",
46 +                                               dev->mtd.index, name, err);
47 +
48 +                       return;
49 +               }
50 +       }
51 +       ERROR("no such device: %s", name);
52 +}
53  
54  static int block2mtd_setup2(const char *val)
55  {
56 @@ -385,6 +411,10 @@ static int block2mtd_setup2(const char *val)
57                 parse_err("device name too long");
58  
59         if (token[1]) {
60 +               if (!strcmp("remove", token[1])) {
61 +                       remove_device_by_name(name);
62 +                       return 0;
63 +               }
64                 ret = parse_num(&erase_size, token[1]);
65                 if (ret) {
66                         parse_err("illegal erase size");
67 -- 
68 2.1.4
69