Commit 00552a1f authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

KREF: fix up the current kref users for the changed api.

        
Based on work from Kiran, but fixed up by me to actually build and
link properly.
Signed-off-by: default avatarRavikiran Thirumalai <kiran@in.ibm.com>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 5e5f1d28
...@@ -188,7 +188,7 @@ static struct scsi_disk *scsi_disk_get(struct gendisk *disk) ...@@ -188,7 +188,7 @@ static struct scsi_disk *scsi_disk_get(struct gendisk *disk)
return sdkp; return sdkp;
out_put: out_put:
kref_put(&sdkp->kref); kref_put(&sdkp->kref, scsi_disk_release);
out_sdkp: out_sdkp:
sdkp = NULL; sdkp = NULL;
out: out:
...@@ -200,7 +200,7 @@ static void scsi_disk_put(struct scsi_disk *sdkp) ...@@ -200,7 +200,7 @@ static void scsi_disk_put(struct scsi_disk *sdkp)
{ {
down(&sd_ref_sem); down(&sd_ref_sem);
scsi_device_put(sdkp->device); scsi_device_put(sdkp->device);
kref_put(&sdkp->kref); kref_put(&sdkp->kref, scsi_disk_release);
up(&sd_ref_sem); up(&sd_ref_sem);
} }
...@@ -1362,7 +1362,7 @@ static int sd_probe(struct device *dev) ...@@ -1362,7 +1362,7 @@ static int sd_probe(struct device *dev)
goto out; goto out;
memset (sdkp, 0, sizeof(*sdkp)); memset (sdkp, 0, sizeof(*sdkp));
kref_init(&sdkp->kref, scsi_disk_release); kref_init(&sdkp->kref);
/* Note: We can accomodate 64 partitions, but the genhd code /* Note: We can accomodate 64 partitions, but the genhd code
* assumes partitions allocate consecutive minors, which they don't. * assumes partitions allocate consecutive minors, which they don't.
...@@ -1464,7 +1464,7 @@ static int sd_remove(struct device *dev) ...@@ -1464,7 +1464,7 @@ static int sd_remove(struct device *dev)
del_gendisk(sdkp->disk); del_gendisk(sdkp->disk);
sd_shutdown(dev); sd_shutdown(dev);
down(&sd_ref_sem); down(&sd_ref_sem);
kref_put(&sdkp->kref); kref_put(&sdkp->kref, scsi_disk_release);
up(&sd_ref_sem); up(&sd_ref_sem);
return 0; return 0;
......
...@@ -147,7 +147,7 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) ...@@ -147,7 +147,7 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
goto out; goto out;
out_put: out_put:
kref_put(&cd->kref); kref_put(&cd->kref, sr_kref_release);
out_null: out_null:
cd = NULL; cd = NULL;
out: out:
...@@ -159,7 +159,7 @@ static inline void scsi_cd_put(struct scsi_cd *cd) ...@@ -159,7 +159,7 @@ static inline void scsi_cd_put(struct scsi_cd *cd)
{ {
down(&sr_ref_sem); down(&sr_ref_sem);
scsi_device_put(cd->device); scsi_device_put(cd->device);
kref_put(&cd->kref); kref_put(&cd->kref, sr_kref_release);
up(&sr_ref_sem); up(&sr_ref_sem);
} }
...@@ -576,7 +576,7 @@ static int sr_probe(struct device *dev) ...@@ -576,7 +576,7 @@ static int sr_probe(struct device *dev)
goto fail; goto fail;
memset(cd, 0, sizeof(*cd)); memset(cd, 0, sizeof(*cd));
kref_init(&cd->kref, sr_kref_release); kref_init(&cd->kref);
disk = alloc_disk(1); disk = alloc_disk(1);
if (!disk) if (!disk)
...@@ -937,7 +937,7 @@ static int sr_remove(struct device *dev) ...@@ -937,7 +937,7 @@ static int sr_remove(struct device *dev)
del_gendisk(cd->disk); del_gendisk(cd->disk);
down(&sr_ref_sem); down(&sr_ref_sem);
kref_put(&cd->kref); kref_put(&cd->kref, sr_kref_release);
up(&sr_ref_sem); up(&sr_ref_sem);
return 0; return 0;
......
...@@ -106,7 +106,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, ...@@ -106,7 +106,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
return buffer - buffer0 + i; return buffer - buffer0 + i;
} }
static void usb_release_interface_cache(struct kref *ref) void usb_release_interface_cache(struct kref *ref)
{ {
struct usb_interface_cache *intfc = ref_to_usb_interface_cache(ref); struct usb_interface_cache *intfc = ref_to_usb_interface_cache(ref);
int j; int j;
...@@ -356,7 +356,7 @@ int usb_parse_configuration(struct device *ddev, int cfgidx, ...@@ -356,7 +356,7 @@ int usb_parse_configuration(struct device *ddev, int cfgidx,
if (!intfc) if (!intfc)
return -ENOMEM; return -ENOMEM;
memset(intfc, 0, len); memset(intfc, 0, len);
kref_init(&intfc->ref, usb_release_interface_cache); kref_init(&intfc->ref);
} }
/* Skip over any Class Specific or Vendor Specific descriptors; /* Skip over any Class Specific or Vendor Specific descriptors;
...@@ -422,7 +422,8 @@ void usb_destroy_configuration(struct usb_device *dev) ...@@ -422,7 +422,8 @@ void usb_destroy_configuration(struct usb_device *dev)
for (i = 0; i < cf->desc.bNumInterfaces; i++) { for (i = 0; i < cf->desc.bNumInterfaces; i++) {
if (cf->intf_cache[i]) if (cf->intf_cache[i])
kref_put(&cf->intf_cache[i]->ref); kref_put(&cf->intf_cache[i]->ref,
usb_release_interface_cache);
} }
} }
kfree(dev->config); kfree(dev->config);
......
...@@ -1195,7 +1195,7 @@ static void release_interface(struct device *dev) ...@@ -1195,7 +1195,7 @@ static void release_interface(struct device *dev)
struct usb_interface_cache *intfc = struct usb_interface_cache *intfc =
altsetting_to_usb_interface_cache(intf->altsetting); altsetting_to_usb_interface_cache(intf->altsetting);
kref_put(&intfc->ref); kref_put(&intfc->ref, usb_release_interface_cache);
kfree(intf); kfree(intf);
} }
......
...@@ -39,7 +39,7 @@ void usb_init_urb(struct urb *urb) ...@@ -39,7 +39,7 @@ void usb_init_urb(struct urb *urb)
{ {
if (urb) { if (urb) {
memset(urb, 0, sizeof(*urb)); memset(urb, 0, sizeof(*urb));
kref_init(&urb->kref, urb_destroy); kref_init(&urb->kref);
spin_lock_init(&urb->lock); spin_lock_init(&urb->lock);
} }
} }
...@@ -88,7 +88,7 @@ struct urb *usb_alloc_urb(int iso_packets, int mem_flags) ...@@ -88,7 +88,7 @@ struct urb *usb_alloc_urb(int iso_packets, int mem_flags)
void usb_free_urb(struct urb *urb) void usb_free_urb(struct urb *urb)
{ {
if (urb) if (urb)
kref_put(&urb->kref); kref_put(&urb->kref, urb_destroy);
} }
/** /**
......
...@@ -10,6 +10,7 @@ extern int usb_unbind_interface (struct device *dev); ...@@ -10,6 +10,7 @@ extern int usb_unbind_interface (struct device *dev);
extern void usb_disable_endpoint (struct usb_device *dev, unsigned int epaddr); extern void usb_disable_endpoint (struct usb_device *dev, unsigned int epaddr);
extern void usb_disable_interface (struct usb_device *dev, extern void usb_disable_interface (struct usb_device *dev,
struct usb_interface *intf); struct usb_interface *intf);
extern void usb_release_interface_cache(struct kref *ref);
extern void usb_disable_device (struct usb_device *dev, int skip_ep0); extern void usb_disable_device (struct usb_device *dev, int skip_ep0);
extern void usb_enable_endpoint (struct usb_device *dev, extern void usb_enable_endpoint (struct usb_device *dev,
......
...@@ -114,7 +114,7 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, int flags) ...@@ -114,7 +114,7 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, int flags)
return qh; return qh;
memset (qh, 0, sizeof *qh); memset (qh, 0, sizeof *qh);
kref_init(&qh->kref, qh_destroy); kref_init(&qh->kref);
qh->ehci = ehci; qh->ehci = ehci;
qh->qh_dma = dma; qh->qh_dma = dma;
// INIT_LIST_HEAD (&qh->qh_list); // INIT_LIST_HEAD (&qh->qh_list);
...@@ -139,7 +139,7 @@ static inline struct ehci_qh *qh_get (struct ehci_qh *qh) ...@@ -139,7 +139,7 @@ static inline struct ehci_qh *qh_get (struct ehci_qh *qh)
static inline void qh_put (struct ehci_qh *qh) static inline void qh_put (struct ehci_qh *qh)
{ {
kref_put(&qh->kref); kref_put(&qh->kref, qh_destroy);
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
......
...@@ -421,6 +421,63 @@ static void return_serial (struct usb_serial *serial) ...@@ -421,6 +421,63 @@ static void return_serial (struct usb_serial *serial)
return; return;
} }
static void destroy_serial(struct kref *kref)
{
struct usb_serial *serial;
struct usb_serial_port *port;
int i;
serial = to_usb_serial(kref);
dbg ("%s - %s", __FUNCTION__, serial->type->name);
serial->type->shutdown(serial);
/* return the minor range that this device had */
return_serial(serial);
for (i = 0; i < serial->num_ports; ++i)
serial->port[i]->open_count = 0;
/* the ports are cleaned up and released in port_release() */
for (i = 0; i < serial->num_ports; ++i)
if (serial->port[i]->dev.parent != NULL) {
device_unregister(&serial->port[i]->dev);
serial->port[i] = NULL;
}
/* If this is a "fake" port, we have to clean it up here, as it will
* not get cleaned up in port_release() as it was never registered with
* the driver core */
if (serial->num_ports < serial->num_port_pointers) {
for (i = serial->num_ports; i < serial->num_port_pointers; ++i) {
port = serial->port[i];
if (!port)
continue;
if (port->read_urb) {
usb_unlink_urb(port->read_urb);
usb_free_urb(port->read_urb);
}
if (port->write_urb) {
usb_unlink_urb(port->write_urb);
usb_free_urb(port->write_urb);
}
if (port->interrupt_in_urb) {
usb_unlink_urb(port->interrupt_in_urb);
usb_free_urb(port->interrupt_in_urb);
}
kfree(port->bulk_in_buffer);
kfree(port->bulk_out_buffer);
kfree(port->interrupt_in_buffer);
}
}
usb_put_dev(serial->dev);
/* free up any memory that we allocated */
kfree (serial);
}
/***************************************************************************** /*****************************************************************************
* Driver tty interface functions * Driver tty interface functions
*****************************************************************************/ *****************************************************************************/
...@@ -465,7 +522,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp) ...@@ -465,7 +522,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);
kref_put(&serial->kref); kref_put(&serial->kref, destroy_serial);
} }
} }
bailout: bailout:
...@@ -496,7 +553,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp) ...@@ -496,7 +553,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
} }
module_put(port->serial->type->owner); module_put(port->serial->type->owner);
kref_put(&port->serial->kref); kref_put(&port->serial->kref, destroy_serial);
} }
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)
...@@ -654,13 +711,6 @@ static void serial_break (struct tty_struct *tty, int break_state) ...@@ -654,13 +711,6 @@ static void serial_break (struct tty_struct *tty, int break_state)
; ;
} }
static void serial_shutdown (struct usb_serial *serial)
{
dbg ("%s", __FUNCTION__);
serial->type->shutdown(serial);
}
static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data) static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
{ {
struct usb_serial *serial; struct usb_serial *serial;
...@@ -694,7 +744,7 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int ...@@ -694,7 +744,7 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
begin += length; begin += length;
length = 0; length = 0;
} }
kref_put(&serial->kref); kref_put(&serial->kref, destroy_serial);
} }
*eof = 1; *eof = 1;
done: done:
...@@ -763,62 +813,6 @@ void usb_serial_port_softint(void *private) ...@@ -763,62 +813,6 @@ void usb_serial_port_softint(void *private)
wake_up_interruptible(&tty->write_wait); wake_up_interruptible(&tty->write_wait);
} }
static void destroy_serial(struct kref *kref)
{
struct usb_serial *serial;
struct usb_serial_port *port;
int i;
serial = to_usb_serial(kref);
dbg ("%s - %s", __FUNCTION__, serial->type->name);
serial_shutdown (serial);
/* return the minor range that this device had */
return_serial(serial);
for (i = 0; i < serial->num_ports; ++i)
serial->port[i]->open_count = 0;
/* the ports are cleaned up and released in port_release() */
for (i = 0; i < serial->num_ports; ++i)
if (serial->port[i]->dev.parent != NULL) {
device_unregister(&serial->port[i]->dev);
serial->port[i] = NULL;
}
/* If this is a "fake" port, we have to clean it up here, as it will
* not get cleaned up in port_release() as it was never registered with
* the driver core */
if (serial->num_ports < serial->num_port_pointers) {
for (i = serial->num_ports; i < serial->num_port_pointers; ++i) {
port = serial->port[i];
if (!port)
continue;
if (port->read_urb) {
usb_unlink_urb(port->read_urb);
usb_free_urb(port->read_urb);
}
if (port->write_urb) {
usb_unlink_urb(port->write_urb);
usb_free_urb(port->write_urb);
}
if (port->interrupt_in_urb) {
usb_unlink_urb(port->interrupt_in_urb);
usb_free_urb(port->interrupt_in_urb);
}
kfree(port->bulk_in_buffer);
kfree(port->bulk_out_buffer);
kfree(port->interrupt_in_buffer);
}
}
usb_put_dev(serial->dev);
/* free up any memory that we allocated */
kfree (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);
...@@ -859,7 +853,7 @@ static struct usb_serial * create_serial (struct usb_device *dev, ...@@ -859,7 +853,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); kref_init(&serial->kref);
return serial; return serial;
} }
...@@ -1209,7 +1203,7 @@ void usb_serial_disconnect(struct usb_interface *interface) ...@@ -1209,7 +1203,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 */
kref_put(&serial->kref); kref_put(&serial->kref, destroy_serial);
} }
dev_info(dev, "device disconnected\n"); dev_info(dev, "device disconnected\n");
} }
......
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