diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2007-12-17 07:22:55 -0500 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2007-12-26 12:15:15 -0500 |
commit | 35ad5fb76cc0a08e14068408b064103439feee36 (patch) | |
tree | 21f90c6206a0d49ded3b35defb705c4fb131eebb | |
parent | fc75a1e166268e0c3366c3b30888a024125f6665 (diff) |
UBI: fix and cleanup volume opening functions
This patch fixes error codes of the functions - if the device number
is out of range, -EINVAL should be returned. It also removes unneeded
try_module_get call from the open by name function.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
-rw-r--r-- | drivers/mtd/ubi/kapi.c | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c index 96f5fef5f3fa..9c283768319f 100644 --- a/drivers/mtd/ubi/kapi.c +++ b/drivers/mtd/ubi/kapi.c | |||
@@ -104,37 +104,32 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode) | |||
104 | 104 | ||
105 | dbg_msg("open device %d volume %d, mode %d", ubi_num, vol_id, mode); | 105 | dbg_msg("open device %d volume %d, mode %d", ubi_num, vol_id, mode); |
106 | 106 | ||
107 | err = -ENODEV; | 107 | if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES) |
108 | if (ubi_num < 0) | 108 | return ERR_PTR(-EINVAL); |
109 | return ERR_PTR(err); | ||
110 | |||
111 | ubi = ubi_devices[ubi_num]; | ||
112 | 109 | ||
113 | if (!try_module_get(THIS_MODULE)) | 110 | if (mode != UBI_READONLY && mode != UBI_READWRITE && |
114 | return ERR_PTR(err); | 111 | mode != UBI_EXCLUSIVE) |
112 | return ERR_PTR(-EINVAL); | ||
115 | 113 | ||
116 | if (ubi_num >= UBI_MAX_DEVICES || !ubi) | 114 | ubi = ubi_devices[ubi_num]; |
117 | goto out_put; | 115 | if (!ubi) |
116 | return ERR_PTR(-ENODEV); | ||
118 | 117 | ||
119 | err = -EINVAL; | ||
120 | if (vol_id < 0 || vol_id >= ubi->vtbl_slots) | 118 | if (vol_id < 0 || vol_id >= ubi->vtbl_slots) |
121 | goto out_put; | 119 | return ERR_PTR(-EINVAL); |
122 | if (mode != UBI_READONLY && mode != UBI_READWRITE && | ||
123 | mode != UBI_EXCLUSIVE) | ||
124 | goto out_put; | ||
125 | 120 | ||
126 | desc = kmalloc(sizeof(struct ubi_volume_desc), GFP_KERNEL); | 121 | desc = kmalloc(sizeof(struct ubi_volume_desc), GFP_KERNEL); |
127 | if (!desc) { | 122 | if (!desc) |
128 | err = -ENOMEM; | 123 | return ERR_PTR(-ENOMEM); |
129 | goto out_put; | 124 | |
130 | } | 125 | err = -ENODEV; |
126 | if (!try_module_get(THIS_MODULE)) | ||
127 | goto out_free; | ||
131 | 128 | ||
132 | spin_lock(&ubi->volumes_lock); | 129 | spin_lock(&ubi->volumes_lock); |
133 | vol = ubi->volumes[vol_id]; | 130 | vol = ubi->volumes[vol_id]; |
134 | if (!vol) { | 131 | if (!vol) |
135 | err = -ENODEV; | ||
136 | goto out_unlock; | 132 | goto out_unlock; |
137 | } | ||
138 | 133 | ||
139 | err = -EBUSY; | 134 | err = -EBUSY; |
140 | switch (mode) { | 135 | switch (mode) { |
@@ -184,13 +179,14 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode) | |||
184 | vol->checked = 1; | 179 | vol->checked = 1; |
185 | } | 180 | } |
186 | mutex_unlock(&ubi->volumes_mutex); | 181 | mutex_unlock(&ubi->volumes_mutex); |
182 | |||
187 | return desc; | 183 | return desc; |
188 | 184 | ||
189 | out_unlock: | 185 | out_unlock: |
190 | spin_unlock(&ubi->volumes_lock); | 186 | spin_unlock(&ubi->volumes_lock); |
191 | kfree(desc); | ||
192 | out_put: | ||
193 | module_put(THIS_MODULE); | 187 | module_put(THIS_MODULE); |
188 | out_free: | ||
189 | kfree(desc); | ||
194 | return ERR_PTR(err); | 190 | return ERR_PTR(err); |
195 | } | 191 | } |
196 | EXPORT_SYMBOL_GPL(ubi_open_volume); | 192 | EXPORT_SYMBOL_GPL(ubi_open_volume); |
@@ -207,7 +203,6 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name, | |||
207 | int mode) | 203 | int mode) |
208 | { | 204 | { |
209 | int i, vol_id = -1, len; | 205 | int i, vol_id = -1, len; |
210 | struct ubi_volume_desc *ret; | ||
211 | struct ubi_device *ubi; | 206 | struct ubi_device *ubi; |
212 | 207 | ||
213 | dbg_msg("open volume %s, mode %d", name, mode); | 208 | dbg_msg("open volume %s, mode %d", name, mode); |
@@ -219,14 +214,12 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name, | |||
219 | if (len > UBI_VOL_NAME_MAX) | 214 | if (len > UBI_VOL_NAME_MAX) |
220 | return ERR_PTR(-EINVAL); | 215 | return ERR_PTR(-EINVAL); |
221 | 216 | ||
222 | ret = ERR_PTR(-ENODEV); | 217 | if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES) |
223 | if (!try_module_get(THIS_MODULE)) | 218 | return ERR_PTR(-EINVAL); |
224 | return ret; | ||
225 | |||
226 | if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES || !ubi_devices[ubi_num]) | ||
227 | goto out_put; | ||
228 | 219 | ||
229 | ubi = ubi_devices[ubi_num]; | 220 | ubi = ubi_devices[ubi_num]; |
221 | if (!ubi) | ||
222 | return ERR_PTR(-ENODEV); | ||
230 | 223 | ||
231 | spin_lock(&ubi->volumes_lock); | 224 | spin_lock(&ubi->volumes_lock); |
232 | /* Walk all volumes of this UBI device */ | 225 | /* Walk all volumes of this UBI device */ |
@@ -241,13 +234,9 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name, | |||
241 | spin_unlock(&ubi->volumes_lock); | 234 | spin_unlock(&ubi->volumes_lock); |
242 | 235 | ||
243 | if (vol_id < 0) | 236 | if (vol_id < 0) |
244 | goto out_put; | 237 | return ERR_PTR(-ENODEV); |
245 | |||
246 | ret = ubi_open_volume(ubi_num, vol_id, mode); | ||
247 | 238 | ||
248 | out_put: | 239 | return ubi_open_volume(ubi_num, vol_id, mode); |
249 | module_put(THIS_MODULE); | ||
250 | return ret; | ||
251 | } | 240 | } |
252 | EXPORT_SYMBOL_GPL(ubi_open_volume_nm); | 241 | EXPORT_SYMBOL_GPL(ubi_open_volume_nm); |
253 | 242 | ||