Replaced kmalloc/memset sequence with kzalloc or kcalloc.
authorIan Abbott <abbotti@mev.co.uk>
Wed, 17 Oct 2007 15:26:59 +0000 (15:26 +0000)
committerIan Abbott <abbotti@mev.co.uk>
Wed, 17 Oct 2007 15:26:59 +0000 (15:26 +0000)
18 files changed:
comedi/comedi_fops.c
comedi/drivers.c
comedi/drivers/amplc_dio200.c
comedi/drivers/cb_das16_cs.c
comedi/drivers/comedi_rt_timer.c
comedi/drivers/das08_cs.c
comedi/drivers/dt9812.c
comedi/drivers/jr3_pci.c
comedi/drivers/mite.c
comedi/drivers/ni_65xx.c
comedi/drivers/ni_daq_dio24.c
comedi/drivers/ni_labpc_cs.c
comedi/drivers/pcmda12.c
comedi/drivers/quatech_daqp_cs.c
comedi/drivers/unioxx5.c
comedi/drivers/usbdux.c
comedi/rt.c
include/linux/comedidev.h

index 7faf4e2afb5adbb29ac4dfb464661a9e78f4bdaf..4eebe26e4dfd6bafe72a175e83a5db942c0c63e7 100644 (file)
@@ -350,12 +350,10 @@ static int do_subdinfo_ioctl(comedi_device *dev,comedi_subdinfo *arg,void *file)
        comedi_subdevice *s;
 
 
-       tmp=kmalloc(dev->n_subdevices*sizeof(comedi_subdinfo),GFP_KERNEL);
+       tmp=kcalloc(dev->n_subdevices,sizeof(comedi_subdinfo),GFP_KERNEL);
        if(!tmp)
                return -ENOMEM;
 
-       memset(tmp,0,sizeof(comedi_subdinfo)*dev->n_subdevices);
-
        /* fill subdinfo structs */
        for(i=0;i<dev->n_subdevices;i++){
                s=dev->subdevices+i;
@@ -1717,7 +1715,7 @@ static int __init comedi_init(void)
                cdev_del(&comedi_cdev);
                return PTR_ERR(comedi_class);
        }
-       comedi_devices=(comedi_device *)kmalloc(sizeof(comedi_device)*COMEDI_NDEVICES,GFP_KERNEL);
+       comedi_devices=kcalloc(COMEDI_NDEVICES,sizeof(comedi_device),GFP_KERNEL);
        if(!comedi_devices)
        {
                unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS);
@@ -1725,7 +1723,6 @@ static int __init comedi_init(void)
                class_destroy(comedi_class);
                return -ENOMEM;
        }
-       memset(comedi_devices,0,sizeof(comedi_device)*COMEDI_NDEVICES);
 
        /* XXX requires /proc interface */
        comedi_proc_init();
index 059ff2a0d5342fbc654fdf90b075556aa1c0738f..b773344c205834e985eb90d112a573c02891177c 100644 (file)
@@ -268,13 +268,12 @@ static int postconfig(comedi_device *dev)
                        BUG_ON((s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) == 0);
                        BUG_ON(!s->do_cmdtest);
 
-                       async = kmalloc(sizeof(comedi_async), GFP_KERNEL);
+                       async = kzalloc(sizeof(comedi_async), GFP_KERNEL);
                        if(async == NULL)
                        {
                                printk("failed to allocate async struct\n");
                                return -ENOMEM;
                        }
-                       memset(async, 0, sizeof(comedi_async));
                        async->subdevice = s;
                        s->async = async;
 
index c5203d15439ea090c88d71f999346683e780a466..137347f7b6a947bc297e9ad854ff7db27542510e 100644 (file)
@@ -914,12 +914,11 @@ dio200_subdev_intr_init(comedi_device *dev, comedi_subdevice *s,
 {
        dio200_subdev_intr *subpriv;
 
-       subpriv = kmalloc(sizeof(*subpriv), GFP_KERNEL);
+       subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
        if (!subpriv) {
                printk(KERN_ERR "comedi%d: error! out of memory!\n", dev->minor);
                return -ENOMEM;
        }
-       memset(subpriv, 0, sizeof(*subpriv));
        subpriv->iobase = iobase;
        subpriv->has_int_sce = has_int_sce;
        subpriv->valid_isns = valid_isns;
@@ -1138,12 +1137,11 @@ dio200_subdev_8254_init(comedi_device *dev, comedi_subdevice *s,
        dio200_subdev_8254 *subpriv;
        unsigned int chan;
 
-       subpriv = kmalloc(sizeof(*subpriv), GFP_KERNEL);
+       subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
        if (!subpriv) {
                printk(KERN_ERR "comedi%d: error! out of memory!\n", dev->minor);
                return -ENOMEM;
        }
-       memset(subpriv, 0, sizeof(*subpriv));
 
        s->private = subpriv;
        s->type = COMEDI_SUBD_COUNTER;
index dbd0a0fb6be453f756d83c557ea73190c864cc82..a53f330e62ac80cbe736227267462c1c9d08283c 100644 (file)
@@ -684,9 +684,8 @@ static int das16cs_pcmcia_attach(struct pcmcia_device *link)
     DEBUG(0, "das16cs_pcmcia_attach()\n");
 
     /* Allocate space for private device-specific data */
-    local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
+    local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
     if (!local) return -ENOMEM;
-    memset(local, 0, sizeof(local_info_t));
     local->link = link;
     link->priv = local;
 
index 40211bdd5c700d0a8a28b947b0db99d05bb842d0..916deff1950ba3e75945ecae7ecdaf46efb7f046 100644 (file)
@@ -661,8 +661,7 @@ static int timer_attach(comedi_device *dev,comedi_devconfig *it)
        start_rt_timer( 1 );
        devpriv->timer_running = 1;
 
-       devpriv->rt_task = kmalloc(sizeof(RT_TASK),GFP_KERNEL);
-       memset(devpriv->rt_task,0,sizeof(RT_TASK));
+       devpriv->rt_task = kzalloc(sizeof(RT_TASK),GFP_KERNEL);
 
        // initialize real-time tasks
        ret = rt_task_init(devpriv->rt_task, timer_task_func,(int)dev, 3000,
@@ -674,8 +673,7 @@ static int timer_attach(comedi_device *dev,comedi_devconfig *it)
                return ret;
        }
 
-       devpriv->scan_task = kmalloc(sizeof(RT_TASK),GFP_KERNEL);
-       memset(devpriv->scan_task,0,sizeof(RT_TASK));
+       devpriv->scan_task = kzalloc(sizeof(RT_TASK),GFP_KERNEL);
 
        ret = rt_task_init(devpriv->scan_task, scan_task_func,
                (int)dev, 3000, scan_priority, 0, 0);
index f53032fd8a7c2d77da5b9215b453c6d7e6967c7a..db72bfea15cde59eb3230ff68d2f01ed6d5ff0e2 100644 (file)
@@ -185,9 +185,8 @@ static int das08_pcmcia_attach(struct pcmcia_device *link)
     DEBUG(0, "das08_pcmcia_attach()\n");
 
     /* Allocate space for private device-specific data */
-    local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
+    local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
     if (!local) return -ENOMEM;
-    memset(local, 0, sizeof(local_info_t));
     local->link = link;
     link->priv = local;
 
index 700e673b14f3e22b8d0ec8be3e6f3ac508d01abd..e83ebd498bc257bc874f9995febc87754ff48736 100644 (file)
@@ -489,12 +489,11 @@ static int dt9812_probe(struct usb_interface *interface,
   u8 fw;
 
   // allocate memory for our device state and initialize it
-  dev = kmalloc(sizeof(*dev), GFP_KERNEL);
+  dev = kzalloc(sizeof(*dev), GFP_KERNEL);
   if (dev == NULL) {
     err("Out of memory");
     goto error;
   }
-  memset(dev, 0x00, sizeof(*dev));
   KREF_INIT(&dev->kref, dt9812_delete);
   
   dev->udev = usb_get_dev(interface_to_usbdev(interface));
index cb79dcb2478440969aed95948bc1466c4d47c0f4..95e10bf62578de4e1b229905f46b38004b1d2cdf 100644 (file)
@@ -772,14 +772,13 @@ static int jr3_pci_attach(comedi_device *dev, comedi_devconfig *it)
     dev->subdevices[i].subdev_flags = SDF_READABLE|SDF_GROUND;
     dev->subdevices[i].n_chan = 8 * 7 + 2;
     dev->subdevices[i].insn_read = jr3_pci_ai_insn_read;
-    dev->subdevices[i].private = kmalloc(sizeof(jr3_pci_subdev_private), 
+    dev->subdevices[i].private = kzalloc(sizeof(jr3_pci_subdev_private), 
                                         GFP_KERNEL);
     if (dev->subdevices[i].private) {
       jr3_pci_subdev_private *p;
       int j;
 
       p = dev->subdevices[i].private;
-      memset(p, 0, sizeof(*p));
       p->channel = &devpriv->iobase->channel[i].data;
       printk("p->channel %p %p (%x)\n",
             p->channel, devpriv->iobase, 
index 870db3391bd3867eb5ae810e30f314c6e93e714d..62a5fce638262a70c8d5d40b2f72183246d7fae0 100644 (file)
@@ -80,13 +80,12 @@ void mite_init(void)
                if(pcidev->vendor==PCI_VENDOR_ID_NATINST){
                        unsigned i;
 
-                       mite=kmalloc(sizeof(*mite),GFP_KERNEL);
+                       mite=kzalloc(sizeof(*mite),GFP_KERNEL);
                        if(!mite){
                                printk("mite: allocation failed\n");
                                pci_dev_put(pcidev);
                                return;
                        }
-                       memset(mite,0,sizeof(*mite));
                        spin_lock_init(&mite->lock);
                        mite->pcidev=pci_dev_get(pcidev);
                        for(i = 0; i < MAX_MITE_DMA_CHANNELS; ++i)
index 0045049758d957fbce7ed3af466247cedc24a9ab..63bfd2ec7662c0a488f3a768d5386f48c3d020f4 100644 (file)
@@ -319,9 +319,8 @@ static inline ni_65xx_subdevice_private* sprivate(comedi_subdevice *subdev)
 }
 static ni_65xx_subdevice_private* ni_65xx_alloc_subdevice_private(void)
 {
-       ni_65xx_subdevice_private *subdev_private = kmalloc(sizeof(ni_65xx_subdevice_private), GFP_KERNEL);
+       ni_65xx_subdevice_private *subdev_private = kzalloc(sizeof(ni_65xx_subdevice_private), GFP_KERNEL);
        if(subdev_private == NULL) return NULL;
-       memset(subdev_private, 0, sizeof(ni_65xx_subdevice_private));
        return subdev_private;
 }
 
index 5eb614ad10e0d79345cb61f669b1458fdc7fd295..bb52285b86be0c4b18d82126a234cf52e456bb5a 100644 (file)
@@ -271,9 +271,8 @@ static int dio24_cs_attach(struct pcmcia_device *link)
     DEBUG(0, "dio24_cs_attach()\n");
 
     /* Allocate space for private device-specific data */
-    local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
+    local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
     if (!local) return -ENOMEM;
-    memset(local, 0, sizeof(local_info_t));
     local->link = link; link->priv = local;
 
     /* Interrupt setup */
index 4eca12c20e271670e92b933788b8c48078c7365a..cc8e6329b7bd5b651dc3b75000501397a945a6bc 100644 (file)
@@ -212,9 +212,8 @@ static int labpc_cs_attach(struct pcmcia_device *link)
     DEBUG(0, "labpc_cs_attach()\n");
 
     /* Allocate space for private device-specific data */
-    local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
+    local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
     if (!local) return -ENOMEM;
-    memset(local, 0, sizeof(local_info_t));
     local->link = link; link->priv = local;
 
     /* Interrupt setup */
index 8b84a41f3428e8a0cc60f841410727a7ce1fc9ee..0f708d4754d2d001ecab25b6074c46c35e87d69b 100644 (file)
@@ -187,8 +187,6 @@ static int pcmda12_attach(comedi_device *dev, comedi_devconfig *it)
       return -ENOMEM;
     }
 
-    memset(devpriv, 0, sizeof(*devpriv));
-
     devpriv->simultaneous_xfer_mode = it->options[1];
 
       /*
index 32666486471618fab76b877aefe0a8c83d51c786..4e9cc6594ac6cc9358b09afc3f85a0af87d0f5f8 100644 (file)
@@ -1048,9 +1048,8 @@ static  int daqp_cs_attach(struct pcmcia_device *link)
     }
 
     /* Allocate space for private device-specific data */
-    local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
+    local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
     if (!local) return -ENOMEM;
-    memset(local, 0, sizeof(local_info_t));
 
     local->table_index = i;
     dev_table[i] = local;
index 9f28a58c087218da56f9c340ab3ef881b93da93e..25e4589a0a78e56ed1c81eded70375ffb271dbdc 100644 (file)
@@ -271,12 +271,11 @@ static int __unioxx5_subdev_init(comedi_subdevice* subdev, int subdev_iobase, in
        return -EIO;
   }
   
-  if((usp = (unioxx5_subd_priv*)kmalloc(sizeof(*usp), GFP_KERNEL)) == NULL) {
+  if((usp = (unioxx5_subd_priv*)kzalloc(sizeof(*usp), GFP_KERNEL)) == NULL) {
        printk(KERN_ERR "comedi%d: erorr! --> out of memory!\n", minor);
        return -1;
   }
   
-  memset(usp, 0, sizeof(*usp));
   usp->usp_iobase = subdev_iobase;
   printk("comedi%d: |", minor);
   
index e8ffdf4e7302ab556e10323102ed7cd9e7530d03..4975059e8a488ebd8c2d661e5128168ba5db644c 100644 (file)
@@ -2327,16 +2327,14 @@ static int usbduxsub_probe(struct usb_interface *uinterf,
                return PROBE_ERR_RETURN( -ENOMEM);
        }
 
-       // create space for the in buffer
-       usbduxsub[index].inBuffer=kmalloc(SIZEINBUF,GFP_KERNEL);
+       // create space for the in buffer and zero it
+       usbduxsub[index].inBuffer=kzalloc(SIZEINBUF,GFP_KERNEL);
        if (!(usbduxsub[index].inBuffer)) {
                printk("comedi_: usbdux: could not alloc space for inBuffer\n");
                tidy_up(&(usbduxsub[index]));
                up(&start_stop_sem);
                return PROBE_ERR_RETURN( -ENOMEM);
        }
-       // set the buffer to zero
-       memset(usbduxsub[index].inBuffer,0,SIZEINBUF);
 
        // create space of the instruction buffer
        usbduxsub[index].insnBuffer=kmalloc(SIZEINSNBUF,GFP_KERNEL);
@@ -2347,16 +2345,14 @@ static int usbduxsub_probe(struct usb_interface *uinterf,
                return PROBE_ERR_RETURN( -ENOMEM);
        }
 
-       // create space for the outbuffer
-       usbduxsub[index].outBuffer=kmalloc(SIZEOUTBUF,GFP_KERNEL);
+       // create space for the outbuffer and zero it
+       usbduxsub[index].outBuffer=kzalloc(SIZEOUTBUF,GFP_KERNEL);
        if (!(usbduxsub[index].outBuffer)) {
                printk("comedi_: usbdux: could not alloc space for outBuffer\n");
                tidy_up(&(usbduxsub[index]));
                up(&start_stop_sem);
                return PROBE_ERR_RETURN( -ENOMEM);
        }
-       // set the buffer to zero
-       memset(usbduxsub[index].outBuffer,0,SIZEOUTBUF);
 
 
 
index 968d0c8a15518877f4c0440dbcfd564bc6feef88..1f5c1ca58a89eef6cc89ddc3be315e19ce81a234 100644 (file)
@@ -89,10 +89,9 @@ int comedi_request_irq(unsigned irq, irqreturn_t (*handler)(int, void *
                }
        }else
        {
-               it = kmalloc(sizeof(struct comedi_irq_struct), GFP_KERNEL);
+               it = kzalloc(sizeof(struct comedi_irq_struct), GFP_KERNEL);
                if(!it)
                        return -ENOMEM;
-               memset(it, 0, sizeof(struct comedi_irq_struct));
        
                it->handler=handler;
                it->irq=irq;
index 86d24dced38e286c0a79592562ed5daa943b2926..1f45b161c58ca144accb3963a923c32481162d07 100644 (file)
@@ -417,14 +417,12 @@ struct comedi_lrange_struct{
 
 static inline int alloc_subdevices(comedi_device *dev, unsigned int num_subdevices)
 {
-       const int size = sizeof(comedi_subdevice) * num_subdevices;
        unsigned i;
 
        dev->n_subdevices = num_subdevices;
-       dev->subdevices = kmalloc(size,GFP_KERNEL);
+       dev->subdevices = kcalloc(num_subdevices,sizeof(comedi_subdevice),GFP_KERNEL);
        if(!dev->subdevices)
                return -ENOMEM;
-       memset(dev->subdevices,0,size);
        for(i = 0; i < num_subdevices; ++i)
        {
                dev->subdevices[i].device = dev;
@@ -436,10 +434,9 @@ static inline int alloc_subdevices(comedi_device *dev, unsigned int num_subdevic
 
 static inline int alloc_private(comedi_device *dev,int size)
 {
-       dev->private=kmalloc(size,GFP_KERNEL);
+       dev->private=kzalloc(size,GFP_KERNEL);
        if(!dev->private)
                return -ENOMEM;
-       memset(dev->private,0,size);
        return 0;
 }