Commit da53a89c authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

[PATCH] USB: replace kobject with kref in usb-serial core.

This saves some memory and is easier to understand what is happening.
parent dd471fb2
...@@ -391,7 +391,7 @@ struct usb_serial *usb_serial_get_by_index(unsigned index) ...@@ -391,7 +391,7 @@ struct usb_serial *usb_serial_get_by_index(unsigned index)
struct usb_serial *serial = serial_table[index]; struct usb_serial *serial = serial_table[index];
if (serial) if (serial)
kobject_get (&serial->kobj); kref_get(&serial->kref);
return serial; return serial;
} }
...@@ -486,7 +486,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp) ...@@ -486,7 +486,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
if (retval) { if (retval) {
port->open_count = 0; port->open_count = 0;
module_put(serial->type->owner); module_put(serial->type->owner);
kobject_put(&serial->kobj); kref_put(&serial->kref);
} }
} }
bailout: bailout:
...@@ -518,7 +518,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp) ...@@ -518,7 +518,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
} }
module_put(port->serial->type->owner); module_put(port->serial->type->owner);
kobject_put(&port->serial->kobj); kref_put(&port->serial->kref);
} }
static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count) static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
...@@ -748,7 +748,7 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int ...@@ -748,7 +748,7 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
begin += length; begin += length;
length = 0; length = 0;
} }
kobject_put(&serial->kobj); kref_put(&serial->kref);
} }
*eof = 1; *eof = 1;
done: done:
...@@ -830,15 +830,15 @@ void usb_serial_port_softint(void *private) ...@@ -830,15 +830,15 @@ void usb_serial_port_softint(void *private)
wake_up_interruptible(&tty->write_wait); wake_up_interruptible(&tty->write_wait);
} }
static void destroy_serial (struct kobject *kobj) static void destroy_serial(struct kref *kref)
{ {
struct usb_serial *serial; struct usb_serial *serial;
struct usb_serial_port *port; struct usb_serial_port *port;
int i; int i;
dbg ("%s - %s", __FUNCTION__, kobj->name); serial = to_usb_serial(kref);
serial = to_usb_serial(kobj); dbg ("%s - %s", __FUNCTION__, serial->type->name);
serial_shutdown (serial); serial_shutdown (serial);
/* return the minor range that this device had */ /* return the minor range that this device had */
...@@ -886,10 +886,6 @@ static void destroy_serial (struct kobject *kobj) ...@@ -886,10 +886,6 @@ static void destroy_serial (struct kobject *kobj)
kfree (serial); kfree (serial);
} }
static struct kobj_type usb_serial_kobj_type = {
.release = destroy_serial,
};
static void port_release(struct device *dev) static void port_release(struct device *dev)
{ {
struct usb_serial_port *port = to_usb_serial_port(dev); struct usb_serial_port *port = to_usb_serial_port(dev);
...@@ -930,10 +926,7 @@ static struct usb_serial * create_serial (struct usb_device *dev, ...@@ -930,10 +926,7 @@ static struct usb_serial * create_serial (struct usb_device *dev,
serial->interface = interface; serial->interface = interface;
serial->vendor = dev->descriptor.idVendor; serial->vendor = dev->descriptor.idVendor;
serial->product = dev->descriptor.idProduct; serial->product = dev->descriptor.idProduct;
kref_init(&serial->kref, destroy_serial);
/* initialize the kobject portion of the usb_device */
kobject_init(&serial->kobj);
serial->kobj.ktype = &usb_serial_kobj_type;
return serial; return serial;
} }
...@@ -1284,7 +1277,7 @@ void usb_serial_disconnect(struct usb_interface *interface) ...@@ -1284,7 +1277,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
if (serial) { if (serial) {
/* let the last holder of this object /* let the last holder of this object
* cause it to be cleaned up */ * cause it to be cleaned up */
kobject_put (&serial->kobj); kref_put(&serial->kref);
} }
dev_info(dev, "device disconnected\n"); dev_info(dev, "device disconnected\n");
} }
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#define __LINUX_USB_SERIAL_H #define __LINUX_USB_SERIAL_H
#include <linux/config.h> #include <linux/config.h>
#include <linux/kref.h>
#define SERIAL_TTY_MAJOR 188 /* Nice legal number now */ #define SERIAL_TTY_MAJOR 188 /* Nice legal number now */
#define SERIAL_TTY_MINORS 255 /* loads of devices :) */ #define SERIAL_TTY_MINORS 255 /* loads of devices :) */
...@@ -163,10 +164,10 @@ struct usb_serial { ...@@ -163,10 +164,10 @@ struct usb_serial {
__u16 vendor; __u16 vendor;
__u16 product; __u16 product;
struct usb_serial_port * port[MAX_NUM_PORTS]; struct usb_serial_port * port[MAX_NUM_PORTS];
struct kobject kobj; struct kref kref;
void * private; void * private;
}; };
#define to_usb_serial(d) container_of(d, struct usb_serial, kobj) #define to_usb_serial(d) container_of(d, struct usb_serial, kref)
#define NUM_DONT_CARE (-1) #define NUM_DONT_CARE (-1)
......
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