Skip to content

Commit

Permalink
[PATCH] USB: convert usbfs/devio.c to use usb notifiers
Browse files Browse the repository at this point in the history
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Greg Kroah-Hartman committed Oct 28, 2005
1 parent 3099e75 commit a7b986b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
41 changes: 34 additions & 7 deletions drivers/usb/core/devio.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <linux/usb.h>
#include <linux/usbdevice_fs.h>
#include <linux/cdev.h>
#include <linux/notifier.h>
#include <asm/uaccess.h>
#include <asm/byteorder.h>
#include <linux/moduleparam.h>
Expand Down Expand Up @@ -1550,7 +1551,7 @@ struct file_operations usbfs_device_file_operations = {
.release = usbdev_release,
};

void usbdev_add(struct usb_device *dev)
static void usbdev_add(struct usb_device *dev)
{
int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1);

Expand All @@ -1561,11 +1562,29 @@ void usbdev_add(struct usb_device *dev)
dev->class_dev->class_data = dev;
}

void usbdev_remove(struct usb_device *dev)
static void usbdev_remove(struct usb_device *dev)
{
class_device_unregister(dev->class_dev);
}

static int usbdev_notify(struct notifier_block *self, unsigned long action,
void *dev)
{
switch (action) {
case USB_DEVICE_ADD:
usbdev_add(dev);
break;
case USB_DEVICE_REMOVE:
usbdev_remove(dev);
break;
}
return NOTIFY_OK;
}

static struct notifier_block usbdev_nb = {
.notifier_call = usbdev_notify,
};

static struct cdev usb_device_cdev = {
.kobj = {.name = "usb_device", },
.owner = THIS_MODULE,
Expand All @@ -1585,24 +1604,32 @@ int __init usbdev_init(void)
retval = cdev_add(&usb_device_cdev, USB_DEVICE_DEV, USB_DEVICE_MAX);
if (retval) {
err("unable to get usb_device major %d", USB_DEVICE_MAJOR);
unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
goto out;
goto error_cdev;
}
usb_device_class = class_create(THIS_MODULE, "usb_device");
if (IS_ERR(usb_device_class)) {
err("unable to register usb_device class");
retval = PTR_ERR(usb_device_class);
usb_device_class = NULL;
cdev_del(&usb_device_cdev);
unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
goto error_class;
}

usb_register_notify(&usbdev_nb);

out:
return retval;

error_class:
usb_device_class = NULL;
cdev_del(&usb_device_cdev);

error_cdev:
unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
goto out;
}

void usbdev_cleanup(void)
{
usb_unregister_notify(&usbdev_nb);
class_destroy(usb_device_class);
cdev_del(&usb_device_cdev);
unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
Expand Down
2 changes: 0 additions & 2 deletions drivers/usb/core/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,6 @@ void usb_disconnect(struct usb_device **pdev)
dev_dbg (&udev->dev, "unregistering device\n");
release_address(udev);
usbfs_remove_device(udev);
usbdev_remove(udev);
usb_remove_sysfs_dev_files(udev);

/* Avoid races with recursively_mark_NOTATTACHED() */
Expand Down Expand Up @@ -1376,7 +1375,6 @@ int usb_new_device(struct usb_device *udev)
usb_notify_add_device(udev);

/* add a /proc/bus/usb entry */
usbdev_add(udev);
usbfs_add_device(udev);
return 0;

Expand Down
2 changes: 0 additions & 2 deletions drivers/usb/core/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ extern void usbfs_conn_disc_event(void);

extern int usbdev_init(void);
extern void usbdev_cleanup(void);
extern void usbdev_add(struct usb_device *dev);
extern void usbdev_remove(struct usb_device *dev);

struct dev_state {
struct list_head list; /* state list */
Expand Down

0 comments on commit a7b986b

Please sign in to comment.