Commit 35ad5fb7 authored by Artem Bityutskiy's avatar Artem Bityutskiy

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: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent fc75a1e1
...@@ -104,37 +104,32 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode) ...@@ -104,37 +104,32 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
dbg_msg("open device %d volume %d, mode %d", ubi_num, vol_id, mode); dbg_msg("open device %d volume %d, mode %d", ubi_num, vol_id, mode);
err = -ENODEV; if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES)
if (ubi_num < 0) return ERR_PTR(-EINVAL);
return ERR_PTR(err);
ubi = ubi_devices[ubi_num];
if (!try_module_get(THIS_MODULE)) if (mode != UBI_READONLY && mode != UBI_READWRITE &&
return ERR_PTR(err); mode != UBI_EXCLUSIVE)
return ERR_PTR(-EINVAL);
if (ubi_num >= UBI_MAX_DEVICES || !ubi) ubi = ubi_devices[ubi_num];
goto out_put; if (!ubi)
return ERR_PTR(-ENODEV);
err = -EINVAL;
if (vol_id < 0 || vol_id >= ubi->vtbl_slots) if (vol_id < 0 || vol_id >= ubi->vtbl_slots)
goto out_put; return ERR_PTR(-EINVAL);
if (mode != UBI_READONLY && mode != UBI_READWRITE &&
mode != UBI_EXCLUSIVE)
goto out_put;
desc = kmalloc(sizeof(struct ubi_volume_desc), GFP_KERNEL); desc = kmalloc(sizeof(struct ubi_volume_desc), GFP_KERNEL);
if (!desc) { if (!desc)
err = -ENOMEM; return ERR_PTR(-ENOMEM);
goto out_put;
} err = -ENODEV;
if (!try_module_get(THIS_MODULE))
goto out_free;
spin_lock(&ubi->volumes_lock); spin_lock(&ubi->volumes_lock);
vol = ubi->volumes[vol_id]; vol = ubi->volumes[vol_id];
if (!vol) { if (!vol)
err = -ENODEV;
goto out_unlock; goto out_unlock;
}
err = -EBUSY; err = -EBUSY;
switch (mode) { switch (mode) {
...@@ -184,13 +179,14 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode) ...@@ -184,13 +179,14 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
vol->checked = 1; vol->checked = 1;
} }
mutex_unlock(&ubi->volumes_mutex); mutex_unlock(&ubi->volumes_mutex);
return desc; return desc;
out_unlock: out_unlock:
spin_unlock(&ubi->volumes_lock); spin_unlock(&ubi->volumes_lock);
kfree(desc);
out_put:
module_put(THIS_MODULE); module_put(THIS_MODULE);
out_free:
kfree(desc);
return ERR_PTR(err); return ERR_PTR(err);
} }
EXPORT_SYMBOL_GPL(ubi_open_volume); 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,7 +203,6 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
int mode) int mode)
{ {
int i, vol_id = -1, len; int i, vol_id = -1, len;
struct ubi_volume_desc *ret;
struct ubi_device *ubi; struct ubi_device *ubi;
dbg_msg("open volume %s, mode %d", name, mode); 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,14 +214,12 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
if (len > UBI_VOL_NAME_MAX) if (len > UBI_VOL_NAME_MAX)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
ret = ERR_PTR(-ENODEV); if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES)
if (!try_module_get(THIS_MODULE)) return ERR_PTR(-EINVAL);
return ret;
if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES || !ubi_devices[ubi_num])
goto out_put;
ubi = ubi_devices[ubi_num]; ubi = ubi_devices[ubi_num];
if (!ubi)
return ERR_PTR(-ENODEV);
spin_lock(&ubi->volumes_lock); spin_lock(&ubi->volumes_lock);
/* Walk all volumes of this UBI device */ /* 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,13 +234,9 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
spin_unlock(&ubi->volumes_lock); spin_unlock(&ubi->volumes_lock);
if (vol_id < 0) if (vol_id < 0)
goto out_put; return ERR_PTR(-ENODEV);
ret = ubi_open_volume(ubi_num, vol_id, mode);
out_put: return ubi_open_volume(ubi_num, vol_id, mode);
module_put(THIS_MODULE);
return ret;
} }
EXPORT_SYMBOL_GPL(ubi_open_volume_nm); EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment