[PATCH] vfree and kfree cleanup in drivers/
authorJesper Juhl <jesper.juhl@gmail.com>
Sat, 10 Sep 2005 07:26:54 +0000 (00:26 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sat, 10 Sep 2005 17:06:30 +0000 (10:06 -0700)
This patch does a full cleanup of 'NULL checks before vfree', and a partial
cleanup of calls to kfree for all of drivers/ - the kfree bit is partial in
that I only did the files that also had vfree calls in them.  The patch
also gets rid of some redundant (void *) casts of pointers being passed to
[vk]free, and a some tiny whitespace corrections also crept in.

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
20 files changed:
drivers/block/z2ram.c
drivers/cdrom/sbpcd.c
drivers/char/agp/backend.c
drivers/isdn/i4l/isdn_bsdcomp.c
drivers/isdn/i4l/isdn_common.c
drivers/md/dm-exception-store.c
drivers/media/common/saa7146_core.c
drivers/media/video/cpia_usb.c
drivers/media/video/stradis.c
drivers/media/video/video-buf.c
drivers/media/video/zoran_driver.c
drivers/media/video/zr36120.c
drivers/mtd/devices/mtdram.c
drivers/mtd/ftl.c
drivers/net/bsd_comp.c
drivers/scsi/53c7xx.c
drivers/scsi/cpqfcTSinit.c
drivers/scsi/osst.c
drivers/usb/media/stv680.c
drivers/video/vgastate.c

index 007f6a6624392c6427601306dddebbda745d60e9..bb5e8d665a2a3ce8bd41fbd647bd06eeec772541 100644 (file)
@@ -296,7 +296,7 @@ z2_open( struct inode *inode, struct file *filp )
     return 0;
 
 err_out_kfree:
-    kfree( z2ram_map );
+    kfree(z2ram_map);
 err_out:
     return rc;
 }
index 30a8977553617c86fb5ec42601ce59dc266811b6..0b7d7412c4a5f69fcd0ba8ccf34b0d2c084ad7e7 100644 (file)
@@ -4216,7 +4216,8 @@ static int sbpcd_dev_ioctl(struct cdrom_device_info *cdi, u_int cmd,
                
        case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
                msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
-               if (current_drive->sbp_audsiz>0) vfree(current_drive->aud_buf);
+               if (current_drive->sbp_audsiz>0)
+                       vfree(current_drive->aud_buf);
                current_drive->aud_buf=NULL;
                current_drive->sbp_audsiz=arg;
                
@@ -5910,7 +5911,8 @@ static void sbpcd_exit(void)
                put_disk(D_S[j].disk);
                devfs_remove("sbp/c0t%d", j);
                vfree(D_S[j].sbp_buf);
-               if (D_S[j].sbp_audsiz>0) vfree(D_S[j].aud_buf);
+               if (D_S[j].sbp_audsiz>0)
+                       vfree(D_S[j].aud_buf);
                if ((unregister_cdrom(D_S[j].sbpcd_infop) == -EINVAL))
                {
                        msg(DBG_INF, "What's that: can't unregister info %s.\n", major_name);
index 4d4e602fdc7e7cfa326000b84135583ed866296d..82b43c541c8dca52ad90c0ea6c6b984a50c455ee 100644 (file)
@@ -206,10 +206,9 @@ static void agp_backend_cleanup(struct agp_bridge_data *bridge)
                bridge->driver->cleanup();
        if (bridge->driver->free_gatt_table)
                bridge->driver->free_gatt_table(bridge);
-       if (bridge->key_list) {
-               vfree(bridge->key_list);
-               bridge->key_list = NULL;
-       }
+
+       vfree(bridge->key_list);
+       bridge->key_list = NULL;
 
        if (bridge->driver->agp_destroy_page &&
            bridge->driver->needs_scratch_page)
index baf4bcad9bf93a825c34941ea57e9f244b1d5bff..0afe442db3b0011568fc96f5f5c2d2baae591342 100644 (file)
@@ -283,23 +283,19 @@ static void bsd_free (void *state)
                /*
                 * Release the dictionary
                 */
-               if (db->dict) {
-                       vfree (db->dict);
-                       db->dict = NULL;
-               }
+               vfree(db->dict);
+               db->dict = NULL;
 
                /*
                 * Release the string buffer
                 */
-               if (db->lens) {
-                       vfree (db->lens);
-                       db->lens = NULL;
-               }
+               vfree(db->lens);
+               db->lens = NULL;
 
                /*
                 * Finally release the structure itself.
                 */
-               kfree (db);
+               kfree(db);
        }
 }
 
