Skip to content

Commit

Permalink
uml: drivers get release methods
Browse files Browse the repository at this point in the history
Define release methods for the ubd and net drivers.  They contain as much of
the remove methods as make sense.  All error checking must have already been
done as well as anything else that might be holding a reference on the device
kobject.

Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Jeff Dike authored and Linus Torvalds committed May 7, 2007
1 parent d883935 commit 2e3f525
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 15 additions & 4 deletions arch/um/drivers/net_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,19 @@ static struct platform_driver uml_net_driver = {
};
static int driver_registered;

static void net_device_release(struct device *dev)
{
struct uml_net *device = dev->driver_data;
struct net_device *netdev = device->dev;
struct uml_net_private *lp = netdev->priv;

if(lp->remove != NULL)
(*lp->remove)(&lp->user);
list_del(&device->list);
kfree(device);
free_netdev(netdev);
}

static void eth_configure(int n, void *init, char *mac,
struct transport *transport)
{
Expand Down Expand Up @@ -396,6 +409,8 @@ static void eth_configure(int n, void *init, char *mac,
}
device->pdev.id = n;
device->pdev.name = DRIVER_NAME;
device->pdev.dev.release = net_device_release;
device->pdev.dev.driver_data = device;
if(platform_device_register(&device->pdev))
goto out_free_netdev;
SET_NETDEV_DEV(dev,&device->pdev.dev);
Expand Down Expand Up @@ -689,13 +704,9 @@ static int net_remove(int n, char **error_out)
lp = dev->priv;
if(lp->fd > 0)
return -EBUSY;
if(lp->remove != NULL) (*lp->remove)(&lp->user);
unregister_netdev(dev);
platform_device_unregister(&device->pdev);

list_del(&device->list);
kfree(device);
free_netdev(dev);
return 0;
}

Expand Down
17 changes: 12 additions & 5 deletions arch/um/drivers/ubd_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,14 @@ static int ubd_open_dev(struct ubd *ubd_dev)
return(err);
}

static void ubd_device_release(struct device *dev)
{
struct ubd *ubd_dev = dev->driver_data;

blk_cleanup_queue(ubd_dev->queue);
*ubd_dev = ((struct ubd) DEFAULT_UBD);
}

static int ubd_disk_register(int major, u64 size, int unit,
struct gendisk **disk_out)
{
Expand All @@ -644,6 +652,8 @@ static int ubd_disk_register(int major, u64 size, int unit,
if (major == MAJOR_NR) {
ubd_devs[unit].pdev.id = unit;
ubd_devs[unit].pdev.name = DRIVER_NAME;
ubd_devs[unit].pdev.dev.release = ubd_device_release;
ubd_devs[unit].pdev.dev.driver_data = &ubd_devs[unit];
platform_device_register(&ubd_devs[unit].pdev);
disk->driverfs_dev = &ubd_devs[unit].pdev.dev;
}
Expand Down Expand Up @@ -787,7 +797,7 @@ static int ubd_id(char **str, int *start_out, int *end_out)

static int ubd_remove(int n, char **error_out)
{
struct gendisk *disk;
struct gendisk *disk = ubd_gendisk[n];
struct ubd *ubd_dev;
int err = -ENODEV;

Expand All @@ -803,7 +813,6 @@ static int ubd_remove(int n, char **error_out)
if(ubd_dev->count > 0)
goto out;

disk = ubd_gendisk[n];
ubd_gendisk[n] = NULL;
if(disk != NULL){
del_gendisk(disk);
Expand All @@ -816,10 +825,8 @@ static int ubd_remove(int n, char **error_out)
fake_gendisk[n] = NULL;
}

blk_cleanup_queue(ubd_dev->queue);
platform_device_unregister(&ubd_dev->pdev);
*ubd_dev = ((struct ubd) DEFAULT_UBD);
err = 0;
platform_device_unregister(&ubd_dev->pdev);
out:
mutex_unlock(&ubd_lock);
return err;
Expand Down

0 comments on commit 2e3f525

Please sign in to comment.