ubi: register ubi devices and volumes as devices
struct ubi_device and struct ubi_volume have devices attached to them. Register them to make them part of the barebox device hierarchy. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
0c76b7e377
commit
9c66af7b0e
|
@ -157,10 +157,18 @@ static int uif_init(struct ubi_device *ubi, int *ref)
|
|||
*ref = 0;
|
||||
sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num);
|
||||
|
||||
sprintf(ubi->dev.name, "ubi");
|
||||
ubi->dev.id = DEVICE_ID_DYNAMIC;
|
||||
ubi->dev.parent = &ubi->mtd->class_dev;
|
||||
|
||||
err = register_device(&ubi->dev);
|
||||
if (err)
|
||||
goto out_unreg;
|
||||
|
||||
err = ubi_cdev_add(ubi);
|
||||
if (err) {
|
||||
ubi_err("cannot add character device");
|
||||
goto out_unreg;
|
||||
goto out_dev;
|
||||
}
|
||||
|
||||
for (i = 0; i < ubi->vtbl_slots; i++)
|
||||
|
@ -177,6 +185,8 @@ static int uif_init(struct ubi_device *ubi, int *ref)
|
|||
out_volumes:
|
||||
kill_volumes(ubi);
|
||||
devfs_remove(&ubi->cdev);
|
||||
out_dev:
|
||||
unregister_device(&ubi->dev);
|
||||
out_unreg:
|
||||
ubi_err("cannot initialize UBI %s, error %d", ubi->ubi_name, err);
|
||||
return err;
|
||||
|
@ -193,6 +203,7 @@ out_unreg:
|
|||
static void uif_close(struct ubi_device *ubi)
|
||||
{
|
||||
kill_volumes(ubi);
|
||||
unregister_device(&ubi->dev);
|
||||
ubi_cdev_remove(ubi);
|
||||
}
|
||||
|
||||
|
|
|
@ -179,6 +179,7 @@ int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol)
|
|||
cdev->name = asprintf("ubi%d.%s", ubi->ubi_num, vol->name);
|
||||
cdev->priv = priv;
|
||||
cdev->size = vol->used_bytes;
|
||||
cdev->dev = &vol->dev;
|
||||
printf("registering %s as /dev/%s\n", vol->name, cdev->name);
|
||||
ret = devfs_create(cdev);
|
||||
if (ret) {
|
||||
|
@ -199,6 +200,7 @@ void ubi_volume_cdev_remove(struct ubi_volume *vol)
|
|||
list_del(&vol->list);
|
||||
|
||||
devfs_remove(cdev);
|
||||
unregister_device(&vol->dev);
|
||||
kfree(cdev->name);
|
||||
kfree(priv);
|
||||
}
|
||||
|
|
|
@ -147,6 +147,13 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
|
|||
vol->last_eb_bytes = vol->usable_leb_size;
|
||||
}
|
||||
|
||||
sprintf(vol->dev.name, "%s.%s", dev_name(&ubi->dev), vol->name);
|
||||
vol->dev.id = DEVICE_ID_SINGLE;
|
||||
vol->dev.parent = &ubi->dev;
|
||||
err = register_device(&vol->dev);
|
||||
if (err)
|
||||
goto out_acc;
|
||||
|
||||
/* Register character device for the volume */
|
||||
err = ubi_volume_cdev_add(ubi, vol);
|
||||
if (err) {
|
||||
|
@ -190,6 +197,7 @@ out_sysfs:
|
|||
out_mapping:
|
||||
if (do_free)
|
||||
kfree(vol->eba_tbl);
|
||||
unregister_device(&vol->dev);
|
||||
out_acc:
|
||||
ubi->rsvd_pebs -= vol->reserved_pebs;
|
||||
ubi->avail_pebs += vol->reserved_pebs;
|
||||
|
@ -245,6 +253,7 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)
|
|||
goto out_err;
|
||||
}
|
||||
|
||||
unregister_device(&vol->dev);
|
||||
devfs_remove(&vol->cdev);
|
||||
|
||||
ubi->rsvd_pebs -= reserved_pebs;
|
||||
|
@ -427,6 +436,13 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
|
|||
|
||||
dbg_gen("add volume");
|
||||
|
||||
sprintf(vol->dev.name, "%s.%s", dev_name(&ubi->dev), vol->name);
|
||||
vol->dev.id = DEVICE_ID_SINGLE;
|
||||
vol->dev.parent = &ubi->dev;
|
||||
err = register_device(&vol->dev);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Register character device for the volume */
|
||||
err = ubi_volume_cdev_add(ubi, vol);
|
||||
if (err) {
|
||||
|
@ -454,6 +470,7 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
|
|||
dbg_gen("free volume %d", vol->vol_id);
|
||||
|
||||
ubi->volumes[vol->vol_id] = NULL;
|
||||
unregister_device(&vol->dev);
|
||||
devfs_remove(&vol->cdev);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue