kernel: disbale HAMRADIO in generic config
[openwrt.git] / target / linux / generic / patches-3.13 / 555-gluebi-sysfs-support.patch
1 --- a/drivers/mtd/ubi/gluebi.c
2 +++ b/drivers/mtd/ubi/gluebi.c
3 @@ -38,6 +38,7 @@
4  #include <linux/mutex.h>
5  #include <linux/mtd/ubi.h>
6  #include <linux/mtd/mtd.h>
7 +#include <linux/export.h>
8  #include "ubi-media.h"
9  
10  #define err_msg(fmt, ...)                                   \
11 @@ -66,6 +67,16 @@ struct gluebi_device {
12  static LIST_HEAD(gluebi_devices);
13  static DEFINE_MUTEX(devices_mutex);
14  
15 +/* Device attribute handler for gluebi files in '/<sysfs>/class/mtd/mtdX' */
16 +static ssize_t gluebi_attribute_show(struct device *dev,
17 +       struct device_attribute *attr, char *buf);
18 +
19 +/* Device attributes corresponding to files in '/<sysfs>/class/mtd/mtdX' */
20 +static struct device_attribute attr_vol_gluebi_ubi_num =
21 +__ATTR(gluebi_ubi_num, S_IRUGO, gluebi_attribute_show, NULL);
22 +static struct device_attribute attr_vol_gluebi_vol_id =
23 +__ATTR(gluebi_vol_id, S_IRUGO, gluebi_attribute_show, NULL);
24 +
25  /**
26   * find_gluebi_nolock - find a gluebi device.
27   * @ubi_num: UBI device number
28 @@ -288,6 +299,36 @@ out_err:
29  }
30  
31  /**
32 + * gluebi_attribute_show - "Show" method for gluebi files in sysfs.
33 + */
34 +static ssize_t gluebi_attribute_show(struct device *dev,
35 +                                 struct device_attribute *attr, char *buf)
36 +{
37 +       int ret;
38 +       struct mtd_info *mtd = container_of(dev, struct mtd_info, dev);
39 +       struct gluebi_device *gluebi;
40 +
41 +       gluebi_get_device(mtd);
42 +       gluebi = container_of(mtd, struct gluebi_device, mtd);
43 +
44 +       /* This really shouldn't happen */
45 +       if (!gluebi)
46 +               return -ENODEV;
47 +
48 +       if (attr == &attr_vol_gluebi_ubi_num) {
49 +               ret = sprintf(buf, "%u\n", gluebi->ubi_num);
50 +       } else if (attr == &attr_vol_gluebi_vol_id) {
51 +               ret = sprintf(buf, "%u\n", gluebi->vol_id);
52 +       } else {
53 +               /* This must be a bug */
54 +               ret = -EINVAL;
55 +       }
56 +
57 +       gluebi_put_device(mtd);
58 +       return ret;
59 +}
60 +
61 +/**
62   * gluebi_create - create a gluebi device for an UBI volume.
63   * @di: UBI device description object
64   * @vi: UBI volume description object
65 @@ -355,6 +396,8 @@ static int gluebi_create(struct ubi_devi
66         mutex_lock(&devices_mutex);
67         list_add_tail(&gluebi->list, &gluebi_devices);
68         mutex_unlock(&devices_mutex);
69 +       device_create_file(&mtd->dev, &attr_vol_gluebi_ubi_num);
70 +       device_create_file(&mtd->dev, &attr_vol_gluebi_vol_id);
71         return 0;
72  }
73  
74 @@ -380,8 +423,11 @@ static int gluebi_remove(struct ubi_volu
75                 err = -ENOENT;
76         } else if (gluebi->refcnt)
77                 err = -EBUSY;
78 -       else
79 +       else {
80 +               device_remove_file(&gluebi->mtd.dev, &attr_vol_gluebi_ubi_num);
81 +               device_remove_file(&gluebi->mtd.dev, &attr_vol_gluebi_vol_id);
82                 list_del(&gluebi->list);
83 +       }
84         mutex_unlock(&devices_mutex);
85         if (err)
86                 return err;