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