提交 1bc3c9e1 编写于 作者: J Jesper Juhl 提交者: Greg K-H

[PATCH] USB: kfree cleanup for drivers/usb/* - no need to check for NULL

Get rid of a bunch of redundant NULL pointer checks in drivers/usb/*,
there's no need to check a pointer for NULL before calling kfree() on it.
Signed-off-by: NJesper Juhl <juhl-lkml@dif.dk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>


Index: gregkh-2.6/drivers/usb/class/audio.c
===================================================================
上级 6fd19f4b
......@@ -649,14 +649,10 @@ static void usbin_stop(struct usb_audiodev *as)
}
}
set_current_state(TASK_RUNNING);
if (u->durb[0].urb->transfer_buffer)
kfree(u->durb[0].urb->transfer_buffer);
if (u->durb[1].urb->transfer_buffer)
kfree(u->durb[1].urb->transfer_buffer);
if (u->surb[0].urb->transfer_buffer)
kfree(u->surb[0].urb->transfer_buffer);
if (u->surb[1].urb->transfer_buffer)
kfree(u->surb[1].urb->transfer_buffer);
kfree(u->durb[0].urb->transfer_buffer);
kfree(u->durb[1].urb->transfer_buffer);
kfree(u->surb[0].urb->transfer_buffer);
kfree(u->surb[1].urb->transfer_buffer);
u->durb[0].urb->transfer_buffer = u->durb[1].urb->transfer_buffer =
u->surb[0].urb->transfer_buffer = u->surb[1].urb->transfer_buffer = NULL;
}
......@@ -1009,21 +1005,17 @@ static int usbin_start(struct usb_audiodev *as)
u->phase = 0;
maxsze = (u->freqmax + 0x3fff) >> (14 - AFMT_BYTESSHIFT(u->format));
bufsz = DESCFRAMES * maxsze;
if (u->durb[0].urb->transfer_buffer)
kfree(u->durb[0].urb->transfer_buffer);
kfree(u->durb[0].urb->transfer_buffer);
u->durb[0].urb->transfer_buffer = kmalloc(bufsz, GFP_KERNEL);
u->durb[0].urb->transfer_buffer_length = bufsz;
if (u->durb[1].urb->transfer_buffer)
kfree(u->durb[1].urb->transfer_buffer);
kfree(u->durb[1].urb->transfer_buffer);
u->durb[1].urb->transfer_buffer = kmalloc(bufsz, GFP_KERNEL);
u->durb[1].urb->transfer_buffer_length = bufsz;
if (u->syncpipe) {
if (u->surb[0].urb->transfer_buffer)
kfree(u->surb[0].urb->transfer_buffer);
kfree(u->surb[0].urb->transfer_buffer);
u->surb[0].urb->transfer_buffer = kmalloc(3*SYNCFRAMES, GFP_KERNEL);
u->surb[0].urb->transfer_buffer_length = 3*SYNCFRAMES;
if (u->surb[1].urb->transfer_buffer)
kfree(u->surb[1].urb->transfer_buffer);
kfree(u->surb[1].urb->transfer_buffer);
u->surb[1].urb->transfer_buffer = kmalloc(3*SYNCFRAMES, GFP_KERNEL);
u->surb[1].urb->transfer_buffer_length = 3*SYNCFRAMES;
}
......@@ -1128,14 +1120,10 @@ static void usbout_stop(struct usb_audiodev *as)
}
}
set_current_state(TASK_RUNNING);
if (u->durb[0].urb->transfer_buffer)
kfree(u->durb[0].urb->transfer_buffer);
if (u->durb[1].urb->transfer_buffer)
kfree(u->durb[1].urb->transfer_buffer);
if (u->surb[0].urb->transfer_buffer)
kfree(u->surb[0].urb->transfer_buffer);
if (u->surb[1].urb->transfer_buffer)
kfree(u->surb[1].urb->transfer_buffer);
kfree(u->durb[0].urb->transfer_buffer);
kfree(u->durb[1].urb->transfer_buffer);
kfree(u->surb[0].urb->transfer_buffer);
kfree(u->surb[1].urb->transfer_buffer);
u->durb[0].urb->transfer_buffer = u->durb[1].urb->transfer_buffer =
u->surb[0].urb->transfer_buffer = u->surb[1].urb->transfer_buffer = NULL;
}
......@@ -1376,21 +1364,17 @@ static int usbout_start(struct usb_audiodev *as)
u->phase = 0;
maxsze = (u->freqmax + 0x3fff) >> (14 - AFMT_BYTESSHIFT(u->format));
bufsz = DESCFRAMES * maxsze;
if (u->durb[0].urb->transfer_buffer)
kfree(u->durb[0].urb->transfer_buffer);
kfree(u->durb[0].urb->transfer_buffer);
u->durb[0].urb->transfer_buffer = kmalloc(bufsz, GFP_KERNEL);
u->durb[0].urb->transfer_buffer_length = bufsz;
if (u->durb[1].urb->transfer_buffer)
kfree(u->durb[1].urb->transfer_buffer);
kfree(u->durb[1].urb->transfer_buffer);
u->durb[1].urb->transfer_buffer = kmalloc(bufsz, GFP_KERNEL);
u->durb[1].urb->transfer_buffer_length = bufsz;
if (u->syncpipe) {
if (u->surb[0].urb->transfer_buffer)
kfree(u->surb[0].urb->transfer_buffer);
kfree(u->surb[0].urb->transfer_buffer);
u->surb[0].urb->transfer_buffer = kmalloc(3*SYNCFRAMES, GFP_KERNEL);
u->surb[0].urb->transfer_buffer_length = 3*SYNCFRAMES;
if (u->surb[1].urb->transfer_buffer)
kfree(u->surb[1].urb->transfer_buffer);
kfree(u->surb[1].urb->transfer_buffer);
u->surb[1].urb->transfer_buffer = kmalloc(3*SYNCFRAMES, GFP_KERNEL);
u->surb[1].urb->transfer_buffer_length = 3*SYNCFRAMES;
}
......
......@@ -309,7 +309,7 @@ static int bluetooth_ctrl_msg (struct usb_bluetooth *bluetooth, int request, int
}
}
if (urb->transfer_buffer_length < len) {
kfree (urb->transfer_buffer);
kfree(urb->transfer_buffer);
urb->transfer_buffer = kmalloc (len, GFP_KERNEL);
if (urb->transfer_buffer == NULL) {
err ("%s - out of memory", __FUNCTION__);
......@@ -535,7 +535,7 @@ static int bluetooth_write (struct tty_struct * tty, const unsigned char *buf, i
}
exit:
kfree (temp_buffer);
kfree(temp_buffer);
return retval;
}
......
......@@ -637,11 +637,8 @@ static int usb_device_open(struct inode *inode, struct file *file)
static int usb_device_release(struct inode *inode, struct file *file)
{
if (file->private_data) {
kfree(file->private_data);
file->private_data = NULL;
}
kfree(file->private_data);
file->private_data = NULL;
return 0;
}
......
......@@ -381,7 +381,7 @@ static void hub_tt_kevent (void *arg)
dev_err (&hdev->dev,
"clear tt %d (%04x) error %d\n",
clear->tt, clear->devinfo, status);
kfree (clear);
kfree(clear);
}
spin_unlock_irqrestore (&hub->tt.lock, flags);
}
......@@ -728,15 +728,11 @@ static void hub_disconnect(struct usb_interface *intf)
list_del_init(&hub->event_list);
spin_unlock_irq(&hub_event_lock);
if (hub->descriptor) {
kfree(hub->descriptor);
hub->descriptor = NULL;
}
kfree(hub->descriptor);
hub->descriptor = NULL;
if (hub->status) {
kfree(hub->status);
hub->status = NULL;
}
kfree(hub->status);
hub->status = NULL;
if (hub->buffer) {
usb_buffer_free(hdev, sizeof(*hub->buffer), hub->buffer,
......@@ -2354,7 +2350,7 @@ check_highspeed (struct usb_hub *hub, struct usb_device *udev, int port1)
schedule_work (&hub->leds);
}
}
kfree (qual);
kfree(qual);
}
static unsigned
......
......@@ -2312,9 +2312,8 @@ static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags)
*/
void gs_buf_free(struct gs_buf *gb)
{
if (gb != NULL) {
if (gb->buf_buf != NULL)
kfree(gb->buf_buf);
if (gb) {
kfree(gb->buf_buf);
kfree(gb);
}
}
......
......@@ -156,8 +156,7 @@ static void ehci_mem_cleanup (struct ehci_hcd *ehci)
ehci->periodic = NULL;
/* shadow periodic table */
if (ehci->pshadow)
kfree (ehci->pshadow);
kfree(ehci->pshadow);
ehci->pshadow = NULL;
}
......
......@@ -890,8 +890,7 @@ static int __init uhci_hcd_init(void)
debugfs_remove(uhci_debugfs_root);
debug_failed:
if (errbuf)
kfree(errbuf);
kfree(errbuf);
errbuf_failed:
......@@ -906,9 +905,7 @@ static void __exit uhci_hcd_cleanup(void)
warn("not all urb_priv's were freed!");
debugfs_remove(uhci_debugfs_root);
if (errbuf)
kfree(errbuf);
kfree(errbuf);
}
module_init(uhci_hcd_init);
......
......@@ -558,8 +558,7 @@ static void hid_free_device(struct hid_device *device)
}
}
if (device->rdesc)
kfree(device->rdesc);
kfree(device->rdesc);
kfree(device);
}
......
......@@ -138,8 +138,7 @@ static int dabusb_free_queue (struct list_head *q)
#ifdef DEBUG
dump_urb(b->purb);
#endif
if (b->purb->transfer_buffer)
kfree (b->purb->transfer_buffer);
kfree(b->purb->transfer_buffer);
usb_free_urb(b->purb);
tmp = p->next;
list_del (p);
......
......@@ -3915,10 +3915,8 @@ ov51x_do_dealloc(struct usb_ov511 *ov)
ov->tempfbuf = NULL;
for (i = 0; i < OV511_NUMSBUF; i++) {
if (ov->sbuf[i].data) {
kfree(ov->sbuf[i].data);
ov->sbuf[i].data = NULL;
}
kfree(ov->sbuf[i].data);
ov->sbuf[i].data = NULL;
}
for (i = 0; i < OV511_NUMFRAMES; i++) {
......@@ -5954,10 +5952,8 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
up(&ov->cbuf_lock);
}
if (ov) {
kfree(ov);
ov = NULL;
}
kfree(ov);
ov = NULL;
error_out:
err("Camera initialization failed");
......
......@@ -868,13 +868,14 @@ static void usb_se401_remove_disconnected (struct usb_se401 *se401)
se401->dev = NULL;
for (i=0; i<SE401_NUMSBUF; i++) if (se401->urb[i]) {
usb_kill_urb(se401->urb[i]);
usb_free_urb(se401->urb[i]);
se401->urb[i] = NULL;
kfree(se401->sbuf[i].data);
}
for (i=0; i<SE401_NUMSCRATCH; i++) if (se401->scratch[i].data) {
for (i=0; i<SE401_NUMSBUF; i++)
if (se401->urb[i]) {
usb_kill_urb(se401->urb[i]);
usb_free_urb(se401->urb[i]);
se401->urb[i] = NULL;
kfree(se401->sbuf[i].data);
}
for (i=0; i<SE401_NUMSCRATCH; i++) {
kfree(se401->scratch[i].data);
}
if (se401->inturb) {
......
......@@ -1169,10 +1169,8 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
}
RingQueue_Free(&uvd->dp);
for (i=0; i < USBVIDEO_NUMSBUF; i++) {
if (uvd->sbuf[i].data != NULL) {
kfree (uvd->sbuf[i].data);
uvd->sbuf[i].data = NULL;
}
kfree(uvd->sbuf[i].data);
uvd->sbuf[i].data = NULL;
}
}
}
......
......@@ -3624,10 +3624,8 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
return 0;
fail: /* Free unused memory */
if (cam->control_buffer)
kfree(cam->control_buffer);
if (cam->data_buffer)
kfree(cam->data_buffer);
kfree(cam->control_buffer);
kfree(cam->data_buffer);
if (cam->v4ldev)
video_device_release(cam->v4ldev);
up(&cam->dev_sem);
......
......@@ -705,16 +705,12 @@ static int auerchain_control_msg (pauerchain_t acp, struct usb_device *dev, unsi
/* free a single auerbuf */
static void auerbuf_free (pauerbuf_t bp)
{
if (bp->bufp) {
kfree (bp->bufp);
}
if (bp->dr) {
kfree (bp->dr);
}
kfree(bp->bufp);
kfree(bp->dr);
if (bp->urbp) {
usb_free_urb (bp->urbp);
usb_free_urb(bp->urbp);
}
kfree (bp);
kfree(bp);
}
/* free the buffers from an auerbuf list */
......@@ -1093,14 +1089,12 @@ static void auerswald_int_complete (struct urb * urb, struct pt_regs *regs)
*/
static void auerswald_int_free (pauerswald_t cp)
{
if (cp->inturbp) {
usb_free_urb (cp->inturbp);
cp->inturbp = NULL;
}
if (cp->intbufp) {
kfree (cp->intbufp);
cp->intbufp = NULL;
}
if (cp->inturbp) {
usb_free_urb(cp->inturbp);
cp->inturbp = NULL;
}
kfree(cp->intbufp);
cp->intbufp = NULL;
}
/* This function is called to activate the interrupt
......
......@@ -106,8 +106,7 @@ int zd1201_fw_upload(struct usb_device *dev, int apfw)
err = 0;
exit:
if (buf)
kfree(buf);
kfree(buf);
release_firmware(fw_entry);
return err;
}
......
......@@ -202,8 +202,7 @@ static void belkin_sa_shutdown (struct usb_serial *serial)
for (i=0; i < serial->num_ports; ++i) {
/* My special items, the standard routines free my urbs */
priv = usb_get_serial_port_data(serial->port[i]);
if (priv)
kfree(priv);
kfree(priv);
}
}
......
......@@ -1340,9 +1340,8 @@ static struct cypress_buf *cypress_buf_alloc(unsigned int size)
static void cypress_buf_free(struct cypress_buf *cb)
{
if (cb != NULL) {
if (cb->buf_buf != NULL)
kfree(cb->buf_buf);
if (cb) {
kfree(cb->buf_buf);
kfree(cb);
}
}
......
......@@ -550,8 +550,7 @@ static int __init empeg_init (void)
failed_usb_serial_register:
for (i = 0; i < NUM_URBS; ++i) {
if (write_urb_pool[i]) {
if (write_urb_pool[i]->transfer_buffer)
kfree(write_urb_pool[i]->transfer_buffer);
kfree(write_urb_pool[i]->transfer_buffer);
usb_free_urb(write_urb_pool[i]);
}
}
......@@ -575,8 +574,7 @@ static void __exit empeg_exit (void)
* the host controllers get fixed to set urb->dev = NULL after
* the urb is finished. Otherwise this call oopses. */
/* usb_kill_urb(write_urb_pool[i]); */
if (write_urb_pool[i]->transfer_buffer)
kfree(write_urb_pool[i]->transfer_buffer);
kfree(write_urb_pool[i]->transfer_buffer);
usb_free_urb (write_urb_pool[i]);
}
}
......
......@@ -1347,9 +1347,7 @@ static int ftdi_common_startup (struct usb_serial *serial)
priv->flags = ASYNC_LOW_LATENCY;
/* Increase the size of read buffers */
if (port->bulk_in_buffer) {
kfree (port->bulk_in_buffer);
}
kfree(port->bulk_in_buffer);
port->bulk_in_buffer = kmalloc (BUFSZ, GFP_KERNEL);
if (!port->bulk_in_buffer) {
kfree (priv);
......@@ -1365,10 +1363,8 @@ static int ftdi_common_startup (struct usb_serial *serial)
usb_free_urb (port->write_urb);
port->write_urb = NULL;
}
if (port->bulk_out_buffer) {
kfree (port->bulk_out_buffer);
port->bulk_out_buffer = NULL;
}
kfree(port->bulk_out_buffer);
port->bulk_out_buffer = NULL;
usb_set_serial_port_data(serial->port[0], priv);
......
......@@ -951,9 +951,7 @@ static void edge_bulk_out_cmd_callback (struct urb *urb, struct pt_regs *regs)
/* clean up the transfer buffer */
if (urb->transfer_buffer != NULL) {
kfree(urb->transfer_buffer);
}
kfree(urb->transfer_buffer);
/* Free the command urb */
usb_free_urb (urb);
......@@ -1266,16 +1264,12 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
if (edge_port->write_urb) {
/* if this urb had a transfer buffer already (old transfer) free it */
if (edge_port->write_urb->transfer_buffer != NULL) {
kfree(edge_port->write_urb->transfer_buffer);
}
usb_free_urb (edge_port->write_urb);
kfree(edge_port->write_urb->transfer_buffer);
usb_free_urb(edge_port->write_urb);
edge_port->write_urb = NULL;
}
if (edge_port->txfifo.fifo) {
kfree(edge_port->txfifo.fifo);
edge_port->txfifo.fifo = NULL;
}
kfree(edge_port->txfifo.fifo);
edge_port->txfifo.fifo = NULL;
dbg("%s exited", __FUNCTION__);
}
......@@ -1419,11 +1413,9 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
// get a pointer to the write_urb
urb = edge_port->write_urb;
/* if this urb had a transfer buffer already (old transfer) free it */
if (urb->transfer_buffer != NULL) {
kfree(urb->transfer_buffer);
urb->transfer_buffer = NULL;
}
/* make sure transfer buffer is freed */
kfree(urb->transfer_buffer);
urb->transfer_buffer = NULL;
/* build the data header for the buffer and port that we are about to send out */
count = fifo->count;
......
......@@ -2845,9 +2845,8 @@ static struct edge_buf *edge_buf_alloc(unsigned int size)
void edge_buf_free(struct edge_buf *eb)
{
if (eb != NULL) {
if (eb->buf_buf != NULL)
kfree(eb->buf_buf);
if (eb) {
kfree(eb->buf_buf);
kfree(eb);
}
}
......
......@@ -341,8 +341,7 @@ static void klsi_105_shutdown (struct usb_serial *serial)
* finished. Otherwise this call
* oopses. */
/* usb_kill_urb(write_urbs[j]); */
if (write_urbs[j]->transfer_buffer)
kfree(write_urbs[j]->transfer_buffer);
kfree(write_urbs[j]->transfer_buffer);
usb_free_urb (write_urbs[j]);
}
}
......
......@@ -178,7 +178,6 @@ static void omninet_close (struct usb_serial_port *port, struct file * filp)
{
struct usb_serial *serial = port->serial;
struct usb_serial_port *wport;
struct omninet_data *od;
dbg("%s - port %d", __FUNCTION__, port->number);
......@@ -186,9 +185,7 @@ static void omninet_close (struct usb_serial_port *port, struct file * filp)
usb_kill_urb(wport->write_urb);
usb_kill_urb(port->read_urb);
od = usb_get_serial_port_data(port);
if (od)
kfree(od);
kfree(usb_get_serial_port_data(port));
}
......
......@@ -1044,9 +1044,8 @@ static struct pl2303_buf *pl2303_buf_alloc(unsigned int size)
static void pl2303_buf_free(struct pl2303_buf *pb)
{
if (pb != NULL) {
if (pb->buf_buf != NULL)
kfree(pb->buf_buf);
if (pb) {
kfree(pb->buf_buf);
kfree(pb);
}
}
......
......@@ -517,8 +517,7 @@ static void ti_shutdown(struct usb_serial *serial)
}
}
if (tdev)
kfree(tdev);
kfree(tdev);
usb_set_serial_data(serial, NULL);
}
......
......@@ -119,10 +119,8 @@ static int sddr55_status(struct us_data *us)
/* expect to get short transfer if no card fitted */
if (result == USB_STOR_XFER_SHORT || result == USB_STOR_XFER_STALLED) {
/* had a short transfer, no card inserted, free map memory */
if (info->lba_to_pba)
kfree(info->lba_to_pba);
if (info->pba_to_lba)
kfree(info->pba_to_lba);
kfree(info->lba_to_pba);
kfree(info->pba_to_lba);
info->lba_to_pba = NULL;
info->pba_to_lba = NULL;
......@@ -649,18 +647,14 @@ static int sddr55_read_map(struct us_data *us) {
return -1;
}
if (info->lba_to_pba)
kfree(info->lba_to_pba);
if (info->pba_to_lba)
kfree(info->pba_to_lba);
kfree(info->lba_to_pba);
kfree(info->pba_to_lba);
info->lba_to_pba = kmalloc(numblocks*sizeof(int), GFP_NOIO);
info->pba_to_lba = kmalloc(numblocks*sizeof(int), GFP_NOIO);
if (info->lba_to_pba == NULL || info->pba_to_lba == NULL) {
if (info->lba_to_pba != NULL)
kfree(info->lba_to_pba);
if (info->pba_to_lba != NULL)
kfree(info->pba_to_lba);
kfree(info->lba_to_pba);
kfree(info->pba_to_lba);
info->lba_to_pba = NULL;
info->pba_to_lba = NULL;
kfree(buffer);
......@@ -728,10 +722,8 @@ static void sddr55_card_info_destructor(void *extra) {
if (!extra)
return;
if (info->lba_to_pba)
kfree(info->lba_to_pba);
if (info->pba_to_lba)
kfree(info->pba_to_lba);
kfree(info->lba_to_pba);
kfree(info->pba_to_lba);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册