Merge tag 'iwlwifi-for-john-2014-10-23' of git://git.kernel.org/pub/scm/linux/kernel...
[cascardo/linux.git] / drivers / mtd / mtdcore.c
index e4831b4..4c61187 100644 (file)
@@ -105,12 +105,11 @@ static LIST_HEAD(mtd_notifiers);
  */
 static void mtd_release(struct device *dev)
 {
-       struct mtd_info __maybe_unused *mtd = dev_get_drvdata(dev);
+       struct mtd_info *mtd = dev_get_drvdata(dev);
        dev_t index = MTD_DEVT(mtd->index);
 
-       /* remove /dev/mtdXro node if needed */
-       if (index)
-               device_destroy(&mtd_class, index + 1);
+       /* remove /dev/mtdXro node */
+       device_destroy(&mtd_class, index + 1);
 }
 
 static int mtd_cls_suspend(struct device *dev, pm_message_t state)
@@ -442,10 +441,8 @@ int add_mtd_device(struct mtd_info *mtd)
        if (device_register(&mtd->dev) != 0)
                goto fail_added;
 
-       if (MTD_DEVT(i))
-               device_create(&mtd_class, mtd->dev.parent,
-                             MTD_DEVT(i) + 1,
-                             NULL, "mtd%dro", i);
+       device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL,
+                     "mtd%dro", i);
 
        pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name);
        /* No need to get a refcount on the module containing
@@ -778,7 +775,7 @@ EXPORT_SYMBOL_GPL(__put_mtd_device);
  */
 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
 {
-       if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)
+       if (instr->addr >= mtd->size || instr->len > mtd->size - instr->addr)
                return -EINVAL;
        if (!(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
@@ -804,7 +801,7 @@ int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
                *phys = 0;
        if (!mtd->_point)
                return -EOPNOTSUPP;
-       if (from < 0 || from > mtd->size || len > mtd->size - from)
+       if (from < 0 || from >= mtd->size || len > mtd->size - from)
                return -EINVAL;
        if (!len)
                return 0;
@@ -817,7 +814,7 @@ int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
 {
        if (!mtd->_point)
                return -EOPNOTSUPP;
-       if (from < 0 || from > mtd->size || len > mtd->size - from)
+       if (from < 0 || from >= mtd->size || len > mtd->size - from)
                return -EINVAL;
        if (!len)
                return 0;
@@ -835,7 +832,7 @@ unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len,
 {
        if (!mtd->_get_unmapped_area)
                return -EOPNOTSUPP;
-       if (offset > mtd->size || len > mtd->size - offset)
+       if (offset >= mtd->size || len > mtd->size - offset)
                return -EINVAL;
        return mtd->_get_unmapped_area(mtd, len, offset, flags);
 }
@@ -846,7 +843,7 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 {
        int ret_code;
        *retlen = 0;
-       if (from < 0 || from > mtd->size || len > mtd->size - from)
+       if (from < 0 || from >= mtd->size || len > mtd->size - from)
                return -EINVAL;
        if (!len)
                return 0;
@@ -869,7 +866,7 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
              const u_char *buf)
 {
        *retlen = 0;
-       if (to < 0 || to > mtd->size || len > mtd->size - to)
+       if (to < 0 || to >= mtd->size || len > mtd->size - to)
                return -EINVAL;
        if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
@@ -892,7 +889,7 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
        *retlen = 0;
        if (!mtd->_panic_write)
                return -EOPNOTSUPP;
-       if (to < 0 || to > mtd->size || len > mtd->size - to)
+       if (to < 0 || to >= mtd->size || len > mtd->size - to)
                return -EINVAL;
        if (!(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
@@ -1011,7 +1008,7 @@ int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
        if (!mtd->_lock)
                return -EOPNOTSUPP;
-       if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
+       if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
                return -EINVAL;
        if (!len)
                return 0;
@@ -1023,7 +1020,7 @@ int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
        if (!mtd->_unlock)
                return -EOPNOTSUPP;
-       if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
+       if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
                return -EINVAL;
        if (!len)
                return 0;
@@ -1035,7 +1032,7 @@ int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
        if (!mtd->_is_locked)
                return -EOPNOTSUPP;
-       if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
+       if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
                return -EINVAL;
        if (!len)
                return 0;
@@ -1045,7 +1042,7 @@ EXPORT_SYMBOL_GPL(mtd_is_locked);
 
 int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs)
 {
-       if (ofs < 0 || ofs > mtd->size)
+       if (ofs < 0 || ofs >= mtd->size)
                return -EINVAL;
        if (!mtd->_block_isreserved)
                return 0;
@@ -1055,7 +1052,7 @@ EXPORT_SYMBOL_GPL(mtd_block_isreserved);
 
 int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
 {
-       if (ofs < 0 || ofs > mtd->size)
+       if (ofs < 0 || ofs >= mtd->size)
                return -EINVAL;
        if (!mtd->_block_isbad)
                return 0;
@@ -1067,7 +1064,7 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
 {
        if (!mtd->_block_markbad)
                return -EOPNOTSUPP;
-       if (ofs < 0 || ofs > mtd->size)
+       if (ofs < 0 || ofs >= mtd->size)
                return -EINVAL;
        if (!(mtd->flags & MTD_WRITEABLE))
                return -EROFS;