diff options
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r-- | drivers/mtd/mtdcore.c | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index e4831b4159db..4c611871d7e6 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c | |||
@@ -105,12 +105,11 @@ static LIST_HEAD(mtd_notifiers); | |||
105 | */ | 105 | */ |
106 | static void mtd_release(struct device *dev) | 106 | static void mtd_release(struct device *dev) |
107 | { | 107 | { |
108 | struct mtd_info __maybe_unused *mtd = dev_get_drvdata(dev); | 108 | struct mtd_info *mtd = dev_get_drvdata(dev); |
109 | dev_t index = MTD_DEVT(mtd->index); | 109 | dev_t index = MTD_DEVT(mtd->index); |
110 | 110 | ||
111 | /* remove /dev/mtdXro node if needed */ | 111 | /* remove /dev/mtdXro node */ |
112 | if (index) | 112 | device_destroy(&mtd_class, index + 1); |
113 | device_destroy(&mtd_class, index + 1); | ||
114 | } | 113 | } |
115 | 114 | ||
116 | static int mtd_cls_suspend(struct device *dev, pm_message_t state) | 115 | static int mtd_cls_suspend(struct device *dev, pm_message_t state) |
@@ -442,10 +441,8 @@ int add_mtd_device(struct mtd_info *mtd) | |||
442 | if (device_register(&mtd->dev) != 0) | 441 | if (device_register(&mtd->dev) != 0) |
443 | goto fail_added; | 442 | goto fail_added; |
444 | 443 | ||
445 | if (MTD_DEVT(i)) | 444 | device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL, |
446 | device_create(&mtd_class, mtd->dev.parent, | 445 | "mtd%dro", i); |
447 | MTD_DEVT(i) + 1, | ||
448 | NULL, "mtd%dro", i); | ||
449 | 446 | ||
450 | pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name); | 447 | pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name); |
451 | /* No need to get a refcount on the module containing | 448 | /* No need to get a refcount on the module containing |
@@ -778,7 +775,7 @@ EXPORT_SYMBOL_GPL(__put_mtd_device); | |||
778 | */ | 775 | */ |
779 | int mtd_erase(struct mtd_info *mtd, struct erase_info *instr) | 776 | int mtd_erase(struct mtd_info *mtd, struct erase_info *instr) |
780 | { | 777 | { |
781 | if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr) | 778 | if (instr->addr >= mtd->size || instr->len > mtd->size - instr->addr) |
782 | return -EINVAL; | 779 | return -EINVAL; |
783 | if (!(mtd->flags & MTD_WRITEABLE)) | 780 | if (!(mtd->flags & MTD_WRITEABLE)) |
784 | return -EROFS; | 781 | return -EROFS; |
@@ -804,7 +801,7 @@ int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, | |||
804 | *phys = 0; | 801 | *phys = 0; |
805 | if (!mtd->_point) | 802 | if (!mtd->_point) |
806 | return -EOPNOTSUPP; | 803 | return -EOPNOTSUPP; |
807 | if (from < 0 || from > mtd->size || len > mtd->size - from) | 804 | if (from < 0 || from >= mtd->size || len > mtd->size - from) |
808 | return -EINVAL; | 805 | return -EINVAL; |
809 | if (!len) | 806 | if (!len) |
810 | return 0; | 807 | return 0; |
@@ -817,7 +814,7 @@ int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len) | |||
817 | { | 814 | { |
818 | if (!mtd->_point) | 815 | if (!mtd->_point) |
819 | return -EOPNOTSUPP; | 816 | return -EOPNOTSUPP; |
820 | if (from < 0 || from > mtd->size || len > mtd->size - from) | 817 | if (from < 0 || from >= mtd->size || len > mtd->size - from) |
821 | return -EINVAL; | 818 | return -EINVAL; |
822 | if (!len) | 819 | if (!len) |
823 | return 0; | 820 | return 0; |
@@ -835,7 +832,7 @@ unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len, | |||
835 | { | 832 | { |
836 | if (!mtd->_get_unmapped_area) | 833 | if (!mtd->_get_unmapped_area) |
837 | return -EOPNOTSUPP; | 834 | return -EOPNOTSUPP; |
838 | if (offset > mtd->size || len > mtd->size - offset) | 835 | if (offset >= mtd->size || len > mtd->size - offset) |
839 | return -EINVAL; | 836 | return -EINVAL; |
840 | return mtd->_get_unmapped_area(mtd, len, offset, flags); | 837 | return mtd->_get_unmapped_area(mtd, len, offset, flags); |
841 | } | 838 | } |
@@ -846,7 +843,7 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, | |||
846 | { | 843 | { |
847 | int ret_code; | 844 | int ret_code; |
848 | *retlen = 0; | 845 | *retlen = 0; |
849 | if (from < 0 || from > mtd->size || len > mtd->size - from) | 846 | if (from < 0 || from >= mtd->size || len > mtd->size - from) |
850 | return -EINVAL; | 847 | return -EINVAL; |
851 | if (!len) | 848 | if (!len) |
852 | return 0; | 849 | return 0; |
@@ -869,7 +866,7 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, | |||
869 | const u_char *buf) | 866 | const u_char *buf) |
870 | { | 867 | { |
871 | *retlen = 0; | 868 | *retlen = 0; |
872 | if (to < 0 || to > mtd->size || len > mtd->size - to) | 869 | if (to < 0 || to >= mtd->size || len > mtd->size - to) |
873 | return -EINVAL; | 870 | return -EINVAL; |
874 | if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE)) | 871 | if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE)) |
875 | return -EROFS; | 872 | return -EROFS; |
@@ -892,7 +889,7 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, | |||
892 | *retlen = 0; | 889 | *retlen = 0; |
893 | if (!mtd->_panic_write) | 890 | if (!mtd->_panic_write) |
894 | return -EOPNOTSUPP; | 891 | return -EOPNOTSUPP; |
895 | if (to < 0 || to > mtd->size || len > mtd->size - to) | 892 | if (to < 0 || to >= mtd->size || len > mtd->size - to) |
896 | return -EINVAL; | 893 | return -EINVAL; |
897 | if (!(mtd->flags & MTD_WRITEABLE)) | 894 | if (!(mtd->flags & MTD_WRITEABLE)) |
898 | return -EROFS; | 895 | return -EROFS; |
@@ -1011,7 +1008,7 @@ int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | |||
1011 | { | 1008 | { |
1012 | if (!mtd->_lock) | 1009 | if (!mtd->_lock) |
1013 | return -EOPNOTSUPP; | 1010 | return -EOPNOTSUPP; |
1014 | if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) | 1011 | if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs) |
1015 | return -EINVAL; | 1012 | return -EINVAL; |
1016 | if (!len) | 1013 | if (!len) |
1017 | return 0; | 1014 | return 0; |
@@ -1023,7 +1020,7 @@ int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | |||
1023 | { | 1020 | { |
1024 | if (!mtd->_unlock) | 1021 | if (!mtd->_unlock) |
1025 | return -EOPNOTSUPP; | 1022 | return -EOPNOTSUPP; |
1026 | if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) | 1023 | if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs) |
1027 | return -EINVAL; | 1024 | return -EINVAL; |
1028 | if (!len) | 1025 | if (!len) |
1029 | return 0; | 1026 | return 0; |
@@ -1035,7 +1032,7 @@ int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) | |||
1035 | { | 1032 | { |
1036 | if (!mtd->_is_locked) | 1033 | if (!mtd->_is_locked) |
1037 | return -EOPNOTSUPP; | 1034 | return -EOPNOTSUPP; |
1038 | if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) | 1035 | if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs) |
1039 | return -EINVAL; | 1036 | return -EINVAL; |
1040 | if (!len) | 1037 | if (!len) |
1041 | return 0; | 1038 | return 0; |
@@ -1045,7 +1042,7 @@ EXPORT_SYMBOL_GPL(mtd_is_locked); | |||
1045 | 1042 | ||
1046 | int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs) | 1043 | int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs) |
1047 | { | 1044 | { |
1048 | if (ofs < 0 || ofs > mtd->size) | 1045 | if (ofs < 0 || ofs >= mtd->size) |
1049 | return -EINVAL; | 1046 | return -EINVAL; |
1050 | if (!mtd->_block_isreserved) | 1047 | if (!mtd->_block_isreserved) |
1051 | return 0; | 1048 | return 0; |
@@ -1055,7 +1052,7 @@ EXPORT_SYMBOL_GPL(mtd_block_isreserved); | |||
1055 | 1052 | ||
1056 | int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) | 1053 | int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) |
1057 | { | 1054 | { |
1058 | if (ofs < 0 || ofs > mtd->size) | 1055 | if (ofs < 0 || ofs >= mtd->size) |
1059 | return -EINVAL; | 1056 | return -EINVAL; |
1060 | if (!mtd->_block_isbad) | 1057 | if (!mtd->_block_isbad) |
1061 | return 0; | 1058 | return 0; |
@@ -1067,7 +1064,7 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs) | |||
1067 | { | 1064 | { |
1068 | if (!mtd->_block_markbad) | 1065 | if (!mtd->_block_markbad) |
1069 | return -EOPNOTSUPP; | 1066 | return -EOPNOTSUPP; |
1070 | if (ofs < 0 || ofs > mtd->size) | 1067 | if (ofs < 0 || ofs >= mtd->size) |
1071 | return -EINVAL; | 1068 | return -EINVAL; |
1072 | if (!(mtd->flags & MTD_WRITEABLE)) | 1069 | if (!(mtd->flags & MTD_WRITEABLE)) |
1073 | return -EROFS; | 1070 | return -EROFS; |