index eebcb0b97f0e9b6f05d0df1bfa12633285dd9f37..8a7d54a5c97d6634525d31e536aa3af098087a5a 100644 (file)
@@ -1953,7 +1953,8 @@ isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
                kfree(d->rcvcount);
        if (!(d->rcvcount = kmalloc(sizeof(int) * m, GFP_ATOMIC))) {
                printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
-               if (!adding) kfree(d->rcverr);
+               if (!adding)
+                       kfree(d->rcverr);
                return -1;
        }
        memset((char *) d->rcvcount, 0, sizeof(int) * m);
index 17212b4201a156aa7d17040ebeabb339b1af0f42..cc07bbebbb1688156db22c88d746ae54a18b41ee 100644 (file)
@@ -568,12 +568,9 @@ int dm_create_persistent(struct exception_store *store, uint32_t chunk_size)
 
       bad:
        dm_io_put(sectors_to_pages(chunk_size));
-       if (ps) {
-               if (ps->area)
-                       free_area(ps);
-
-               kfree(ps);
-       }
+       if (ps && ps->area)
+               free_area(ps);
+       kfree(ps);
        return r;
 }
 
index cd5828b5e9e346ad2199ef18d542f31ebc0413ec..206cc2f61f26154bb3f5e1a6b62e888ee74e8065 100644 (file)
@@ -168,10 +168,8 @@ void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt)
                return;
        pci_free_consistent(pci, pt->size, pt->cpu, pt->dma);
        pt->cpu = NULL;
-       if (NULL != pt->slist) {
-               kfree(pt->slist);
-               pt->slist = NULL;
-       }
+       kfree(pt->slist);
+       pt->slist = NULL;
 }
 
 int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt)
index cdda423386c5ca3cdf33246893a0f80a82729908..9774e94d1e7d94ae7e8a8eb46a7e72b936680e8d 100644 (file)
@@ -445,10 +445,8 @@ static void cpia_usb_free_resources(struct usb_cpia *ucpia, int try)
                ucpia->sbuf[1].urb = NULL;
        }
 
-       if (ucpia->sbuf[1].data) {
-               kfree(ucpia->sbuf[1].data);
-               ucpia->sbuf[1].data = NULL;
-       }
+       kfree(ucpia->sbuf[1].data);
+       ucpia->sbuf[1].data = NULL;
  
        if (ucpia->sbuf[0].urb) {
                usb_kill_urb(ucpia->sbuf[0].urb);
@@ -456,10 +454,8 @@ static void cpia_usb_free_resources(struct usb_cpia *ucpia, int try)
                ucpia->sbuf[0].urb = NULL;
        }
 
-       if (ucpia->sbuf[0].data) {
-               kfree(ucpia->sbuf[0].data);
-               ucpia->sbuf[0].data = NULL;
-       }
+       kfree(ucpia->sbuf[0].data);
+       ucpia->sbuf[0].data = NULL;
 }
 
 static int cpia_usb_close(void *privdata)
@@ -623,20 +619,14 @@ static void cpia_disconnect(struct usb_interface *intf)
 
        ucpia->curbuff = ucpia->workbuff = NULL;
 
-       if (ucpia->buffers[2]) {
-               vfree(ucpia->buffers[2]);
-               ucpia->buffers[2] = NULL;
-       }
+       vfree(ucpia->buffers[2]);
+       ucpia->buffers[2] = NULL;
 
-       if (ucpia->buffers[1]) {
-               vfree(ucpia->buffers[1]);
-               ucpia->buffers[1] = NULL;
-       }
+       vfree(ucpia->buffers[1]);
+       ucpia->buffers[1] = NULL;
 
-       if (ucpia->buffers[0]) {
-               vfree(ucpia->buffers[0]);
-               ucpia->buffers[0] = NULL;
-       }
+       vfree(ucpia->buffers[0]);
+       ucpia->buffers[0] = NULL;
 
        cam->lowlevel_data = NULL;
        kfree(ucpia);
index b57743571087b892d3a351f7c07d769d5976db90..d4497dbae05c7b641abaa617e9f17563847ecd0e 100644 (file)
@@ -2184,30 +2184,18 @@ static void release_saa(void)
                vfree(saa->vidbuf);
                vfree(saa->audbuf);
                vfree(saa->osdbuf);
-               if (saa->dmavid2)
-                       kfree((void *) saa->dmavid2);
+               kfree(saa->dmavid2);
                saa->audbuf = saa->vidbuf = saa->osdbuf = NULL;
                saa->dmavid2 = NULL;
-               if (saa->dmadebi)
-                       kfree((void *) saa->dmadebi);
-               if (saa->dmavid1)
-                       kfree((void *) saa->dmavid1);
-               if (saa->dmavid2)
-                       kfree((void *) saa->dmavid2);
-               if (saa->dmavid3)
-                       kfree((void *) saa->dmavid3);
-               if (saa->dmaa1in)
-                       kfree((void *) saa->dmaa1in);
-               if (saa->dmaa1out)
-                       kfree((void *) saa->dmaa1out);
-               if (saa->dmaa2in)
-                       kfree((void *) saa->dmaa2in);
-               if (saa->dmaa2out)
-                       kfree((void *) saa->dmaa2out);
-               if (saa->dmaRPS1)
-                       kfree((void *) saa->dmaRPS1);
-               if (saa->dmaRPS2)
-                       kfree((void *) saa->dmaRPS2);
+               kfree(saa->dmadebi);
+               kfree(saa->dmavid1);
+               kfree(saa->dmavid3);
+               kfree(saa->dmaa1in);
+               kfree(saa->dmaa1out);
+               kfree(saa->dmaa2in);
+               kfree(saa->dmaa2out);
+               kfree(saa->dmaRPS1);
+               kfree(saa->dmaRPS2);
                free_irq(saa->irq, saa);
                if (saa->saa7146_mem)
                        iounmap(saa->saa7146_mem);
index 97354f253a80273b58e128c566222bf1d45038fb..574b8e36f3c611e54e4698db948b2dd04c9b8cb3 100644 (file)
@@ -267,10 +267,10 @@ int videobuf_dma_free(struct videobuf_dmabuf *dma)
                kfree(dma->pages);
                dma->pages = NULL;
        }
-       if (dma->vmalloc) {
-               vfree(dma->vmalloc);
-               dma->vmalloc = NULL;
-       }
+
+       vfree(dma->vmalloc);
+       dma->vmalloc = NULL;
+
        if (dma->bus_addr) {
                dma->bus_addr = 0;
        }
index ba838a42ec806c7e8fe1d55abb2ac1626585a28a..53adeb70f2cafb2f7a551ff5e121782f306df329 100644 (file)
@@ -650,7 +650,7 @@ jpg_fbuffer_free (struct file *file)
                                     off += PAGE_SIZE)
                                        ClearPageReserved(MAP_NR
                                                          (mem + off));
-                               kfree((void *) mem);
+                               kfree(mem);
                                fh->jpg_buffers.buffer[i].frag_tab[0] = 0;
                                fh->jpg_buffers.buffer[i].frag_tab[1] = 0;
                        }
