From: Ian Abbott Date: Wed, 17 Oct 2007 15:26:59 +0000 (+0000) Subject: Replaced kmalloc/memset sequence with kzalloc or kcalloc. X-Git-Tag: r0_7_75~17 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e3f6ea54ab958527ff9cce1eade71442cb0a2d1d;p=comedi.git Replaced kmalloc/memset sequence with kzalloc or kcalloc. --- diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 7faf4e2a..4eebe26e 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -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;in_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(); diff --git a/comedi/drivers.c b/comedi/drivers.c index 059ff2a0..b773344c 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -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; diff --git a/comedi/drivers/amplc_dio200.c b/comedi/drivers/amplc_dio200.c index c5203d15..137347f7 100644 --- a/comedi/drivers/amplc_dio200.c +++ b/comedi/drivers/amplc_dio200.c @@ -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; diff --git a/comedi/drivers/cb_das16_cs.c b/comedi/drivers/cb_das16_cs.c index dbd0a0fb..a53f330e 100644 --- a/comedi/drivers/cb_das16_cs.c +++ b/comedi/drivers/cb_das16_cs.c @@ -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; diff --git a/comedi/drivers/comedi_rt_timer.c b/comedi/drivers/comedi_rt_timer.c index 40211bdd..916deff1 100644 --- a/comedi/drivers/comedi_rt_timer.c +++ b/comedi/drivers/comedi_rt_timer.c @@ -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); diff --git a/comedi/drivers/das08_cs.c b/comedi/drivers/das08_cs.c index f53032fd..db72bfea 100644 --- a/comedi/drivers/das08_cs.c +++ b/comedi/drivers/das08_cs.c @@ -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; diff --git a/comedi/drivers/dt9812.c b/comedi/drivers/dt9812.c index 700e673b..e83ebd49 100644 --- a/comedi/drivers/dt9812.c +++ b/comedi/drivers/dt9812.c @@ -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)); diff --git a/comedi/drivers/jr3_pci.c b/comedi/drivers/jr3_pci.c index cb79dcb2..95e10bf6 100644 --- a/comedi/drivers/jr3_pci.c +++ b/comedi/drivers/jr3_pci.c @@ -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, diff --git a/comedi/drivers/mite.c b/comedi/drivers/mite.c index 870db339..62a5fce6 100644 --- a/comedi/drivers/mite.c +++ b/comedi/drivers/mite.c @@ -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) diff --git a/comedi/drivers/ni_65xx.c b/comedi/drivers/ni_65xx.c index 00450497..63bfd2ec 100644 --- a/comedi/drivers/ni_65xx.c +++ b/comedi/drivers/ni_65xx.c @@ -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; } diff --git a/comedi/drivers/ni_daq_dio24.c b/comedi/drivers/ni_daq_dio24.c index 5eb614ad..bb52285b 100644 --- a/comedi/drivers/ni_daq_dio24.c +++ b/comedi/drivers/ni_daq_dio24.c @@ -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 */ diff --git a/comedi/drivers/ni_labpc_cs.c b/comedi/drivers/ni_labpc_cs.c index 4eca12c2..cc8e6329 100644 --- a/comedi/drivers/ni_labpc_cs.c +++ b/comedi/drivers/ni_labpc_cs.c @@ -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 */ diff --git a/comedi/drivers/pcmda12.c b/comedi/drivers/pcmda12.c index 8b84a41f..0f708d47 100644 --- a/comedi/drivers/pcmda12.c +++ b/comedi/drivers/pcmda12.c @@ -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]; /* diff --git a/comedi/drivers/quatech_daqp_cs.c b/comedi/drivers/quatech_daqp_cs.c index 32666486..4e9cc659 100644 --- a/comedi/drivers/quatech_daqp_cs.c +++ b/comedi/drivers/quatech_daqp_cs.c @@ -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; diff --git a/comedi/drivers/unioxx5.c b/comedi/drivers/unioxx5.c index 9f28a58c..25e4589a 100644 --- a/comedi/drivers/unioxx5.c +++ b/comedi/drivers/unioxx5.c @@ -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); diff --git a/comedi/drivers/usbdux.c b/comedi/drivers/usbdux.c index e8ffdf4e..4975059e 100644 --- a/comedi/drivers/usbdux.c +++ b/comedi/drivers/usbdux.c @@ -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); diff --git a/comedi/rt.c b/comedi/rt.c index 968d0c8a..1f5c1ca5 100644 --- a/comedi/rt.c +++ b/comedi/rt.c @@ -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; diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index 86d24dce..1f45b161 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -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; }