index c33533155cc7242f9954dfd8a80ea5d4ae710625..07286816d7dfd4828df6aa879f17e02c864ac2d1 100644 (file)
@@ -820,11 +820,9 @@ void zoran_close(struct video_device* dev)
         msleep(100);                   /* Wait 1/10th of a second */
 
        /* free the allocated framebuffer */
-       if (ztv->fbuffer)
-               bfree( ztv->fbuffer, ZORAN_MAX_FBUFSIZE );
+       bfree(ztv->fbuffer, ZORAN_MAX_FBUFSIZE);
        ztv->fbuffer = 0;
-       if (ztv->overinfo.overlay)
-               kfree( ztv->overinfo.overlay );
+       kfree(ztv->overinfo.overlay);
        ztv->overinfo.overlay = 0;
 
 }
index bb713fed2f373c66fd13e8f29be3abbc733963bb..1443117fd8f4afb988becd36beb1d14a084c5646 100644 (file)
@@ -91,8 +91,7 @@ static void __exit cleanup_mtdram(void)
 {
        if (mtd_info) {
                del_mtd_device(mtd_info);
-               if (mtd_info->priv)
-                       vfree(mtd_info->priv);
+               vfree(mtd_info->priv);
                kfree(mtd_info);
        }
 }
index d9ab60b36fd43d571995165d3df190fdbebbb01b..d32c1b3a8ce34422bd7c476b80299beef40ebb67 100644 (file)
@@ -1017,27 +1017,16 @@ static int ftl_writesect(struct mtd_blktrans_dev *dev,
 
 void ftl_freepart(partition_t *part)
 {
-    if (part->VirtualBlockMap) {
        vfree(part->VirtualBlockMap);
        part->VirtualBlockMap = NULL;
-    }
-    if (part->VirtualPageMap) {
        kfree(part->VirtualPageMap);
        part->VirtualPageMap = NULL;
-    }
-    if (part->EUNInfo) {
        kfree(part->EUNInfo);
        part->EUNInfo = NULL;
-    }
-    if (part->XferInfo) {
        kfree(part->XferInfo);
        part->XferInfo = NULL;
-    }
-    if (part->bam_cache) {
        kfree(part->bam_cache);
        part->bam_cache = NULL;
-    }
-    
 } /* ftl_freepart */
 
 static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
index 3d88ad622bdb35faf267fcc2d4e21e04628af9eb..fb4098ed469eeb8a2be64d6754cddda98e640324 100644 (file)
@@ -323,33 +323,27 @@ static void bsd_reset (void *state)
  */
 
 static void bsd_free (void *state)
-  {
-    struct bsd_db *db = (struct bsd_db *) state;
+{
+       struct bsd_db *db = state;
     
-    if (db)
-      {
+       if (!db)
+               return;
+
 /*
  * Release the dictionary
  */
-       if (db->dict)
-         {
-           vfree (db->dict);
-           db->dict = NULL;
-         }
+       vfree(db->dict);
+       db->dict = NULL;
 /*
  * Release the string buffer
  */
-       if (db->lens)
-         {
-           vfree (db->lens);
-           db->lens = NULL;
-         }
+       vfree(db->lens);
+       db->lens = NULL;
 /*
  * Finally release the structure itself.
  */
-       kfree (db);
-      }
-  }
+       kfree(db);
+}
 
 /*
  * Allocate space for a (de) compressor.
index 2341d27ceed7359991733e564eebba5c6a039f08..7a33c708f5b3dd0a65d4433e3900d52f64ae42aa 100644 (file)
@@ -6090,8 +6090,8 @@ NCR53c7x0_release(struct Scsi_Host *host) {
     if (hostdata->num_cmds)
        printk ("scsi%d : leaked %d NCR53c7x0_cmd structures\n",
            host->host_no, hostdata->num_cmds);
-    if (hostdata->events) 
-       vfree ((void *)hostdata->events);
+
+    vfree(hostdata->events);
 
     /* XXX This assumes default cache mode to be IOMAP_FULL_CACHING, which
      * XXX may be invalid (CONFIG_060_WRITETHROUGH)
index d72be0ce89c84534911026dce7879659045bd619..3fda8d455c5b06e1965d95f26810d128586ab690 100644 (file)
@@ -691,8 +691,7 @@ int cpqfcTS_ioctl( struct scsi_device *ScsiDev, int Cmnd, void *arg)
         if(  copy_to_user( vendor_cmd->bufp, buf, vendor_cmd->len))
                result = -EFAULT;
 
-        if( buf) 
-         kfree( buf);
+       kfree(buf);
 
         return result;
       }
index 89a4a0615c22d67d6099527443347ec3f21f5026..3f2f2464fa6351ebbe8938c594e3f3cce3dec9c1 100644 (file)
@@ -1377,7 +1377,7 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
        
                if ((STp->buffer)->syscall_result || !SRpnt) {
                        printk(KERN_ERR "%s:E: Failed to read frame back from OnStream buffer\n", name);
-                       vfree((void *)buffer);
+                       vfree(buffer);
                        *aSRpnt = SRpnt;
                        return (-EIO);
                }
@@ -1419,7 +1419,7 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
 
                        if (new_frame > frame + 1000) {
                                printk(KERN_ERR "%s:E: Failed to find writable tape media\n", name);
-                               vfree((void *)buffer);
+                               vfree(buffer);
                                return (-EIO);
                        }
                        if ( i >= nframes + pending ) break;
@@ -1500,7 +1500,7 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
                             SRpnt->sr_sense_buffer[12]         ==  0 &&
                             SRpnt->sr_sense_buffer[13]         ==  2) {
                                printk(KERN_ERR "%s:E: Volume overflow in write error recovery\n", name);
-                               vfree((void *)buffer);
+                               vfree(buffer);
                                return (-EIO);                  /* hit end of tape = fail */
                        }
                        i = ((SRpnt->sr_sense_buffer[3] << 24) |
@@ -1525,7 +1525,7 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
        }
        if (!pending)
                osst_copy_to_buffer(STp->buffer, p);    /* so buffer content == at entry in all cases */
-       vfree((void *)buffer);
+       vfree(buffer);
        return 0;
 }
 
@@ -5852,7 +5852,7 @@ static int osst_remove(struct device *dev)
                        os_scsi_tapes[i] = NULL;
                        osst_nr_dev--;
                        write_unlock(&os_scsi_tapes_lock);
-                       if (tpnt->header_cache != NULL) vfree(tpnt->header_cache);
+                       vfree(tpnt->header_cache);
                        if (tpnt->buffer) {
                                normalize_buffer(tpnt->buffer);
                                kfree(tpnt->buffer);
@@ -5896,8 +5896,7 @@ static void __exit exit_osst (void)
                for (i=0; i < osst_max_dev; ++i) {
                        if (!(STp = os_scsi_tapes[i])) continue;
                        /* This is defensive, supposed to happen during detach */
-                       if (STp->header_cache)
-                               vfree(STp->header_cache);
+                       vfree(STp->header_cache);
                        if (STp->buffer) {
                                normalize_buffer(STp->buffer);
                                kfree(STp->buffer);
index 7398a7f19c1e4e994c8de5f2343fc6dcfe6255c3..0fd0fa9fec21f172d703f16fed7e34b246ed35a8 100644 (file)
@@ -260,7 +260,7 @@ static int stv_stop_video (struct usb_stv *dev)
                        PDEBUG (0, "STV(i): Camera set to original resolution");
        }
        /* origMode */
-       kfree (buf);
+       kfree(buf);
        return i;
 }
 
@@ -276,7 +276,7 @@ static int stv_set_video_mode (struct usb_stv *dev)
        }
 
        if ((i = stv_set_config (dev, 1, 0, 0)) < 0) {
-               kfree (buf);
+               kfree(buf);
                return i;
        }
 
@@ -301,13 +301,13 @@ static int stv_set_video_mode (struct usb_stv *dev)
        goto exit;
 
 error:
-       kfree (buf);
+       kfree(buf);
        if (stop_video == 1)
                stv_stop_video (dev);
        return -1;
 
 exit:
-       kfree (buf);
+       kfree(buf);
        return 0;
 }
 
@@ -327,7 +327,7 @@ static int stv_init (struct usb_stv *stv680)
 
        /* set config 1, interface 0, alternate 0 */
        if ((i = stv_set_config (stv680, 1, 0, 0)) < 0) {
-               kfree (buffer);
+               kfree(buffer);
                PDEBUG (0, "STV(e): set config 1,0,0 failed");
                return -1;
        }
@@ -435,11 +435,11 @@ static int stv_init (struct usb_stv *stv680)
 error:
        i = stv_sndctrl (0, stv680, 0x80, 0, buffer, 0x02);     /* Get Last Error */
        PDEBUG (1, "STV(i): last error: %i,  command = 0x%x", buffer[0], buffer[1]);
-       kfree (buffer);
+       kfree(buffer);
        return -1;
 
 exit:
-       kfree (buffer);
+       kfree(buffer);
 
        /* video = 320x240, 352x288 */
        if (stv680->CIF == 1) {
@@ -708,10 +708,10 @@ static int stv680_stop_stream (struct usb_stv *stv680)
                        usb_kill_urb (stv680->urb[i]);
                        usb_free_urb (stv680->urb[i]);
                        stv680->urb[i] = NULL;
-                       kfree (stv680->sbuf[i].data);
+                       kfree(stv680->sbuf[i].data);
                }
        for (i = 0; i < STV680_NUMSCRATCH; i++) {
-               kfree (stv680->scratch[i].data);
+               kfree(stv680->scratch[i].data);
                stv680->scratch[i].data = NULL;
        }
 
@@ -1068,7 +1068,7 @@ static int stv_close (struct inode *inode, struct file *file)
        stv680->user = 0;
 
        if (stv680->removed) {
-               kfree (stv680);
+               kfree(stv680);
                stv680 = NULL;
                PDEBUG (0, "STV(i): device unregistered");
        }
@@ -1445,14 +1445,14 @@ static inline void usb_stv680_remove_disconnected (struct usb_stv *stv680)
                        usb_kill_urb (stv680->urb[i]);
                        usb_free_urb (stv680->urb[i]);
                        stv680->urb[i] = NULL;
-                       kfree (stv680->sbuf[i].data);
+                       kfree(stv680->sbuf[i].data);
                }
        for (i = 0; i < STV680_NUMSCRATCH; i++)
-               kfree (stv680->scratch[i].data);
+               kfree(stv680->scratch[i].data);
        PDEBUG (0, "STV(i): %s disconnected", stv680->camera_name);
 
        /* Free the memory */
-       kfree (stv680);
+       kfree(stv680);
 }
 
 static void stv680_disconnect (struct usb_interface *intf)
index 0ea62d8bc703d1550f9d9a005d97cfb16c17ba76..ca92940f39438d9d7b4bffe0456815a2421b6b58 100644 (file)
@@ -342,16 +342,11 @@ static void vga_cleanup(struct vgastate *state)
        if (state->vidstate != NULL) {
                struct regstate *saved = (struct regstate *) state->vidstate;
 
-               if (saved->vga_font0) 
-                       vfree(saved->vga_font0);
-               if (saved->vga_font1) 
-                       vfree(saved->vga_font1);
-               if (saved->vga_text)
-                       vfree(saved->vga_text);
-               if (saved->vga_cmap)
-                       vfree(saved->vga_cmap);
-               if (saved->attr)
-                       vfree(saved->attr);
+               vfree(saved->vga_font0);
+               vfree(saved->vga_font1);
+               vfree(saved->vga_text);
+               vfree(saved->vga_cmap);
+               vfree(saved->attr);
                kfree(saved);
                state->vidstate = NULL;
        }