drivers: Conversions from kmalloc+memset to k(z|c)alloc.
Subsystems (22)
PATCH 1/1 drivers: Conversions from kmalloc+memset to k(z|c)alloc.
From: Panagiotis Issaris <[email protected]>
drivers: Conversions from kmalloc+memset to k(z|c)alloc.
---
Second edition
drivers/acpi/hotkey.c | 6 ++---- drivers/atm/zatm.c | 6 ++---- drivers/char/consolemap.c | 6 ++---- drivers/char/keyboard.c | 4 ++-- drivers/char/random.c | 6 ++---- drivers/char/sx.c | 14 +------------- drivers/char/tty_io.c | 29 ++++++---------------------- drivers/isdn/hisax/elsa_cs.c | 3 +-- drivers/isdn/hisax/hfc_usb.c | 6 ++---- drivers/isdn/hisax/sedlbauer_cs.c | 3 +-- drivers/isdn/hisax/teles_cs.c | 3 +-- drivers/isdn/hysdn/hysdn_proclog.c | 7 ++++--- drivers/isdn/i4l/isdn_v110.c | 4 ++-- drivers/macintosh/therm_windtunnel.c | 4 ++-- drivers/md/dm-mpath.c | 9 +++------ drivers/media/video/planb.c | 4 ++-- drivers/mfd/mcp-core.c | 3 +-- drivers/misc/ibmasm/module.c | 3 +-- drivers/mmc/mmc_sysfs.c | 4 +--- drivers/net/e100.c | 4 ++-- drivers/net/loopback.c | 3 +-- drivers/net/pcmcia/ibmtr_cs.c | 3 +-- drivers/net/wireless/hostap/hostap_ioctl.c | 12 +++--------- drivers/nubus/nubus.c | 8 ++++---- drivers/parport/parport_cs.c | 3 +-- drivers/rapidio/rio-scan.c | 6 ++---- drivers/scsi/ide-scsi.c | 16 +++++++-------- drivers/scsi/megaraid.c | 10 +++++++--- drivers/scsi/pcmcia/aha152x_stub.c | 3 +-- drivers/scsi/pcmcia/nsp_cs.c | 3 +-- drivers/scsi/sata_mv.c | 9 +++------ drivers/scsi/sata_qstor.c | 3 +-- drivers/scsi/sata_svw.c | 3 +-- drivers/scsi/sata_sx4.c | 9 +++------ drivers/scsi/sata_via.c | 3 +-- drivers/scsi/sata_vsc.c | 3 +-- drivers/serial/ip22zilog.c | 17 ++-------------- drivers/serial/serial_core.c | 7 ++----- drivers/usb/host/ohci-hcd.c | 3 +-- drivers/usb/host/sl811_cs.c | 3 +-- drivers/usb/serial/ark3116.c | 3 +-- drivers/usb/serial/console.c | 6 ++---- drivers/usb/serial/ti_usb_3410_5052.c | 5 ++--- drivers/video/amba-clcd.c | 3 +-- drivers/video/aty/atyfb_base.c | 3 +-- drivers/video/au1100fb.c | 9 ++++----- drivers/video/au1200fb.c | 3 +-- drivers/video/clps711xfb.c | 3 +-- drivers/video/controlfb.c | 3 +-- drivers/video/cyber2000fb.c | 4 +--- drivers/video/i810/i810_main.c | 4 ++-- drivers/video/igafb.c | 7 ++----- drivers/video/intelfb/intelfbdrv.c | 3 +-- drivers/video/matrox/matroxfb_crtc2.c | 3 +-- drivers/video/nvidia/nvidia.c | 4 +--- drivers/video/offb.c | 5 ++--- drivers/video/pvr2fb.c | 4 +--- drivers/video/pxafb.c | 3 +-- drivers/video/retz3fb.c | 5 ++--- drivers/video/riva/fbdev.c | 3 +-- drivers/video/sa1100fb.c | 3 +-- drivers/video/savage/savagefb_driver.c | 3 +-- drivers/video/sis/sis_main.c | 3 +-- drivers/video/sun3fb.c | 3 +-- drivers/video/tgafb.c | 3 +-- drivers/video/valkyriefb.c | 3 +-- 66 files changed, 119 insertions(+), 237 deletions(-)
drivers/acpi/hotkey.c +2 -4
@@ -246,10 +246,8 @@ static char *format_result(union acpi_ob {char *buf =NULL ; - buf = (char *)kmalloc (RESULT_STR_LEN ,GFP_KERNEL ); -if (buf) -memset (buf,0 ,RESULT_STR_LEN ); -else + buf =kzalloc (RESULT_STR_LEN ,GFP_KERNEL ); +if (!buf) goto do_fail;/* Now, just support integer type */
drivers/atm/zatm.c +2 -4
@@ -603,9 +603,8 @@ static int start_rx(struct atm_dev *dev)DPRINTK ("start_rx\n" ); zatm_dev =ZATM_DEV (dev); size =sizeof (struct atm_vcc *)*zatm_dev->chans; - zatm_dev->rx_map = (struct atm_vcc **)kmalloc (size,GFP_KERNEL ); + zatm_dev->rx_map =kzalloc (size,GFP_KERNEL );if (!zatm_dev->rx_map)return -ENOMEM ; -memset (zatm_dev->rx_map,0 ,size);/* set VPI/VCI split (use all VCIs and give what's left to VPIs) */ zpokel (zatm_dev,(1 << dev->ci_range.vci_bits)-1 ,uPD98401_VRR);/* prepare free buffer pools */
@@ -951,9 +950,8 @@ static int open_tx_first(struct atm_vccskb_queue_head_init (&zatm_vcc->tx_queue);init_waitqueue_head (&zatm_vcc->tx_wait);/* initialize ring */ - zatm_vcc->ring =kmalloc (RING_SIZE ,GFP_KERNEL ); + zatm_vcc->ring =kzalloc (RING_SIZE ,GFP_KERNEL );if (!zatm_vcc->ring)return -ENOMEM ; -memset (zatm_vcc->ring,0 ,RING_SIZE ); loop = zatm_vcc->ring+RING_ENTRIES *RING_WORDS ; loop[0 ] = uPD98401_TXPD_V; loop[1 ] = loop[2 ] =0 ;
drivers/char/consolemap.c +2 -4
@@ -192,8 +192,7 @@ static void set_inverse_transl(struct vc q = p->inverse_translations[i];if (!q) { - q = p->inverse_translations[i] = (unsigned char *) -kmalloc (MAX_GLYPH ,GFP_KERNEL ); + q = p->inverse_translations[i] =kmalloc (MAX_GLYPH ,GFP_KERNEL );if (!q)return ; }memset (q,0 ,MAX_GLYPH );
@@ -443,12 +442,11 @@ int con_clear_unimap(struct vc_data *vc, p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;if (p && p->readonly)return -EIO ;if (!p || --p->refcount) { - q = (struct uni_pagedir *)kmalloc (sizeof (*p),GFP_KERNEL ); + q =kzalloc (sizeof (*p),GFP_KERNEL );if (!q) {if (p) p->refcount++;return -ENOMEM ; } -memset (q,0 ,sizeof (*q)); q->refcount=1 ; *vc->vc_uni_pagedir_loc = (unsigned long )q; }else {
drivers/char/keyboard.c +2 -2
@@ -1298,9 +1298,9 @@ static struct input_handle *kbd_connect(if (i ==BTN_MISC && !test_bit (EV_SND , dev->evbit))return NULL ; -if (!(handle =kmalloc (sizeof (struct input_handle ),GFP_KERNEL ))) + handle =kzalloc (sizeof (struct input_handle ),GFP_KERNEL ); +if (!handle)return NULL ; -memset (handle,0 ,sizeof (struct input_handle )); handle->dev = dev; handle->handler = handler;
drivers/char/random.c +2 -4
@@ -911,9 +911,8 @@ void rand_initialize_irq(int irq)* If kmalloc returns null, we just won't use that entropy * source. */ - state =kmalloc (sizeof (struct timer_rand_state ),GFP_KERNEL ); + state =kzalloc (sizeof (struct timer_rand_state ),GFP_KERNEL );if (state) { -memset (state,0 ,sizeof (struct timer_rand_state )); irq_timer_state[irq] = state; } }
@@ -926,9 +925,8 @@ void rand_initialize_disk(struct gendisk* If kmalloc returns null, we just won't use that entropy * source. */ - state =kmalloc (sizeof (struct timer_rand_state ),GFP_KERNEL ); + state =kzalloc (sizeof (struct timer_rand_state ),GFP_KERNEL );if (state) { -memset (state,0 ,sizeof (struct timer_rand_state )); disk->random = state; } }
drivers/char/sx.c +1 -13
@@ -2278,18 +2278,6 @@ static int sx_init_drivers(void)return 0 ; } - -static void *ckmalloc (int size) -{ -void *p; - - p =kmalloc (size,GFP_KERNEL ); -if (p) -memset (p,0 , size); -return p; -} - -static int sx_init_portstructs (int nboards,int nports) {struct sx_board *board;
@@ -2302,7 +2290,7 @@ static int sx_init_portstructs (int nboa/* Many drivers statically allocate the maximum number of ports There is no reason not to allocate them dynamically. Is there? -- REW */ - sx_ports =ckmalloc (nports *sizeof (struct sx_port )); + sx_ports =kcalloc (nports,sizeof (struct sx_port ),GFP_KERNEL );if (!sx_ports)return -ENOMEM ;
drivers/char/tty_io.c +6 -23
@@ -153,17 +153,6 @@ int tty_ioctl(struct inode * inode, strustatic int tty_fasync (int fd,struct file * filp,int on);static void release_mem (struct tty_struct *tty,int idx); - -static struct tty_struct *alloc_tty_struct (void ) -{ -struct tty_struct *tty; - - tty =kmalloc (sizeof (struct tty_struct ),GFP_KERNEL ); -if (tty) -memset (tty,0 ,sizeof (struct tty_struct )); -return tty; -} -static void tty_buffer_free_all (struct tty_struct *);static inline void free_tty_struct (struct tty_struct *tty)
@@ -1477,7 +1466,7 @@ static int init_dev(struct tty_driver *d tp = o_tp =NULL ; ltp = o_ltp =NULL ; - tty =alloc_tty_struct (); + tty =kzalloc (sizeof (struct tty_struct ),GFP_KERNEL );if (!tty) goto fail_no_mem;initialize_tty_struct (tty);
@@ -1502,15 +1491,13 @@ static int init_dev(struct tty_driver *d }if (!*ltp_loc) { - ltp = (struct termios *)kmalloc (sizeof (struct termios ), -GFP_KERNEL ); + ltp =kzalloc (sizeof (struct termios ),GFP_KERNEL );if (!ltp) goto free_mem_out; -memset (ltp,0 ,sizeof (struct termios )); }if (driver->type ==TTY_DRIVER_TYPE_PTY ) { - o_tty =alloc_tty_struct (); + o_tty =kzalloc (sizeof (struct tty_struct ),GFP_KERNEL );if (!o_tty) goto free_mem_out;initialize_tty_struct (o_tty);
@@ -1535,11 +1522,9 @@ static int init_dev(struct tty_driver *d }if (!*o_ltp_loc) { - o_ltp = (struct termios *) -kmalloc (sizeof (struct termios ),GFP_KERNEL ); + o_ltp =kzalloc (sizeof (struct termios ),GFP_KERNEL );if (!o_ltp) goto free_mem_out; -memset (o_ltp,0 ,sizeof (struct termios )); }/*
@@ -2996,9 +2981,8 @@ struct tty_driver *alloc_tty_driver(int {struct tty_driver *driver; - driver =kmalloc (sizeof (struct tty_driver ),GFP_KERNEL ); + driver =kzalloc (sizeof (struct tty_driver ),GFP_KERNEL );if (driver) { -memset (driver,0 ,sizeof (struct tty_driver )); driver->magic =TTY_DRIVER_MAGIC ; driver->num = lines;/* later we'll move allocation of tables here */
@@ -3057,10 +3041,9 @@ int tty_register_driver(struct tty_drivereturn 0 ;if (!(driver->flags &TTY_DRIVER_DEVPTS_MEM )) { - p =kmalloc (driver->num *3 *sizeof (void *),GFP_KERNEL ); + p =kcalloc (driver->num *3 ,sizeof (void *),GFP_KERNEL );if (!p)return -ENOMEM ; -memset (p,0 , driver->num *3 *sizeof (void *)); }if (!driver->major) {
drivers/isdn/hisax/elsa_cs.c +1 -2
@@ -146,9 +146,8 @@ static int elsa_cs_probe(struct pcmcia_dDEBUG (0 ,"elsa_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->p_dev = link; link->priv = local;
drivers/isdn/hisax/hfc_usb.c +2 -4
@@ -1479,11 +1479,9 @@ #endif/* found a valid USB Ta Endpint config */ if (small_match !=0xffff ) { iface = iface_used; -if (! - (context = -kmalloc (sizeof (hfcusb_data),GFP_KERNEL ))) + context =kzalloc (sizeof (hfcusb_data),GFP_KERNEL ); +if (!context)return (-ENOMEM );/* got no mem */ -memset (context,0 ,sizeof (hfcusb_data)); ep = iface->endpoint; vcf = validconf[small_match];
drivers/isdn/hisax/sedlbauer_cs.c +1 -2
@@ -155,9 +155,8 @@ static int sedlbauer_probe(struct pcmciaDEBUG (0 ,"sedlbauer_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->cardnr =-1 ; local->p_dev = link;
drivers/isdn/hisax/teles_cs.c +1 -2
@@ -137,9 +137,8 @@ static int teles_probe(struct pcmcia_devDEBUG (0 ,"teles_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->cardnr =-1 ; local->p_dev = link;
drivers/isdn/hysdn/hysdn_proclog.c +4 -3
@@ -111,7 +111,8 @@ put_log_buffer(hysdn_card * card, char *if (pd->if_used <=0 )return ;/* no open file for read */ -if (!(ib = (struct log_data *)kmalloc (sizeof (struct log_data ) +strlen (cp),GFP_ATOMIC ))) + ib =kmalloc (sizeof (struct log_data ) +strlen (cp),GFP_ATOMIC ); +if (!ib)return ;/* no memory */ strcpy (ib->log_start, cp);/* set output string */ ib->next =NULL ;
@@ -408,8 +409,8 @@ hysdn_proclog_init(hysdn_card * card)/* create a cardlog proc entry */ -if ((pd = (struct procdata *)kmalloc (sizeof (struct procdata ),GFP_KERNEL )) !=NULL ) { -memset (pd,0 ,sizeof (struct procdata )); + pd =kzalloc (sizeof (struct procdata ),GFP_KERNEL ); +if (pd) {sprintf (pd->log_name,"%s%d" ,PROC_LOG_BASENAME , card->myid);if ((pd->log =create_proc_entry (pd->log_name,S_IFREG |S_IRUGO |S_IWUSR , hysdn_proc_entry)) !=NULL ) { pd->log->proc_fops = &log_fops;
drivers/isdn/i4l/isdn_v110.c +2 -2
@@ -92,9 +92,9 @@ isdn_v110_open(unsigned char key, int hdint i;isdn_v110_stream *v; -if ((v =kmalloc (sizeof (isdn_v110_stream),GFP_ATOMIC )) ==NULL ) + v =kzalloc (sizeof (isdn_v110_stream),GFP_ATOMIC ); +if (!v)return NULL ; -memset (v,0 ,sizeof (isdn_v110_stream)); v->key = key; v->nbits =0 ;for (i =0 ; key & (1 << i); i++)
drivers/macintosh/therm_windtunnel.c +2 -2
@@ -430,9 +430,9 @@ do_probe( struct i2c_adapter *adapter, i | I2C_FUNC_SMBUS_WRITE_BYTE) )return 0 ; -if ( !(cl=kmalloc (sizeof (*cl),GFP_KERNEL )) ) + cl =kzalloc (sizeof (*cl),GFP_KERNEL ); +if ( !cl )return -ENOMEM ; -memset ( cl,0 ,sizeof (struct i2c_client ) ); cl->addr = addr; cl->adapter = adapter;
drivers/md/dm-mpath.c +3 -6
@@ -114,10 +114,9 @@ static void trigger_event(void *data);static struct pgpath *alloc_pgpath (void ) { -struct pgpath *pgpath =kmalloc (sizeof (*pgpath),GFP_KERNEL ); +struct pgpath *pgpath =kzalloc (sizeof (*pgpath),GFP_KERNEL );if (pgpath) { -memset (pgpath,0 ,sizeof (*pgpath)); pgpath->path.is_active =1 ; }
@@ -133,11 +132,10 @@ static struct priority_group *alloc_prio {struct priority_group *pg; - pg =kmalloc (sizeof (*pg),GFP_KERNEL ); + pg =kzalloc (sizeof (*pg),GFP_KERNEL );if (!pg)return NULL ; -memset (pg,0 ,sizeof (*pg));INIT_LIST_HEAD (&pg->pgpaths);return pg;
@@ -172,9 +170,8 @@ static struct multipath *alloc_multipath {struct multipath *m; - m =kmalloc (sizeof (*m),GFP_KERNEL ); + m =kzalloc (sizeof (*m),GFP_KERNEL );if (m) { -memset (m,0 ,sizeof (*m));INIT_LIST_HEAD (&m->priority_groups);spin_lock_init (&m->lock); m->queue_io =1 ;
drivers/media/video/planb.c +2 -2
@@ -353,9 +353,9 @@ static int planb_prepare_open(struct pla * PLANB_DUMMY)*sizeof(struct dbdma_cmd) +(PLANB_MAXLINES *((PLANB_MAXPIXELS +7 )& ~7 ))/8 +MAX_GBUFFERS *sizeof (unsigned int ); -if ((pb->priv_space =kmalloc (size,GFP_KERNEL )) ==0 ) + pb->priv_space =kzalloc (size,GFP_KERNEL ); +if (!pb->priv_space)return -ENOMEM ; -memset ((void *) pb->priv_space,0 , size); pb->overlay_last1 = pb->ch1_cmd = (volatile struct dbdma_cmd *)DBDMA_ALIGN (pb->priv_space); pb->overlay_last2 = pb->ch2_cmd = pb->ch1_cmd + pb->tab_size;
drivers/mfd/mcp-core.c +1 -2
@@ -200,9 +200,8 @@ struct mcp *mcp_host_alloc(struct device {struct mcp *mcp; - mcp =kmalloc (sizeof (struct mcp ) + size,GFP_KERNEL ); + mcp =kzalloc (sizeof (struct mcp ) + size,GFP_KERNEL );if (mcp) { -memset (mcp,0 ,sizeof (struct mcp ) + size);spin_lock_init (&mcp->lock); mcp->attached_device.parent = parent; mcp->attached_device.bus = &mcp_bus_type;
drivers/misc/ibmasm/module.c +1 -2
@@ -77,13 +77,12 @@ static int __devinit ibmasm_init_one(str/* vnc client won't work without bus-mastering */ pci_set_master (pdev); - sp =kmalloc (sizeof (struct service_processor ),GFP_KERNEL ); + sp =kzalloc (sizeof (struct service_processor ),GFP_KERNEL );if (sp ==NULL ) {dev_err (&pdev->dev,"Failed to allocate memory\n" ); result = -ENOMEM ; goto error_kmalloc; } -memset (sp,0 ,sizeof (struct service_processor ));spin_lock_init (&sp->lock);INIT_LIST_HEAD (&sp->command_queue);
drivers/mmc/mmc_sysfs.c +1 -3
@@ -262,10 +262,8 @@ struct mmc_host *mmc_alloc_host_sysfs(in {struct mmc_host *host; - host =kmalloc (sizeof (struct mmc_host ) + extra,GFP_KERNEL ); + host =kzalloc (sizeof (struct mmc_host ) + extra,GFP_KERNEL );if (host) { -memset (host,0 ,sizeof (struct mmc_host ) + extra); - host->dev = dev; host->class_dev.dev = host->dev; host->class_dev.class = &mmc_host_class;
drivers/net/e100.c +2 -2
@@ -1930,9 +1930,9 @@ static int e100_rx_alloc_list(struct nic nic->rx_to_use = nic->rx_to_clean =NULL ; nic->ru_running =RU_UNINITIALIZED ; -if (!(nic->rxs =kmalloc (sizeof (struct rx ) * count,GFP_ATOMIC ))) + nic->rxs =kcalloc (count,sizeof (struct rx ),GFP_ATOMIC ); +if (!nic->rxs)return -ENOMEM ; -memset (nic->rxs,0 ,sizeof (struct rx ) * count);for (rx = nic->rxs, i =0 ; i < count; rx++, i++) { rx->next = (i +1 < count) ? rx +1 : nic->rxs;
drivers/net/loopback.c +1 -2
@@ -224,9 +224,8 @@ int __init loopback_init(void)struct net_device_stats *stats;/* Can survive without statistics */ - stats =kmalloc (sizeof (struct net_device_stats ),GFP_KERNEL ); + stats =kzalloc (sizeof (struct net_device_stats ),GFP_KERNEL );if (stats) { -memset (stats,0 ,sizeof (struct net_device_stats )); loopback_dev.priv = stats; loopback_dev.get_stats = &get_stats; }
drivers/net/pcmcia/ibmtr_cs.c +1 -2
@@ -146,9 +146,8 @@ static int ibmtr_attach(struct pcmcia_deDEBUG (0 ,"ibmtr_attach()\n" );/* Create new token-ring device */ - info =kmalloc (sizeof (*info),GFP_KERNEL ); + info =kzalloc (sizeof (*info),GFP_KERNEL );if (!info)return -ENOMEM ; -memset (info,0 ,sizeof (*info)); dev =alloc_trdev (sizeof (struct tok_info ));if (!dev) {kfree (info);
drivers/net/wireless/hostap/hostap_ioctl.c +3 -9
@@ -181,12 +181,10 @@ static int prism2_ioctl_siwencode(structstruct ieee80211_crypt_data *new_crypt;/* take WEP into use */ - new_crypt = (struct ieee80211_crypt_data *) -kmalloc (sizeof (struct ieee80211_crypt_data ), + new_crypt =kzalloc (sizeof (struct ieee80211_crypt_data ),GFP_KERNEL );if (new_crypt ==NULL )return -ENOMEM ; -memset (new_crypt,0 ,sizeof (struct ieee80211_crypt_data )); new_crypt->ops =ieee80211_get_crypto_ops ("WEP" );if (!new_crypt->ops) {request_module ("ieee80211_crypt_wep" );
@@ -3320,14 +3318,12 @@ static int prism2_ioctl_siwencodeext(strprism2_crypt_delayed_deinit (local, crypt); - new_crypt = (struct ieee80211_crypt_data *) -kmalloc (sizeof (struct ieee80211_crypt_data ), + new_crypt =kzalloc (sizeof (struct ieee80211_crypt_data ),GFP_KERNEL );if (new_crypt ==NULL ) { ret = -ENOMEM ; goto done; } -memset (new_crypt,0 ,sizeof (struct ieee80211_crypt_data )); new_crypt->ops = ops; new_crypt->priv = new_crypt->ops->init (i);if (new_crypt->priv ==NULL ) {
@@ -3538,14 +3534,12 @@ static int prism2_ioctl_set_encryption(lprism2_crypt_delayed_deinit (local, crypt); - new_crypt = (struct ieee80211_crypt_data *) -kmalloc (sizeof (struct ieee80211_crypt_data ), + new_crypt =kzalloc (sizeof (struct ieee80211_crypt_data ),GFP_KERNEL );if (new_crypt ==NULL ) { ret = -ENOMEM ; goto done; } -memset (new_crypt,0 ,sizeof (struct ieee80211_crypt_data )); new_crypt->ops = ops; new_crypt->priv = new_crypt->ops->init (param->u.crypt.idx);if (new_crypt->priv ==NULL ) {
drivers/nubus/nubus.c +4 -4
@@ -466,9 +466,9 @@ static struct nubus_dev* __init parent->base, dir.base);/* Actually we should probably panic if this fails */ -if ((dev =kmalloc (sizeof (*dev),GFP_ATOMIC )) ==NULL ) + dev =kzalloc (sizeof (*dev),GFP_ATOMIC ); +if (!dev)return NULL ; -memset (dev,0 ,sizeof (*dev)); dev->resid = parent->type; dev->directory = dir.base; dev->board = board;
@@ -800,9 +800,9 @@ static struct nubus_board* __init nubus_nubus_rewind (&rp,FORMAT_BLOCK_SIZE , bytelanes);/* Actually we should probably panic if this fails */ -if ((board =kmalloc (sizeof (*board),GFP_ATOMIC )) ==NULL ) + board =kzalloc (sizeof (*board),GFP_ATOMIC ); +if (!board)return NULL ; -memset (board,0 ,sizeof (*board)); board->fblock = rp;/* Dump the format block for debugging purposes */
drivers/parport/parport_cs.c +1 -2
@@ -106,9 +106,8 @@ static int parport_probe(struct pcmcia_dDEBUG (0 ,"parport_attach()\n" );/* Create new parport device */ - info =kmalloc (sizeof (*info),GFP_KERNEL ); + info =kzalloc (sizeof (*info),GFP_KERNEL );if (!info)return -ENOMEM ; -memset (info,0 ,sizeof (*info)); link->priv = info; info->p_dev = link;
drivers/rapidio/rio-scan.c +2 -4
@@ -297,11 +297,10 @@ static struct rio_dev *rio_setup_device(struct rio_switch *rswitch;int result, rdid; - rdev =kmalloc (sizeof (struct rio_dev ),GFP_KERNEL ); + rdev =kzalloc (sizeof (struct rio_dev ),GFP_KERNEL );if (!rdev) goto out; -memset (rdev,0 ,sizeof (struct rio_dev )); rdev->net = net;rio_mport_read_config_32 (port, destid, hopcount,RIO_DEV_ID_CAR , &result);
@@ -784,9 +783,8 @@ static struct rio_net __devinit *rio_all {struct rio_net *net; - net =kmalloc (sizeof (struct rio_net ),GFP_KERNEL ); + net =kzalloc (sizeof (struct rio_net ),GFP_KERNEL );if (net) { -memset (net,0 ,sizeof (struct rio_net ));INIT_LIST_HEAD (&net->node);INIT_LIST_HEAD (&net->devices);INIT_LIST_HEAD (&net->mports);
drivers/scsi/ide-scsi.c +7 -9
@@ -259,9 +259,9 @@ static inline void idescsi_transform_pc1unsigned short new_len;if (!scsi_buf)return ; -if ((atapi_buf =kmalloc (pc->buffer_size +4 ,GFP_ATOMIC )) ==NULL ) + atapi_buf =kzalloc (pc->buffer_size +4 ,GFP_ATOMIC ); +if (!atapi_buf)return ; -memset (atapi_buf,0 , pc->buffer_size +4 );memset (c,0 ,12 ); c[0 ] = sc[0 ] |0x40 ; c[1 ] = sc[1 ];
@@ -327,17 +327,15 @@ static int idescsi_check_condition(ide_du8 *buf;/* stuff a sense request in front of our current request */ - pc =kmalloc (sizeof (idescsi_pc_t),GFP_ATOMIC ); - rq =kmalloc (sizeof (struct request ),GFP_ATOMIC ); - buf =kmalloc (SCSI_SENSE_BUFFERSIZE ,GFP_ATOMIC ); + pc =kzalloc (sizeof (*pc),GFP_ATOMIC ); + rq =kmalloc (sizeof (*rq),GFP_ATOMIC ); + buf =kzalloc (SCSI_SENSE_BUFFERSIZE ,GFP_ATOMIC );if (pc ==NULL || rq ==NULL || buf ==NULL ) {kfree (buf);kfree (rq);kfree (pc);return -ENOMEM ; } -memset (pc,0 ,sizeof (idescsi_pc_t)); -memset (buf,0 ,SCSI_SENSE_BUFFERSIZE );ide_init_drive_cmd (rq); rq->special = (char *) pc; pc->rq = rq;
@@ -899,8 +897,8 @@ static int idescsi_queue (struct scsi_cm goto abort; } scsi =drive_to_idescsi (drive); - pc =kmalloc (sizeof (idescsi_pc_t),GFP_ATOMIC ); - rq =kmalloc (sizeof (struct request ),GFP_ATOMIC ); + pc =kmalloc (sizeof (*pc),GFP_ATOMIC ); + rq =kmalloc (sizeof (*rq),GFP_ATOMIC );if (rq ==NULL || pc ==NULL ) {printk (KERN_ERR "ide-scsi: %s: out of memory\n" , drive->name); goto abort;
drivers/scsi/megaraid.c +7 -3
@@ -4487,8 +4487,12 @@ mega_internal_command(adapter_t *adapter scmd = &adapter->int_scmd;memset (scmd,0 ,sizeof (Scsi_Cmnd)); - sdev =kmalloc (sizeof (struct scsi_device ),GFP_KERNEL ); -memset (sdev,0 ,sizeof (struct scsi_device )); + sdev =kzalloc (sizeof (struct scsi_device ),GFP_KERNEL ); +if (!sdev) { + rval = -ENOMEM ; +printk (KERN_ERR "megaraid: memory allocation failed\n" ); + goto out; + } scmd->device = sdev; scmd->device->host = adapter->host;
@@ -4526,7 +4530,7 @@ mega_internal_command(adapter_t *adapterprintk ("megaraid: cmd [%x, %x, %x] status:[%x]\n" , mc->cmd, mc->opcode, mc->subopcode, scmd->result); } - +out:mutex_unlock (&adapter->int_mtx);return rval;
drivers/scsi/pcmcia/aha152x_stub.c +1 -2
@@ -107,9 +107,8 @@ static int aha152x_probe(struct pcmcia_dDEBUG (0 ,"aha152x_attach()\n" );/* Create new SCSI device */ - info =kmalloc (sizeof (*info),GFP_KERNEL ); + info =kzalloc (sizeof (*info),GFP_KERNEL );if (!info)return -ENOMEM ; -memset (info,0 ,sizeof (*info)); info->p_dev = link; link->priv = info;
drivers/scsi/pcmcia/nsp_cs.c +1 -2
@@ -1602,9 +1602,8 @@ static int nsp_cs_probe(struct pcmcia_densp_dbg (NSP_DEBUG_INIT ,"in" );/* Create new SCSI device */ - info =kmalloc (sizeof (*info),GFP_KERNEL ); + info =kzalloc (sizeof (*info),GFP_KERNEL );if (info ==NULL ) {return -ENOMEM ; } -memset (info,0 ,sizeof (*info)); info->p_dev = link; link->priv = info; data->ScsiInfo = info;
drivers/scsi/sata_mv.c +3 -6
@@ -883,10 +883,9 @@ static int mv_port_start(struct ata_portdma_addr_t mem_dma;int rc = -ENOMEM ; - pp =kmalloc (sizeof (*pp),GFP_KERNEL ); + pp =kzalloc (sizeof (*pp),GFP_KERNEL );if (!pp) goto err_out; -memset (pp,0 ,sizeof (*pp)); mem =dma_alloc_coherent (dev,MV_PORT_PRIV_DMA_SZ , &mem_dma,GFP_KERNEL );
@@ -2365,13 +2364,12 @@ static int mv_init_one(struct pci_dev *p goto err_out; } - probe_ent =kmalloc (sizeof (*probe_ent),GFP_KERNEL ); + probe_ent =kzalloc (sizeof (*probe_ent),GFP_KERNEL );if (probe_ent ==NULL ) { rc = -ENOMEM ; goto err_out_regions; } -memset (probe_ent,0 ,sizeof (*probe_ent)); probe_ent->dev =pci_dev_to_dev (pdev);INIT_LIST_HEAD (&probe_ent->node);
@@ -2381,12 +2379,11 @@ static int mv_init_one(struct pci_dev *p goto err_out_free_ent; } - hpriv =kmalloc (sizeof (*hpriv),GFP_KERNEL ); + hpriv =kzalloc (sizeof (*hpriv),GFP_KERNEL );if (!hpriv) { rc = -ENOMEM ; goto err_out_iounmap; } -memset (hpriv,0 ,sizeof (*hpriv)); probe_ent->sht = mv_port_info[board_idx].sht; probe_ent->host_flags = mv_port_info[board_idx].host_flags;
drivers/scsi/sata_qstor.c +1 -2
@@ -662,13 +662,12 @@ static int qs_ata_init_one(struct pci_deif (rc) goto err_out_iounmap; - probe_ent =kmalloc (sizeof (*probe_ent),GFP_KERNEL ); + probe_ent =kzalloc (sizeof (*probe_ent),GFP_KERNEL );if (probe_ent ==NULL ) { rc = -ENOMEM ; goto err_out_iounmap; } -memset (probe_ent,0 ,sizeof (*probe_ent)); probe_ent->dev =pci_dev_to_dev (pdev);INIT_LIST_HEAD (&probe_ent->node);
drivers/scsi/sata_svw.c +1 -2
@@ -394,13 +394,12 @@ static int k2_sata_init_one (struct pci_if (rc) goto err_out_regions; - probe_ent =kmalloc (sizeof (*probe_ent),GFP_KERNEL ); + probe_ent =kzalloc (sizeof (*probe_ent),GFP_KERNEL );if (probe_ent ==NULL ) { rc = -ENOMEM ; goto err_out_regions; } -memset (probe_ent,0 ,sizeof (*probe_ent)); probe_ent->dev =pci_dev_to_dev (pdev);INIT_LIST_HEAD (&probe_ent->node);
drivers/scsi/sata_sx4.c +3 -6
@@ -266,12 +266,11 @@ static int pdc_port_start(struct ata_porif (rc)return rc; - pp =kmalloc (sizeof (*pp),GFP_KERNEL ); + pp =kzalloc (sizeof (*pp),GFP_KERNEL );if (!pp) { rc = -ENOMEM ; goto err_out; } -memset (pp,0 ,sizeof (*pp)); pp->pkt =dma_alloc_coherent (dev,128 , &pp->pkt_dma,GFP_KERNEL );if (!pp->pkt) {
@@ -1395,13 +1394,12 @@ static int pdc_sata_init_one (struct pciif (rc) goto err_out_regions; - probe_ent =kmalloc (sizeof (*probe_ent),GFP_KERNEL ); + probe_ent =kzalloc (sizeof (*probe_ent),GFP_KERNEL );if (probe_ent ==NULL ) { rc = -ENOMEM ; goto err_out_regions; } -memset (probe_ent,0 ,sizeof (*probe_ent)); probe_ent->dev =pci_dev_to_dev (pdev);INIT_LIST_HEAD (&probe_ent->node);
@@ -1412,12 +1410,11 @@ static int pdc_sata_init_one (struct pci } base = (unsigned long ) mmio_base; - hpriv =kmalloc (sizeof (*hpriv),GFP_KERNEL ); + hpriv =kzalloc (sizeof (*hpriv),GFP_KERNEL );if (!hpriv) { rc = -ENOMEM ; goto err_out_iounmap; } -memset (hpriv,0 ,sizeof (*hpriv)); dimm_mmio =pci_iomap (pdev,4 ,0 );if (!dimm_mmio) {
drivers/scsi/sata_via.c +1 -2
@@ -229,11 +229,10 @@ static struct ata_probe_ent *vt6421_initstruct ata_probe_ent *probe_ent;unsigned int i; - probe_ent =kmalloc (sizeof (*probe_ent),GFP_KERNEL ); + probe_ent =kzalloc (sizeof (*probe_ent),GFP_KERNEL );if (!probe_ent)return NULL ; -memset (probe_ent,0 ,sizeof (*probe_ent)); probe_ent->dev =pci_dev_to_dev (pdev);INIT_LIST_HEAD (&probe_ent->node);
drivers/scsi/sata_vsc.c +1 -2
@@ -373,12 +373,11 @@ static int __devinit vsc_sata_init_one (if (rc) goto err_out_regions; - probe_ent =kmalloc (sizeof (*probe_ent),GFP_KERNEL ); + probe_ent =kzalloc (sizeof (*probe_ent),GFP_KERNEL );if (probe_ent ==NULL ) { rc = -ENOMEM ; goto err_out_regions; } -memset (probe_ent,0 ,sizeof (*probe_ent)); probe_ent->dev =pci_dev_to_dev (pdev);INIT_LIST_HEAD (&probe_ent->node);
drivers/serial/ip22zilog.c +2 -15
@@ -922,23 +922,10 @@ static struct zilog_layout **ip22zilog_cstatic struct uart_ip22zilog_port *ip22zilog_irq_chain;static int zilog_irq =-1 ; -static void *__init alloc_one_table (unsigned long size) -{ -void *ret; - - ret =kmalloc (size,GFP_KERNEL ); -if (ret !=NULL ) -memset (ret,0 , size); - -return ret; -} -static void __init ip22zilog_alloc_tables (void ) { - ip22zilog_port_table = (struct uart_ip22zilog_port *) -alloc_one_table (NUM_CHANNELS *sizeof (struct uart_ip22zilog_port )); - ip22zilog_chip_regs = (struct zilog_layout **) -alloc_one_table (NUM_IP22ZILOG *sizeof (struct zilog_layout *)); + ip22zilog_port_table =kcalloc (NUM_CHANNELS ,sizeof (struct uart_ip22zilog_port ),GFP_KERNEL ); + ip22zilog_chip_regs =kcalloc (NUM_IP22ZILOG ,sizeof (struct zilog_layout *),GFP_KERNEL );if (ip22zilog_port_table ==NULL || ip22zilog_chip_regs ==NULL ) {panic ("IP22-Zilog: Cannot allocate IP22-Zilog tables." );
drivers/serial/serial_core.c +2 -5
@@ -1522,9 +1522,8 @@ static struct uart_state *uart_get(struc }if (!state->info) { - state->info =kmalloc (sizeof (struct uart_info ),GFP_KERNEL ); + state->info =kzalloc (sizeof (struct uart_info ),GFP_KERNEL );if (state->info) { -memset (state->info,0 ,sizeof (struct uart_info ));init_waitqueue_head (&state->info->open_wait);init_waitqueue_head (&state->info->delta_msr_wait);
@@ -2147,13 +2146,11 @@ int uart_register_driver(struct uart_dri* Maybe we should be using a slab cache for this, especially if * we have a large number of ports to handle. */ - drv->state =kmalloc (sizeof (struct uart_state ) * drv->nr,GFP_KERNEL ); + drv->state =kcalloc (drv->nr,sizeof (struct uart_state ),GFP_KERNEL ); retval = -ENOMEM ;if (!drv->state) goto out; -memset (drv->state,0 ,sizeof (struct uart_state ) * drv->nr); - normal =alloc_tty_driver (drv->nr);if (!normal) goto out;
drivers/usb/host/ohci-hcd.c +1 -2
@@ -223,11 +223,10 @@ #endif }/* allocate the private part of the URB */ - urb_priv =kmalloc (sizeof (urb_priv_t) + size *sizeof (struct td *), + urb_priv =kzalloc (sizeof (urb_priv_t) + size *sizeof (struct td *), mem_flags);if (!urb_priv)return -ENOMEM ; -memset (urb_priv,0 ,sizeof (urb_priv_t) + size *sizeof (struct td *));INIT_LIST_HEAD (&urb_priv->pending); urb_priv->length = size; urb_priv->ed = ed;
drivers/usb/host/sl811_cs.c +1 -2
@@ -286,10 +286,9 @@ static int sl811_cs_probe(struct pcmcia_ {local_info_t *local; - 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->p_dev = link; link->priv = local;
drivers/usb/serial/ark3116.c +1 -2
@@ -84,10 +84,9 @@ static int ark3116_attach(struct usb_serint i;for (i =0 ; i < serial->num_ports; ++i) { - priv =kmalloc (sizeof (struct ark3116_private ),GFP_KERNEL ); + priv =kzalloc (sizeof (struct ark3116_private ),GFP_KERNEL );if (!priv) goto cleanup; -memset (priv,0x00 ,sizeof (struct ark3116_private ));spin_lock_init (&priv->lock);usb_set_serial_port_data (serial->port[i], priv);
drivers/usb/serial/console.c +2 -4
@@ -166,19 +166,17 @@ static int usb_console_setup(struct consif (serial->type->set_termios) {/* build up a fake tty structure so that the open call has something * to look at to get the cflag value */ - tty =kmalloc (sizeof (*tty),GFP_KERNEL ); + tty =kzalloc (sizeof (*tty),GFP_KERNEL );if (!tty) {err ("no more memory" );return -ENOMEM ; } - termios =kmalloc (sizeof (*termios),GFP_KERNEL ); + termios =kzalloc (sizeof (*termios),GFP_KERNEL );if (!termios) {err ("no more memory" );kfree (tty);return -ENOMEM ; } -memset (tty,0x00 ,sizeof (*tty)); -memset (termios,0x00 ,sizeof (*termios)); termios->c_cflag = cflag; tty->termios = termios; port->tty = tty;
drivers/usb/serial/ti_usb_3410_5052.c +2 -3
@@ -459,13 +459,12 @@ static int ti_startup(struct usb_serial/* set up port structures */ for (i =0 ; i < serial->num_ports; ++i) { - tport =kmalloc (sizeof (struct ti_port ),GFP_KERNEL ); + tport =kzalloc (sizeof (struct ti_port ),GFP_KERNEL );if (tport ==NULL ) {dev_err (&dev->dev,"%s - out of memory\n" , __FUNCTION__); status = -ENOMEM ; goto free_tports; } -memset (tport,0 ,sizeof (struct ti_port ));spin_lock_init (&tport->tp_lock); tport->tp_uart_base_addr = (i ==0 ?TI_UART1_BASE_ADDR :TI_UART2_BASE_ADDR ); tport->tp_flags = low_latency ?ASYNC_LOW_LATENCY :0 ;
@@ -1709,7 +1708,7 @@ static struct circ_buf *ti_buf_alloc(voi {struct circ_buf *cb; - cb = (struct circ_buf *)kmalloc (sizeof (struct circ_buf ),GFP_KERNEL ); + cb =kmalloc (sizeof (struct circ_buf ),GFP_KERNEL );if (cb ==NULL )return NULL ;
drivers/video/amba-clcd.c +1 -2
@@ -447,13 +447,12 @@ static int clcdfb_probe(struct amba_devi goto out; } - fb = (struct clcd_fb *)kmalloc (sizeof (struct clcd_fb ),GFP_KERNEL ); + fb =kzalloc (sizeof (struct clcd_fb ),GFP_KERNEL );if (!fb) {printk (KERN_INFO "CLCD: could not allocate new clcd_fb struct\n" ); ret = -ENOMEM ; goto free_region; } -memset (fb,0 ,sizeof (struct clcd_fb )); fb->dev = dev; fb->board = board;
drivers/video/aty/atyfb_base.c +1 -2
@@ -2995,12 +2995,11 @@ static int __devinit atyfb_setup_sparc(s/* nothing */ ; j = i +4 ; - par->mmap_map =kmalloc (j *sizeof (*par->mmap_map),GFP_ATOMIC ); + par->mmap_map =kzalloc (j *sizeof (*par->mmap_map),GFP_ATOMIC );if (!par->mmap_map) {PRINTKE ("atyfb_setup_sparc() can't alloc mmap_map\n" );return -ENOMEM ; } -memset (par->mmap_map,0 , j *sizeof (*par->mmap_map));for (i =0 , j =2 ; i <6 && pdev->resource[i].start; i++) {struct resource *rp = &pdev->resource[i];
drivers/video/au1100fb.c +4 -5
@@ -453,11 +453,11 @@ int au1100fb_drv_probe(struct device *dereturn -EINVAL ;/* Allocate new device private */ -if (!(fbdev =kmalloc (sizeof (struct au1100fb_device ),GFP_KERNEL ))) { + fbdev =kzalloc (sizeof (struct au1100fb_device ),GFP_KERNEL ); +if (!fbdev) {print_err ("fail to allocate device private record" );return -ENOMEM ; } -memset ((void *)fbdev,0 ,sizeof (struct au1100fb_device )); fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
@@ -534,10 +534,9 @@ #endif fbdev->info.fbops = &au1100fb_ops; fbdev->info.fix = au1100fb_fix; -if (!(fbdev->info.pseudo_palette =kmalloc (sizeof (u32) *16 ,GFP_KERNEL ))) { + fbdev->info.pseudo_palette =kcalloc (16 ,sizeof (u32),GFP_KERNEL ); +if (!fbdev->info.pseudo_palette)return -ENOMEM ; - } -memset (fbdev->info.pseudo_palette,0 ,sizeof (u32) *16 );if (fb_alloc_cmap (&fbdev->info.cmap,AU1100_LCD_NBR_PALETTE_ENTRIES ,0 ) <0 ) { print_err("Fail to allocate colormap (%d entries)",
drivers/video/au1200fb.c +1 -2
@@ -1589,11 +1589,10 @@ static int au1200fb_init_fbinfo(struct areturn -EFAULT ; } - fbi->pseudo_palette =kmalloc (sizeof (u32) *16 ,GFP_KERNEL ); + fbi->pseudo_palette =kcalloc (16 ,sizeof (u32),GFP_KERNEL );if (!fbi->pseudo_palette) {return -ENOMEM ; } -memset (fbi->pseudo_palette,0 ,sizeof (u32) *16 );if (fb_alloc_cmap (&fbi->cmap,AU1200_LCD_NBR_PALETTE_ENTRIES ,0 ) <0 ) { print_err("Fail to allocate colormap (%d entries)",
drivers/video/clps711xfb.c +1 -2
@@ -366,11 +366,10 @@ int __init clps711xfb_init(void)if (fb_get_options ("clps711xfb" ,NULL ))return -ENODEV ; - cfb =kmalloc (sizeof (*cfb),GFP_KERNEL ); + cfb =kzalloc (sizeof (*cfb),GFP_KERNEL );if (!cfb) goto out; -memset (cfb,0 ,sizeof (*cfb));strcpy (cfb->fix.id,"clps711x" ); cfb->fbops = &clps7111fb_ops;
drivers/video/controlfb.c +1 -2
@@ -692,11 +692,10 @@ static int __init control_of_init(structprintk (KERN_ERR "can't get 2 addresses for control\n" );return -ENXIO ; } - p =kmalloc (sizeof (*p),GFP_KERNEL ); + p =kzalloc (sizeof (*p),GFP_KERNEL );if (p ==0 )return -ENXIO ; control_fb = p;/* save it for cleanups */ -memset (p,0 ,sizeof (*p));/* Map in frame buffer and registers */ p->fb_orig_base = fb_res.start;
drivers/video/cyber2000fb.c +1 -3
@@ -1221,12 +1221,10 @@ cyberpro_alloc_fb_info(unsigned int id, {struct cfb_info *cfb; - cfb =kmalloc (sizeof (struct cfb_info ),GFP_KERNEL ); + cfb =kzalloc (sizeof (struct cfb_info ),GFP_KERNEL );if (!cfb)return NULL ; -memset (cfb,0 ,sizeof (struct cfb_info )); - cfb->id = id;if (id ==ID_CYBERPRO_5000 )
drivers/video/i810/i810_main.c +2 -2
@@ -2010,11 +2010,11 @@ static int __devinit i810fb_init_pci (st par = info->par; par->dev = dev; -if (!(info->pixmap.addr =kmalloc (8 *1024 ,GFP_KERNEL ))) { + info->pixmap.addr =kzalloc (8 *1024 ,GFP_KERNEL ); +if (!info->pixmap.addr) {i810fb_release_resource (info, par);return -ENOMEM ; } -memset (info->pixmap.addr,0 ,8 *1024 ); info->pixmap.size =8 *1024 ; info->pixmap.buf_align =8 ; info->pixmap.access_align =32 ;
drivers/video/igafb.c +2 -5
@@ -400,12 +400,11 @@ int __init igafb_init(void) size =sizeof (struct fb_info ) +sizeof (struct iga_par ) +sizeof (u32)*16 ; - info =kmalloc (size,GFP_ATOMIC ); + info =kzalloc (size,GFP_ATOMIC );if (!info) {printk ("igafb_init: can't alloc fb_info\n" );return -ENOMEM ; } -memset (info,0 , size); par = (struct iga_par *) (info +1 );
@@ -464,7 +463,7 @@ #ifdef __sparc__* one additional region with size == 0. */ - par->mmap_map =kmalloc (4 *sizeof (*par->mmap_map),GFP_ATOMIC ); + par->mmap_map =kzalloc (4 *sizeof (*par->mmap_map),GFP_ATOMIC );if (!par->mmap_map) {printk ("igafb_init: can't alloc mmap_map\n" );iounmap ((void *)par->io_base);
@@ -473,8 +472,6 @@ #ifdef __sparc__return -ENOMEM ; } -memset (par->mmap_map,0 ,4 *sizeof (*par->mmap_map)); -/* * Set default vmode and cmode from PROM properties. */
drivers/video/intelfb/intelfbdrv.c +1 -2
@@ -529,12 +529,11 @@ intelfb_pci_register(struct pci_dev *pde dinfo->pdev = pdev;/* Reserve pixmap space. */ - info->pixmap.addr =kmalloc (64 *1024 ,GFP_KERNEL ); + info->pixmap.addr =kzalloc (64 *1024 ,GFP_KERNEL );if (info->pixmap.addr ==NULL ) {ERR_MSG ("Cannot reserve pixmap memory.\n" ); goto err_out_pixmap; } -memset (info->pixmap.addr,0 ,64 *1024 );/* set early this option because it could be changed by tv encoder driver */
drivers/video/matrox/matroxfb_crtc2.c +1 -2
@@ -694,12 +694,11 @@ static void* matroxfb_crtc2_probe(struct/* hardware is CRTC2 incapable... */ if (!ACCESS_FBINFO (devflags.crtc2))return NULL ; - m2info = (struct matroxfb_dh_fb_info *)kmalloc (sizeof (*m2info),GFP_KERNEL ); + m2info =kzalloc (sizeof (*m2info),GFP_KERNEL );if (!m2info) {printk (KERN_ERR "matroxfb_crtc2: Not enough memory for CRTC2 control structs\n" );return NULL ; } -memset (m2info,0 ,sizeof (*m2info)); m2info->primary_dev =MINFO ;if (matroxfb_dh_registerfb (m2info)) {kfree (m2info);
drivers/video/nvidia/nvidia.c +1 -3
@@ -1194,13 +1194,11 @@ static int __devinit nvidiafb_probe(stru par = info->par; par->pci_dev = pd; - info->pixmap.addr =kmalloc (8 *1024 ,GFP_KERNEL ); + info->pixmap.addr =kzalloc (8 *1024 ,GFP_KERNEL );if (info->pixmap.addr ==NULL ) goto err_out_kfree; -memset (info->pixmap.addr,0 ,8 *1024 ); -if (pci_enable_device (pd)) { printk(KERN_ERR PFX "cannot enable PCI device\n"); goto err_out_enable;
drivers/video/offb.c +2 -3
@@ -376,13 +376,12 @@ static void __init offb_init_fb(const ch size =sizeof (struct fb_info ) +sizeof (u32) *17 ; - info =kmalloc (size,GFP_ATOMIC ); + info =kzalloc (size,GFP_ATOMIC ); -if (info ==0 ) { +if (!info) {release_mem_region (res_start, res_size);return ; } -memset (info,0 , size); fix = &info->fix; var = &info->var;
drivers/video/pvr2fb.c +1 -3
@@ -1065,14 +1065,12 @@ #ifndef MODULE#endif size =sizeof (struct fb_info ) +sizeof (struct pvr2fb_par ) +16 *sizeof (u32); - fb_info =kmalloc (size,GFP_KERNEL ); + fb_info =kzalloc (size,GFP_KERNEL );if (!fb_info) {printk (KERN_ERR "Failed to allocate memory for fb_info\n" );return -ENOMEM ; } -memset (fb_info,0 , size); - currentpar = (struct pvr2fb_par *)(fb_info +1 );for (i =0 ; i <ARRAY_SIZE (board_list); i++) {
drivers/video/pxafb.c +1 -2
@@ -1051,11 +1051,10 @@ static struct pxafb_info * __init pxafb_struct pxafb_mach_info *inf = dev->platform_data;/* Alloc the pxafb_info and pseudo_palette in one step */ - fbi =kmalloc (sizeof (struct pxafb_info ) +sizeof (u32) *16 ,GFP_KERNEL ); + fbi =kzalloc (sizeof (struct pxafb_info ) +sizeof (u32) *16 ,GFP_KERNEL );if (!fbi)return NULL ; -memset (fbi,0 ,sizeof (struct pxafb_info )); fbi->dev = dev;strcpy (fbi->fb.fix.id,PXA_NAME );
drivers/video/retz3fb.c +2 -3
@@ -1369,10 +1369,9 @@ int __init retz3fb_init(void)release_mem_region (board_addr,0x00c00000 );continue ; } -if (!(zinfo =kmalloc (sizeof (struct retz3_fb_info ), -GFP_KERNEL ))) + zinfo =kzalloc (sizeof (struct retz3_fb_info ),GFP_KERNEL ); +if (!zinfo)return -ENOMEM ; -memset (zinfo,0 ,sizeof (struct retz3_fb_info )); zinfo->base =ioremap (board_addr, board_size); zinfo->regs = zinfo->base;
drivers/video/riva/fbdev.c +1 -2
@@ -1999,12 +1999,11 @@ static int __devinit rivafb_probe(struct default_par = info->par; default_par->pdev = pd; - info->pixmap.addr =kmalloc (8 *1024 ,GFP_KERNEL ); + info->pixmap.addr =kzalloc (8 *1024 ,GFP_KERNEL );if (info->pixmap.addr ==NULL ) { ret = -ENOMEM ; goto err_framebuffer_release; } -memset (info->pixmap.addr,0 ,8 *1024 ); ret =pci_enable_device (pd);if (ret <0 ) {
drivers/video/sa1100fb.c +1 -2
@@ -1373,12 +1373,11 @@ static struct sa1100fb_info * __init sa1struct sa1100fb_mach_info *inf;struct sa1100fb_info *fbi; - fbi =kmalloc (sizeof (struct sa1100fb_info ) +sizeof (u32) *16 , + fbi =kzalloc (sizeof (struct sa1100fb_info ) +sizeof (u32) *16 ,GFP_KERNEL );if (!fbi)return NULL ; -memset (fbi,0 ,sizeof (struct sa1100fb_info )); fbi->dev = dev;strcpy (fbi->fb.fix.id,SA1100_NAME );
drivers/video/savage/savagefb_driver.c +1 -2
@@ -2122,11 +2122,10 @@ static int __devinit savage_init_fb_info#if defined(CONFIG_FB_SAVAGE_ACCEL )/* FIFO size + padding for commands */ - info->pixmap.addr =kmalloc (8 *1024 ,GFP_KERNEL ); + info->pixmap.addr =kzalloc (8 *1024 ,GFP_KERNEL ); err = -ENOMEM ;if (info->pixmap.addr) { -memset (info->pixmap.addr,0 ,8 *1024 ); info->pixmap.size =8 *1024 ; info->pixmap.scan_align =4 ; info->pixmap.buf_align =4 ;
drivers/video/sis/sis_main.c +1 -2
@@ -5875,10 +5875,9 @@ #if (LINUX_VERSION_CODE >= KERNEL_VERSIOif (!sis_fb_info)return -ENOMEM ;#else - sis_fb_info =kmalloc (sizeof (*sis_fb_info) +sizeof (*ivideo),GFP_KERNEL ); + sis_fb_info =kzalloc (sizeof (*sis_fb_info) +sizeof (*ivideo),GFP_KERNEL );if (!sis_fb_info)return -ENOMEM ; -memset (sis_fb_info,0 ,sizeof (*sis_fb_info) +sizeof (*ivideo)); sis_fb_info->par = ((char *)sis_fb_info +sizeof (*sis_fb_info));#endif
drivers/video/sun3fb.c +1 -2
@@ -524,11 +524,10 @@ static int __init sun3fb_init_fb(int fbtint linebytes, w, h, depth;char *p =NULL ; - fb =kmalloc (sizeof (struct fb_info_sbusfb ),GFP_ATOMIC ); + fb =kzalloc (sizeof (struct fb_info_sbusfb ),GFP_ATOMIC );if (!fb)return -ENOMEM ; -memset (fb,0 ,sizeof (struct fb_info_sbusfb )); fix = &fb->fix; var = &fb->var; disp = &fb->disp;
drivers/video/tgafb.c +1 -2
@@ -1394,12 +1394,11 @@ tgafb_pci_register(struct pci_dev *pdev, }/* Allocate the fb and par structures. */ - all =kmalloc (sizeof (*all),GFP_KERNEL ); + all =kzalloc (sizeof (*all),GFP_KERNEL );if (!all) {printk (KERN_ERR "tgafb: Cannot allocate memory\n" );return -ENOMEM ; } -memset (all,0 ,sizeof (*all));pci_set_drvdata (pdev, all);/* Request the mem regions. */
drivers/video/valkyriefb.c +1 -2
@@ -357,10 +357,9 @@ #else /* ppc (!CONFIG_MAC) */ }#endif /* ppc (!CONFIG_MAC) */ - p =kmalloc (sizeof (*p),GFP_ATOMIC ); + p =kzalloc (sizeof (*p),GFP_ATOMIC );if (p ==0 )return -ENOMEM ; -memset (p,0 ,sizeof (*p));/* Map in frame buffer and registers */ if (!request_mem_region (frame_buffer_phys,0x100000 ,"valkyriefb" )) {
Signature · 1 line
1.4.2.rc1.ge7a0-dirty
Am Donnerstag, 20. Juli 2006 21:05 schrieb Panagiotis Issaris:
drivers/atm/zatm.c static int start_rx(struct atm_dev *dev) · line 606
Quoted 11 lines
From: Panagiotis Issaris <[email protected]>
drivers: Conversions from kmalloc+memset to k(z|c)alloc.
drivers/atm/zatm.c +1
-1@@ -603,9 +603,8 @@ static int start_rx(struct atm_dev *dev)DPRINTK ("start_rx\n" ); zatm_dev =ZATM_DEV (dev); size =sizeof (struct atm_vcc *)*zatm_dev->chans; - zatm_dev->rx_map = (struct atm_vcc **)kmalloc (size,GFP_KERNEL ); + zatm_dev->rx_map =kzalloc (size,GFP_KERNEL );
Space after comma.
drivers/atm/zatm.c static int open_tx_first(struct atm_vcc · line 953
Quoted 6 lines
drivers/atm/zatm.c +1
-1@@ -951,9 +950,8 @@ static int open_tx_first(struct atm_vccskb_queue_head_init (&zatm_vcc->tx_queue);init_waitqueue_head (&zatm_vcc->tx_wait);/* initialize ring */ - zatm_vcc->ring =kmalloc (RING_SIZE ,GFP_KERNEL ); + zatm_vcc->ring =kzalloc (RING_SIZE ,GFP_KERNEL );
Same here
Quoted 4 lines
drivers/atm/zatm.c +0
-0@@ -443,12 +442,11 @@ int con_clear_unimap(struct vc_data *vc, p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;if (p && p->readonly)return -EIO ;if (!p || --p->refcount) {
drivers/atm/zatm.c int con_clear_unimap(struct vc_data *vc, · line 452
Quoted 10 lines
drivers/atm/zatm.c +1
-2- q = (struct uni_pagedir *)kmalloc (sizeof (*p),GFP_KERNEL ); + q =kzalloc (sizeof (*p),GFP_KERNEL );if (!q) {if (p) p->refcount++;return -ENOMEM ; } -memset (q,0 ,sizeof (*q)); q->refcount=1 ; *vc->vc_uni_pagedir_loc = (unsigned long )q; }else {
This one still changes the way the code works. Before your patch *p will be always zeroed out. Now if p is there before it will keep it's contents.
drivers/char/keyboard.c static struct input_handle *kbd_connect( · line 1303
Quoted 12 lines
drivers/char/keyboard.c +2
-1@@ -1298,9 +1298,9 @@ static struct input_handle *kbd_connect(if (i ==BTN_MISC && !test_bit (EV_SND , dev->evbit))return NULL ; -if (!(handle =kmalloc (sizeof (struct input_handle ),GFP_KERNEL ))) + handle =kzalloc (sizeof (struct input_handle ),GFP_KERNEL ); +if (!handle)return NULL ;
sizeof(*handle)?
drivers/char/random.c void rand_initialize_irq(int irq) · line 914
Quoted 10 lines
drivers/char/random.c +1
-1@@ -911,9 +911,8 @@ void rand_initialize_irq(int irq)* If kmalloc returns null, we just won't use that entropy * source. */ - state =kmalloc (sizeof (struct timer_rand_state ),GFP_KERNEL ); + state =kzalloc (sizeof (struct timer_rand_state ),GFP_KERNEL );
sizeof(*state)?
drivers/char/random.c void rand_initialize_disk(struct gendisk · line 928
Quoted 6 lines
drivers/char/random.c +1
-1@@ -926,9 +925,8 @@ void rand_initialize_disk(struct gendisk* If kmalloc returns null, we just won't use that entropy * source. */ - state =kmalloc (sizeof (struct timer_rand_state ),GFP_KERNEL ); + state =kzalloc (sizeof (struct timer_rand_state ),GFP_KERNEL );
Also here.
Quoted 24 lines
drivers/char/sx.c +0
-12@@ -2278,18 +2278,6 @@ static int sx_init_drivers(void)return 0 ; } - -static void *ckmalloc (int size) -{ -void *p; - - p =kmalloc (size,GFP_KERNEL ); -if (p) -memset (p,0 , size); -return p; -} - -static int sx_init_portstructs (int nboards,int nports) {struct sx_board *board;
drivers/char/sx.c static int sx_init_portstructs (int nboa · line 2294
Quoted 5 lines
drivers/char/sx.c +1
-0@@ -2302,7 +2290,7 @@ static int sx_init_portstructs (int nboa/* Many drivers statically allocate the maximum number of ports There is no reason not to allocate them dynamically. Is there? -- REW */ - sx_ports =ckmalloc (nports *sizeof (struct sx_port )); + sx_ports =kcalloc (nports,sizeof (struct sx_port ),GFP_KERNEL );
No space before opening brace.
drivers/char/sx.c static int init_dev(struct tty_driver *d · line 1469
Quoted 6 lines
drivers/char/sx.c +1
-1@@ -1477,7 +1466,7 @@ static int init_dev(struct tty_driver *d tp = o_tp =NULL ; ltp = o_ltp =NULL ; - tty =alloc_tty_struct (); + tty =kzalloc (sizeof (struct tty_struct ),GFP_KERNEL );
sizeof(*tty)?
drivers/char/sx.c static int init_dev(struct tty_driver *d · line 1494
Quoted 7 lines
drivers/char/sx.c +1
-2@@ -1502,15 +1491,13 @@ static int init_dev(struct tty_driver *d }if (!*ltp_loc) { - ltp = (struct termios *)kmalloc (sizeof (struct termios ), -GFP_KERNEL ); + ltp =kzalloc (sizeof (struct termios ),GFP_KERNEL );
sizeof(*ltp)?
[more of this snipped]
Quoted 5 lines
drivers/isdn/hisax/hfc_usb.c +0
-0
drivers/isdn/hisax/hfc_usb.c #endif · line 1484
Quoted 9 lines
drivers/isdn/hisax/hfc_usb.c +2
-3@@ -1479,11 +1479,9 @@ #endif/* found a valid USB Ta Endpint config */ if (small_match !=0xffff ) { iface = iface_used; -if (! - (context = -kmalloc (sizeof (hfcusb_data),GFP_KERNEL ))) + context =kzalloc (sizeof (hfcusb_data),GFP_KERNEL ); +if (!context)return (-ENOMEM );/* got no mem */
while you're at it. can you please change it to "return -ENOMEM;"? The comment does not help anyone and we return without braces.
drivers/media/video/planb.c static int planb_prepare_open(struct pla · line 356
Quoted 10 lines
drivers/media/video/planb.c +1
-1@@ -353,9 +353,9 @@ static int planb_prepare_open(struct pla * PLANB_DUMMY)*sizeof(struct dbdma_cmd) +(PLANB_MAXLINES *((PLANB_MAXPIXELS +7 )& ~7 ))/8 +MAX_GBUFFERS *sizeof (unsigned int ); -if ((pb->priv_space =kmalloc (size,GFP_KERNEL )) ==0 ) + pb->priv_space =kzalloc (size,GFP_KERNEL );
space
[...]
Eike
Quoted 6 lines · Rolf Eike Beer
drivers/char/keyboard.c static struct input_handle *kbd_connect( · line 1303
Quoted 4 lines
drivers/char/keyboard.c +2
-1-if (!(handle =kmalloc (sizeof (struct input_handle ),GFP_KERNEL ))) + handle =kzalloc (sizeof (struct input_handle ),GFP_KERNEL ); +if (!handle)return NULL ;
sizeof(*handle)?
In general, yes. However, some maintainers don't like that, so I would recommend to keep them as-is unless you get a clear ack from the maintainer to change it.
Quoted 11 lines · Pekka Enberg
Quoted 6 lines · Rolf Eike Beer
drivers/char/keyboard.c static struct input_handle *kbd_connect( · line 1303
Quoted 4 lines
drivers/char/keyboard.c +2
-1-if (!(handle =kmalloc (sizeof (struct input_handle ),GFP_KERNEL ))) + handle =kzalloc (sizeof (struct input_handle ),GFP_KERNEL ); +if (!handle)return NULL ;
sizeof(*handle)?In general, yes. However, some maintainers don't like that, so I would recommend to keep them as-is unless you get a clear ack from the maintainer to change it.
Strongly agreed. Follow the style of the existing code as closely as possible, and resist the temptation of making little "improvements" while you are doing a task...
Jeff
Quoted 7 lines · Jeff Garzik
Quoted 6 lines · Pekka Enberg
Quoted 5 lines · Rolf Eike Beer
Quoted 4 lines
drivers/char/keyboard.c +2
-1-if (!(handle =kmalloc (sizeof (struct input_handle ),GFP_KERNEL ))) + handle =kzalloc (sizeof (struct input_handle ),GFP_KERNEL ); +if (!handle)return NULL ;
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
sizeof(*handle)?In general, yes. However, some maintainers don't like that, so I would recommend to keep them as-is unless you get a clear ack from the maintainer to change it.
I suggest:
- check if "sizeof(type)"->"sizeof(*ptr)" is correct
- if yes, change it
- do this for all kmalloc + kzalloc in a file you touched, or better yet for all kmalloc + kzalloc in a driver or subsystem you touched
Maintainers who don't agree can always post a NAK. There are hardly any special cases which speak against that change --- provided the change is done for the whole subsystem.
Quoted 3 lines
Strongly agreed. Follow the style of the existing code as closely as possible, and resist the temptation of making little "improvements" while you are doing a task...
The 2nd half of this statement is a good and important rule. But look at this particular case. The patch does (or could) contain
- consolidation of kmalloc+memset/0 -> kzalloc where correct,
- better style of the size argument where correct,
- whitespace style adjustments of the touched regions.
All of these changes, if done correct, are true improvements WRT programming idioms. IMO it's a single task, therefore adheres to that rule. I'd only split this kind of patches if separately maintained subsystems are touched.
As for the 1st half of this statement, "follow the style of existing code as closely as possible": This is problematic in light of the more important rule "follow CodingStyle".
I suggest to follow existing style if small changes are introduced and the existing code mostly complies to CodingStyle. If existing code with small deviations from CodingStyle is touched, the potential loss of readability by partial conversion to CodingStyle may be negligible. If existing code with bigger deviations from CodingStyle is touched, the author of a patch should consider to provide an additional patch before or after that with a complete conversion to CodingStyle. (I took the time to do this on a few occasions too.)
Signature · 3 lines
Stefan Richter -=====-=-==- -=== =--== http://arcgraph.de/sr/
Quoted 17 lines · Stefan Richter
Quoted 7 lines · Jeff Garzik
Quoted 6 lines · Pekka Enberg
Quoted 5 lines · Rolf Eike Beer
Quoted 4 lines
drivers/char/keyboard.c +2
-1-if (!(handle =kmalloc (sizeof (struct input_handle ),GFP_KERNEL ))) + handle =kzalloc (sizeof (struct input_handle ),GFP_KERNEL ); +if (!handle)return NULL ;Quoted 5 lines
Quoted 5 lines
Quoted 1 line
sizeof(*handle)?In general, yes. However, some maintainers don't like that, so I would recommend to keep them as-is unless you get a clear ack from the maintainer to change it.
I suggest:
- check if "sizeof(type)"->"sizeof(*ptr)" is correct
- if yes, change it
[snip]
Quoted 1 line
- better style of the size argument where correct,
Who says it's "better style" ?
You can argue that sizeof(type) is more readable.
When reading the code you don't have to go lookup the type of ptr in sizeof(*ptr) before you know what type the code is working with.
Signature · 3 lines
Jesper Juhl <[email protected]> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please http://www.expita.com/nomime.html
Hi,
Quoted 4 lines · Jesper Juhl
[snip]
Quoted 1 line
- better style of the size argument where correct,
Who says it's "better style" ?
Documentation/CodingStyle does :) (which in fact, I only noticed when I was validating someone's remark that it would be a good idea to change sizeof's)
"The preferred form for passing a size of a struct is the following:
p = kmalloc(sizeof(*p), ...);
The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed to a memory allocator is not."
Quoted 3 lines
You can argue that sizeof(type) is more readable.
When reading the code you don't have to go lookup the type of ptr insizeof(*ptr)before you know what type the code is working with.
With friendly regards,
Takis
Quoted 1 line · Jesper Juhl
Quoted 1 line
Who says it's "better style" ?
Quoted 3 lines · Panagiotis Issaris
Documentation/CodingStyledoes :) (which in fact, I only noticed when I was validating someone's remark that it would be a good idea to change sizeof's)
Yeah, that's what Andrew prefers but there are maintainers that disagree with that.
Pekka
Quoted 2 lines · Pekka J Enberg
Yeah, that's what Andrew prefers but there are maintainers that disagree with that.
Then they should change CodingStyle.
Signature · 3 lines
Stefan Richter -=====-=-==- -=== =--== http://arcgraph.de/sr/
Quoted 5 lines · Stefan Richter
Quoted 2 lines · Pekka J Enberg
Yeah, that's what Andrew prefers but there are maintainers that disagree with that.
Then they should change CodingStyle.
Better will be start use indent.
Coding style seems is Linux case kind of never ending story.
Keep one/common coding style in this case is someting not for small tool but more for .. Superman/Hecules (?)
Why not add .indent.pro file in aeach source tree directory and add to Makefile "indent" target ? Why not after add this just before make next release run "make indent" and commit all this to git tree ?
kloczek
Signature · 4 lines
----------------------------------------------------------- *Ludzie nie mają problemów, tylko sobie sami je stwarzają* ----------------------------------------------------------- Tomasz Kłoczko, sys adm @zie.pg.gda.pl|*e-mail: [email protected]*
Quoted 9 lines · Tomasz Kłoczko
Quoted 6 lines · Stefan Richter
Quoted 2 lines · Pekka J Enberg
Yeah, that's what Andrew prefers but there are maintainers that disagree with that.
Then they should change CodingStyle.
Better will be start use indent.
Style issues like "sizeof(struct foo)" versus "sizeof(*bar)" in memory allocation are beyond what indent can and should do.
Quoted 1 line
Coding style seems is Linux case kind of never ending story.
It's not a big deal in my limited experience, as far as there is a documented consensus.
Quoted 1 line
Keep one/common coding style in this case is someting not for small tool but more for .. Superman/Hecules (?)
[...]
Yes. Or subsystem maintainers who didn't already could adopt the documented style. Or correct the document where it doesn't reflect consensus.
Signature · 3 lines
Stefan Richter -=====-=-==- -=== =-==- http://arcgraph.de/sr/
On Sat, 22 Jul 2006, Stefan Richter wrote:
[..]
Quoted 10 lines
Style issues like "sizeof(struct foo)" versus "
sizeof(*bar)" in memory allocation are beyond what indent can and should do.Quoted 1 line
Coding style seems is Linux case kind of never ending story.
It's not a big deal in my limited experience, as far as there is a documented consensus.
Quoted 1 line
Keep one/common coding style in this case is someting not for small tool but more for .. Superman/Hecules (?)
[...]
Yes. Or subsystem maintainers who didn't already could adopt the documented style. Or correct the document where it doesn't reflect consensus.
Moment .. are you want to say something like "keep commont coding style can't be maintained by tool" ?
Even if indent watches on to small coding style emenets still I don't see why using this tool isn't one of the current ement of release procedure (?).
kloczek
Signature · 4 lines
----------------------------------------------------------- *Ludzie nie mają problemów, tylko sobie sami je stwarzają* ----------------------------------------------------------- Tomasz Kłoczko, sys adm @zie.pg.gda.pl|*e-mail: [email protected]*
Quoted 2 lines · Tomasz Kłoczko
Moment .. are you want to say something like "keep commont coding style can't be maintained by tool" ?
Even if indent watches on to small coding style emenets still I don't see why using this tool isn't one of the current ement of release procedure (?).
indent isn't perfect, _especially_ where C99 comes into the picture.
And running indent across the tree pre-release would (a) create a ton of noise before each release, and (b) undo perfectly valid, readable formatting.
scripts/Lindent exists and gets used, but it is not perfect.
Jeff
Quoted 5 lines · Jeff Garzik
Quoted 2 lines · Tomasz Kłoczko
Moment .. are you want to say something like "keep commont coding style can't be maintained by tool" ?
Even if indent watches on to small coding style emenets still I don't see why using this tool isn't one of the current ement of release procedure (?).indent isn't perfect, _especially_ where C99 comes into the picture.
Again: is in this case "isn't perfect" mean "it does not make all what we want" ? If yes still I don't see why not use indent + some other tool or if you will show real example where it does something badady (like now for checking code syntax is used compiler and some other tools like sparse).
Quoted 1 line
And running indent across the tree pre-release would (a) create a ton of noise before each release, and (b) undo perfectly valid, readable formatting.
Committing all this "noise" will plug all this thing and allow reve most of content Documentation/CodingStyle document.
Is it not wort stop all questions/discuss/flames on this subject ?
Again: using indent mainly will mean only one time massive changes. After this ident can be runed for example by Linus just before make release and/or partial release.
Quoted 1 line
scripts/Lindentexists and gets used, but it is not perfect.
Again: anywhere are listed/was posted list of "not perfect" examples ? And/or: what does it mean in this case "not perfect" ? Show this for allow start work on fix indent by other people (if all cases will be resul of some bugs in this tool).
kloczek
Signature · 4 lines
----------------------------------------------------------- *Ludzie nie mają problemów, tylko sobie sami je stwarzają* ----------------------------------------------------------- Tomasz Kłoczko, sys adm @zie.pg.gda.pl|*e-mail: [email protected]*
[CC list trimmed]
Quoted 16 lines · Tomasz Kłoczko
Quoted 8 lines · Jeff Garzik
Quoted 5 lines · Tomasz Kłoczko
Moment .. are you want to say something like "keep commont coding style can't be maintained by tool" ?
Even if indent watches on to small coding style emenets still I don't see why using this tool isn't one of the current ement of release procedure (?).indent isn't perfect, _especially_ where C99 comes into the picture.
Again: is in this case "isn't perfect" mean "it does not make all what we want" ? If yes still I don't see why not use indent + some other tool or if you will show real example where it does something badady (like now for checking code syntax is used compiler and some other tools like sparse).
Quoted 7 lines
Quoted 3 lines
And running indent across the tree pre-release would (a) create a ton of noise before each release, and (b) undo perfectly valid, readable formatting.
Committing all this "noise" will plug all this thing and allow reve most of content
Documentation/CodingStyledocument.
Is it not wort stop all questions/discuss/flames on this subject ?
Yes, it's better to stop this thread. Because you haven't done your homework and advocating procedure which will create massive spurious changes every time it's applied.
If you have math background:
Lindent \cdot Lindent \neq Lindent
pretty often. If you don't, see below.
Quoted 1 line
Again: using indent mainly will mean only one time massive changes.
True, 180M(!) of them.
Quoted 3 lines
After
this ident can be runed for example by Linus just before make release and/or partial release.
~4M per run.
Quoted 1 line
Quoted 1 line
scripts/Lindentexists and gets used, but it is not perfect.
Correction: GNU indent exists and gets used, but it is not perfect.
Last time I checked BSD indent don't have some option Lindent use. forgot which.
Quoted 1 line
Again: anywhere are listed/was posted list of "not perfect" examples ?
OOhhhh, please do
find . -type f -name '*.[ch]' | xargs ./scripts/Lindent
on any large C codebase.
Quoted 5 lines
And/or: what does it mean in this case "not perfect" ?
Show this for
allow start work on fix indent by other people (if all cases will be resul of some bugs in this tool).
Start fixing indent(1) if you're serious about all this. There are _plenty_ of C code flying around.
On Sun, 23 Jul 2006, Alexey Dobriyan wrote:
[..]
Quoted 3 lines
Quoted 1 line
Again: using indent mainly will mean only one time massive changes.
True, 180M(!) of them.
~160M.
And this is so huge now because seems there is no obligation use common format .. all is formated using hands/mind/difftent editors autoformaters.
Quoted 5 lines
Quoted 3 lines
After
this ident can be runed for example by Linus just before make release and/or partial release.~4M per run.
If patch submmitter will use formating tool and it will add it will statr work on formated source tree it will be 0M per run.
Quoted 3 lines
Quoted 1 line
Quoted 1 line
scripts/Lindentexists and gets used, but it is not perfect.Correction: GNU indent exists and gets used, but it is not perfect.
Yes .. and produce by Lindent ~160MB patch it excelent proof how offent is is used now :> (please stop this crap "argumentation" :>)
Quoted 2 lines
Last time I checked BSD indent don't have some option Lindent use. forgot which.
Any problems with use BDS indent instead GNU ?
Quoted 7 lines
Quoted 1 line
Again: anywhere are listed/was posted list of "not perfect" examples ?
OOhhhh, please do
find . -type f -name '*.[ch]' | xargs
./scripts/Lindenton any large C codebase.
Runing above on linux-2.6.17.6 tree produces 248 errors mainly because was used *bad coding style*. I.e. by keep in distribution tree some strange pieces of code like:
#if 0
if () {
#endif
if () {
}Quoted 8 lines
Quoted 5 lines
And/or: what does it mean in this case "not perfect" ?
Show this for
allow start work on fix indent by other people (if all cases will be resul of some bugs in this tool).Start fixing indent(1) if you're serious about all this. There are _plenty_ of C code flying around.
IMO .. first will be good xcleanup some Linux code by remove some to many multiple using C preprocessor stantments which seems is now main cause why indent can be used. Current linux-2.6.17.6 tree have 16028 *.[ch] files.
Gnu indet produces errors on:
[linux-2.6.17.6]$ find -name \*.c -o -name \*.h | xargs indent -npro -kr \
-i8 -ts8 -sob -l80 -ss -ncs 2>&1 | awk '{print $2}' | awk -F: \
'{print $1}' | sort | uniq | wc -l76
*76 files*
Again: using indent requires keep code in some order. General "Coding Style" is list of rules. It will be now add one new simple rule "keep code in form which allow use indent without producing errors".
Below list of files on which now indent produces orrors (from 2.6.17.6 tree):
./arch/xtensa/mm/tlb.c./drivers/atm/iphase.c./drivers/cdrom/cm206.c./drivers/cdrom/mcdx.c./drivers/char/ftape/lowlevel/ftape-bsm.c./drivers/char/ip2/ip2main.c./drivers/char/serial167.c./drivers/i2c/algos/i2c-algo-bit.c./drivers/ide/legacy/hd.c./drivers/ide/pci/alim15x3.c./drivers/isdn/hardware/eicon/capifunc.c./drivers/isdn/hisax/l3dss1.c./drivers/md/linear.c./drivers/media/video/w9968cf.c./drivers/net/cris/eth_v10.c./drivers/net/eepro100.c./drivers/net/sk98lin/skdim.c./drivers/net/sk98lin/skge.c./drivers/net/sk98lin/skgesirq.c./drivers/net/wireless/i82586.h./drivers/net/yellowfin.c./drivers/parport/parport_arc.c./drivers/s390/cio/qdio.c./drivers/s390/s390mach.c./drivers/sbus/char/aurora.c./drivers/scsi/3w-9xxx.c./drivers/scsi/53c7xx.c./drivers/scsi/lpfc/lpfc_init.c./drivers/scsi/seagate.c./drivers/scsi/st.c./drivers/serial/68328serial.c./drivers/serial/crisv10.c./drivers/usb/host/hc_crisv10.c./drivers/usb/input/hid-core.c./drivers/video/intelfb/intelfbhw.c./drivers/video/neofb.c./drivers/video/sis/init301.c./fs/jffs2/wbuf.c./fs/jffs/intrep.c./fs/jfs/jfs_txnmgr.c./fs/ntfs/super.c./include/asm-frv/math-emu.h./include/asm-m68k/atariints.h./include/asm-m68k/math-emu.h./include/asm-m68k/raw_io.h./include/asm-m68k/tlbflush.h./include/asm-mips/delay.h./include/asm-s390/page.h./include/asm-x86_64/calling.h./include/asm-xtensa/xtensa/coreasm.h./sound/isa/es18xx.c./sound/oss/ad1889.c./sound/oss/cs4232.c./sound/oss/sb_ess.c
kloczek
Signature · 4 lines
----------------------------------------------------------- *Ludzie nie mają problemów, tylko sobie sami je stwarzają* ----------------------------------------------------------- Tomasz Kłoczko, sys adm @zie.pg.gda.pl|*e-mail: [email protected]*
Quoted 19 lines · Tomasz Kłoczko
On Sun, 23 Jul 2006, Alexey Dobriyan wrote:
[..]Quoted 3 lines
Quoted 1 line
Again: using indent mainly will mean only one time massive changes.
True, 180M(!) of them.
~160M.
And this is so huge now because seems there is no obligation use common format .. all is formated using hands/mind/difftent editors autoformaters.Quoted 5 lines
Quoted 3 lines
After
this ident can be runed for example by Linus just before make release and/or partial release.~4M per run.
If patch submmitter will use formating tool and it will add it will statr work on formated source tree it will be 0M per run.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
scripts/Lindentexists and gets used, but it is not perfect.Correction: GNU indent exists and gets used, but it is not perfect.
Yes .. and produce by Lindent ~160MB patch it excelent proof how offent is is used now :>
(please stop this crap "argumentation" :>)
Yeah, please stop it.
Did you actually _look_ at what indent does to code sometimes? It sometimes (often?) renders perfectly readable code into a huge blob of crap.
Face reality. The linux kernel is following the general codingstyle very well already. I don't think there is need to improve the current codebase for non-existent codingstyle issues. And we already review new code for codingstyle issues, so the codebase remains clean.
Look at other projects with horrible codingstyle problems and suggest solutions to their _real_ issues. *cough*kde*cough*
Signature · 1 line
Greetings Michael.
On Sun, 23 Jul 2006, Michael Buesch wrote:
[..]
Quoted 4 lines
Yeah, please stop it.
Did you actually _look_ at what indent does to code sometimes? It sometimes (often?) renders perfectly readable code into a huge blob of crap.
Do you remember file names ?
I'm just review diff after using indent with Lindent args and only in few places I saw something badly looking:
- badly formated __asm__ () content
- in case some functions with very long function names worser looling function header,
- struct with filled field using multicolumt (why not use single col ?)
IMO curent issue isn't "indent produces (generaly) bad output" but "in some very limited (compare to all amout of code) cases it produces something looking bad". In all other/most of cases (probably ~99%) Lindetd can be used .. but for NOW GENERALY IT IS NOT NOT USED.
Quoted 4 lines
Face reality. The linux kernel is following the general codingstyle very well already. I don't think there is need to improve the current codebase for non-existent codingstyle issues. And we already review new code for codingstyle issues, so the codebase remains clean.
Sorry but it is not true. There is no single coding style. Now in probably compareble amout of points is used constructions like:
1) top of the function:
static inline void *find_pa(unsigned long *vptb, void *ptr)
or
static inline void *find_pa(unsigned long *vptb, void *ptr)
(Lindent produces second variant)
2) type conversion:
return (void *) result;
or
return (void*)result;
or
return (void *)result;(Lindent produces last)
3) using tab or not (Lindent produces code with tabs)
4) sometimes functions argumeta are formated in sigle colum but sometimes not:
printk("%s Module Type: 0x%x - Unit ID 0x%x - "
"Condition 0x%x\n",
err_print_prefix,
env->module_type,
env->unit_id,
env->condition);
or
printk("%s Module Type: 0x%x - Unit ID 0x%x - "
"Condition 0x%x\n",
env->module_type, env->unit_id, env->condition);5) remove trailing spaces or not (indent removes trailing spaces)
and probably much, much more small details like this.
Quoted 2 lines
Look at other projects with horrible codingstyle problems and suggest solutions to their _real_ issues. *cough*kde*cough*
Sorry but in this case it is simple chicken and egg problem. First you must define "coding style" details and after this you can start work on tool for indenting all source code.
Now I know why Linux code NEVER was autoformated using some tool. Cause is VERY simple: because THERE IS NO complet coding style definition for Linux tree.
Current Documentation/CodingStyle contains only *very* limited neccessary for finish this details.
There is not general rule like "if it produces correctly looking output use Lindet" so current Linux coding style is "free style" .. nothing more.
Add general advice "try use Lindent" will allow start discuss on some never defined coding style details. Probaly it will als show some bad coded fregmets (for exxample when somen uses very long identifiers for variables or function names and it will badly look on 80 colums). Withouty this any time when "coding style" will back it can produce next flame theread.
kloczek
PS. In case coding style Linus is right "Documentations/specyfications is close to useless" because usability of Documentation/CodingStyle is realy cloase to useless but .. in *this* case ducumetation isn't guilty.
Signature · 4 lines
----------------------------------------------------------- *Ludzie nie mają problemów, tylko sobie sami je stwarzają* ----------------------------------------------------------- Tomasz Kłoczko, sys adm @zie.pg.gda.pl|*e-mail: [email protected]*
On Mon, 24 Jul 2006, Tomasz Kłoczko wrote:
[..]
Quoted 1 line
In all other/most of cases (probably ~99%) Lindetd can be used .. but for NOW GENERALY IT IS NOT NOT USED.
I'm just look on number changed fles by Lindent. diffstat shows 14593 changed files. Number of all *.[ch] files is 16028. So it shows now ~9% all files passes cleanly indentation using Lindent (my above "GENERALY IT IS NOT NOT USED" isn't true :).
IMO it is sill possible add general rule "allways use Lindent" because indent can be dissabled/enabled aroud code inccorectly formated by add control comments like:
/* *INDENT-OFF* */
/* *INDENT-ON* */
If it will be widely used probably it will allow better identify some indent problems.
kloczek
Signature · 4 lines
----------------------------------------------------------- *Ludzie nie mają problemów, tylko sobie sami je stwarzają* ----------------------------------------------------------- Tomasz Kłoczko, sys adm @zie.pg.gda.pl|*e-mail: [email protected]*
Lindent cleanup (was Re: [PATCH] drivers: Conversions from kmalloc+memset to k(z|c)alloc.)
Quoted 9 lines · Tomasz Kłoczko
On Mon, 24 Jul 2006, Tomasz Kłoczko wrote:
[..]Quoted 2 lines
In all other/most of cases (probably ~99%) Lindetd can be used .. but for NOW GENERALY IT IS NOT NOT USED.
I'm just look on number changed fles by Lindent. diffstat shows 14593 changed files. Number of all *.[ch] files is 16028. So it shows now ~9% all files passes cleanly indentation using Lindent (my above "GENERALY IT IS NOT NOT USED" isn't true :).
You already posted a good step-by-step proposal. I suggest another slightly different approach:
People who are interested to help out should just go systematically through subsystems and drivers, run them through Lindent, check and perhaps beautify the output, and submit the resulting patches in a form and to the appropriate addresses as usual (i.e. sensibly broken-up patches, submitted to subsystem mailinglists and maintainers).
Whenever manual corrections after Lindent were necessary and whenever there will be objections by reviewers to Lindent's results, take this feedback as input for the two discussions about
- consensus about preferred style, i.e. refinement of CodingStyle,
- possible improvements of Lindent.
These discussions should of course take place at LKML instead of subsystem mailinglists.
Quoted 9 lines
IMO it is sill possible add general rule "allways use Lindent" because indent can be dissabled/enabled aroud code inccorectly formated by add control comments like:
/* *INDENT-OFF* */
/* *INDENT-ON* */If it will be widely used probably it will allow better identify some indent problems.
IMHO: Write code for cpp, cc, as --- but not for any other processor-de-jour. All those processors (formatters, checkers etc.) are fine to *inspect* code for formal or semantic problems. But this should not lead to thousands more or less obscure processor keywords sprinkled all over the sources --- bloating them and making them confusing.
Signature · 3 lines
Stefan Richter -=====-=-==- -=== ==--- http://arcgraph.de/sr/
Re: Lindent cleanup (was Re: [PATCH] drivers: Conversions from kmalloc+memset to k(z|c)alloc.)
On Mon, 24 Jul 2006, Stefan Richter wrote:
[..]
Quoted 7 lines
Quoted 7 lines
IMO it is sill possible add general rule "allways use Lindent" because indent can be dissabled/enabled aroud code inccorectly formated by add control comments like:
/* *INDENT-OFF* */
/* *INDENT-ON* */
Quoted 8 lines
Quoted 2 lines
If it will be widely used probably it will allow better identify some indent problems.
IMHO: Write code for cpp, cc, as --- but not for any other processor-de-jour. All those processors (formatters, checkers etc.) are fine to *inspect* code for formal or semantic problems. But this should not lead to thousands more or less obscure processor keywords sprinkled all over the sources --- bloating them and making them confusing.
*If* it will be allowed by some kind of coding style rules IMO use indent control comments will be good use *only* for files (not for piece of files) for mark by subsystem maintainer "don't touch this using formaters without inform me". IMO allow formating only below main level Linux kernel developers (read: below Linus & close co. :) will only make this process longer (read: less effective). Time neccessary for make progress from current ~10% to ~90% is in this case very importand (will allow cut amount of flames ;).
Finally probably best will be good add point in release procedure something like: "use on whole tree Lindent and commit changes before bump to final release". Only first this kind patch will be very huge. All other will be small or very small.
IMO for good start for above will be send to all Linux maintainers kind plain message for try review changes produced by Lindent (by add to announce message small comment about this). Only after this IMO it will be possible good disscuss on current indend rules.
Anyway .. disscuss on subject without this people will be pointless.
I'll try to monitor diffstat for each next release and generate
kind of "status: using Lindent on curent Linux tree". Probably this can help on using indent on Linux tree.
kloczek
Signature · 4 lines
----------------------------------------------------------- *Ludzie nie mają problemów, tylko sobie sami je stwarzają* ----------------------------------------------------------- Tomasz Kłoczko, sys adm @zie.pg.gda.pl|*e-mail: [email protected]*
Quoted 2 lines · Jeff Garzik
Quoted 1 line · Tomasz Kłoczko
Moment .. are you want to say something like "keep commont coding style can't be maintained by tool" ?
Yes and no.
Quoted 7 lines
Quoted 1 line
Even if indent watches on to small coding style emenets still I don't see why using this tool isn't one of the current ement of release procedure (?).
indent isn't perfect, _especially_ where C99 comes into the picture.
And running indent across the tree pre-release would (a) create a ton of noise before each release, and (b) undo perfectly valid, readable formatting.
scripts/Lindentexists and gets used, but it is not perfect.
Tomasz,
yes, we have scripts/Lindent, but it cannot and is not supposed to solve all style issues. Coding style is about _much_ more than whitespace. It includes sensible names, usage of language features...
Furthermore, much of this thread revolved around style issues where a common coding style is not fully established in the first place.
Signature · 3 lines
Stefan Richter -=====-=-==- -=== =-=== http://arcgraph.de/sr/
On Sun, 23 Jul 2006, Stefan Richter wrote:
[..]
Quoted 3 lines
Tomasz,
yes, we have
scripts/Lindent, but it cannot and is not supposed to solve all style issues. Coding style is about _much_ more than whitespace. It includes sensible names, usage of language features...
Yes .. I know about this but it can allow plug some subset of current coding style problems. Prodicing Perfect-Word in sigle step is probably impossible but start this step by step will be probably rationale :)
Look below is it not will be good now start:
1) review current tree for fix/change code allow pass throw indent without errors and commit all neccessary for this changes,
2) produce diff for whole source tree and start disscuss on "are current Lindent script indentation rules are correct or not ?",
3) after prepare acceptable by Linus indent rules set setup kind of moratory for all (co)developers for submitting indentation changes during normal changes submission (month or even half year but IMo shorter will be better),
4) aftter passing moratory date Linus can commit all pending changes in single commit.
??
kloczek
Signature · 4 lines
----------------------------------------------------------- *Ludzie nie mają problemów, tylko sobie sami je stwarzają* ----------------------------------------------------------- Tomasz Kłoczko, sys adm @zie.pg.gda.pl|*e-mail: [email protected]*
Quoted 4 lines · Jesper Juhl
Quoted 1 line · Stefan Richter
- better style of the size argument where correct,
Who says it's "better style" ?
I correct myself: s/better/conforming/
Signature · 3 lines
Stefan Richter -=====-=-==- -=== =--== http://arcgraph.de/sr/
Quoted 4 lines · I wrote:
Quoted 1 line · Jesper Juhl
Who says it's "better style" ?
I correct myself: s/better/conforming/
PS: By which I don't want to deny that this style may have objective benefits.
Signature · 3 lines
Stefan Richter -=====-=-==- -=== =--== http://arcgraph.de/sr/
Quoted 19 lines · Jesper Juhl
Quoted 11 lines · Stefan Richter
Quoted 3 lines · Jeff Garzik
Quoted 2 lines · Pekka Enberg
Quoted 1 line · Rolf Eike Beer
Quoted 1 line
- if (!(handle = kmalloc(sizeof(struct
input_handle),
GFP_KERNEL)))Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/char/keyboard.c static struct input_handle *kbd_connect( · line 1303
Quoted 3 lines
drivers/char/keyboard.c +2
-0+ handle =kzalloc (sizeof (struct input_handle ),GFP_KERNEL ); +if (!handle)return NULL ;
sizeof(*handle)?Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
In general, yes. However, some maintainers don't like that, so I would recommend to keep them as-is unless you get a clear ack from the maintainer to change it.
I suggest:
- check if "sizeof(type)"->"sizeof(*ptr)" is correct
- if yes, change it
Quoted 7 lines
[snip]
Quoted 1 line
- better style of the size argument where correct,
Who says it's "better style" ?
You can argue that sizeof(type) is more readable.
When reading the code you don't have to go lookup the type of ptr insizeof(*ptr)before you know what type the code is working with.
All the more reason that such changes -- unrelated to kzalloc/kcalloc conversion -- should be in a separate patch.
Jeff
Quoted 12 lines · Stefan Richter
Quoted 10 lines · Jeff Garzik
Quoted 9 lines · Pekka Enberg
Quoted 5 lines · Rolf Eike Beer
drivers/char/keyboard.c static struct input_handle *kbd_connect( · line 1303
Quoted 4 lines
drivers/char/keyboard.c +2
-1-if (!(handle =kmalloc (sizeof (struct input_handle ),GFP_KERNEL ))) + handle =kzalloc (sizeof (struct input_handle ),GFP_KERNEL ); +if (!handle)return NULL ;
sizeof(*handle)?In general, yes. However, some maintainers don't like that, so I would recommend to keep them as-is unless you get a clear ack from the maintainer to change it.
Quoted 6 lines
I suggest:
- check if "sizeof(type)"->"sizeof(*ptr)" is correct
- if yes, change it
- do this for all kmalloc + kzalloc in a file you touched, or better yet for all kmalloc + kzalloc in a driver or subsystem you touched
This breaks the rules of standard Linux patches.
The patch should contain ONE logical change. Any cleanups such as sizeof(type) -> sizeof(*ptr) should be in a SEPARATE PATCH.
Jeff
Quoted 1 line · Jeff Garzik
The patch should contain ONE logical change.
Definitely yes. The problem is to figure out what "one" is.
I already posted what I considered one logical change in this case and why I did: It's an idiomatic makeover of k*alloc calls without change in functionality. What breaks my counting of "one" is that unwritten rules about preferred idioms (are said to) override written rules.
Signature · 3 lines
Stefan Richter -=====-=-==- -=== =-==- http://arcgraph.de/sr/
Re: [PATCH] drivers: Conversions from kmalloc+memset tok(z|c)alloc.
In reply to Jeff GarzikHi,
Quoted 9 lines · Jeff Garzik
Quoted 8 lines · Pekka Enberg
Quoted 6 lines · Rolf Eike Beer
drivers/char/keyboard.c static struct input_handle *kbd_connect( · line 1303
Quoted 4 lines
drivers/char/keyboard.c +2
-1-if (!(handle =kmalloc (sizeof (struct input_handle ),GFP_KERNEL ))) + handle =kzalloc (sizeof (struct input_handle ),GFP_KERNEL ); +if (!handle)return NULL ;
sizeof(*handle)?
Quoted 7 lines
Quoted 3 lines
In general, yes. However, some maintainers don't like that, so I would recommend to keep them as-is unless you get a clear ack from the maintainer to change it.
Strongly agreed. Follow the style of the existing code as closely as possible, and resist the temptation of making little "improvements" while you are doing a task...
Ah okay. Up until now, I thought it would be okay to change the style of the code if it was listed in the CodingStyle document and in any other cause should be left untouched as it would be left to the maintainers personal preference. That's why I explicitly asked about the "if ((buf = kmalloc(...)==NULL) -> buf = kmalloc(...); if (!buf)" type of changes.
Ofcourse, I should have put cosmetic changes in a separate patch anyway.
With friendly regards,
Takis
Re: [PATCH] drivers: Conversions from kmalloc+memset tok(z|c)alloc.
Quoted 7 lines · Panagiotis Issaris
Ah okay. Up until now, I thought it would be okay to change the style of the code if it was listed in the CodingStyle document and in any other cause should be left untouched as it would be left to the maintainers personal preference. That's why I explicitly asked about the "if ((buf = kmalloc(...)==NULL) -> buf = kmalloc(...); if (!buf)" type of changes.
Ofcourse, I should have put cosmetic changes in a separate patch anyway.
At least Andrew seems to prefer cleaning up in the same patch. Anyway, I don't think Jeff meant that you shouldn't do any cleanups, but that you should try to respect the existing style as much possible. There are things that are almost generally agreed upon, such as removal of redundant typecasts, redundant wrappers, and moving assignment out of if statement expression. Formatting and the dreaded sizeof thing, however, are not, so it is best to keep them as-is.
Pekka
Re: [PATCH] drivers: Conversions from kmalloc+memset tok(z|c)alloc.
Quoted 9 lines · Pekka J Enberg
Quoted 7 lines · Panagiotis Issaris
Ah okay. Up until now, I thought it would be okay to change the style of the code if it was listed in the CodingStyle document and in any other cause should be left untouched as it would be left to the maintainers personal preference. That's why I explicitly asked about the "if ((buf = kmalloc(...)==NULL) -> buf = kmalloc(...); if (!buf)" type of changes.
Ofcourse, I should have put cosmetic changes in a separate patch anyway.
Quoted 7 lines
At least Andrew seems to prefer cleaning up in the same patch. Anyway, I don't think Jeff meant that you shouldn't do any cleanups, but that you should try to respect the existing style as much possible. There are things that are almost generally agreed upon, such as removal of redundant typecasts, redundant wrappers, and moving assignment out of if statement expression. Formatting and the dreaded sizeof thing, however, are not, so it is best to keep them as-is.
Thank God! I had been preparing such a cleanup patch for several hours last night :)
With friendly regards,
Takis
Re: [PATCH] drivers: Conversions from kmalloc+memset tok(z|c)alloc.
In reply to Pekka J EnbergQuoted 3 lines · Pekka J Enberg
At least Andrew seems to prefer cleaning up in the same patch. Anyway, I don't think Jeff meant that you shouldn't do any cleanups, but that you should try to respect the existing style as much possible.
First and foremost, respect that the Linux sources need to have a minimum level of stylistic uniformity.
Quoted 5 lines
There are
things that are almost generally agreed upon, such as removal of redundant typecasts, redundant wrappers, and moving assignment out of if statement expression. Formatting and the dreaded sizeof thing, however, are not, so it is best to keep them as-is.
Contributors can't know what the (supposed) _agreements_ are.
Contributors can only know what the _documented conventions_ are.
Signature · 3 lines
Stefan Richter -=====-=-==- -=== =--== http://arcgraph.de/sr/
Re: [PATCH] drivers: Conversions from kmalloc+memset tok(z|c)alloc.
Quoted 4 lines · At some point in time, I wrote:
Quoted 4 lines
There are things that are almost generally agreed upon, such as removal of redundant typecasts, redundant wrappers, and moving assignment out of if statement expression. Formatting and the dreaded sizeof thing, however, are not, so it is best to keep them as-is.
Quoted 3 lines · Stefan Richter
Contributors can't know what the (supposed) _agreements_ are.
Contributors can only know what the
_documentedconventions_are.
Life gets easier when you accept the fact that there are different conventions within the kernel, driven by maintainer preference. Which is why it is impossible to document a definite set of conventions too. CodingStyle really is just a good approximation what kernel code should look like. If you deviate from it too much, everyone agrees that you're violating it, but there definitely is room for maintainer preference. As a contributor, when you accept that, you'll have much greater chances of getting your patches merged.
Pekka
Re: [PATCH] drivers: Conversions from kmalloc+memset tok(z|c)alloc.
Quoted 9 lines · Pekka J Enberg
Quoted 3 lines · Stefan Richter
Contributors can't know what the (supposed) _agreements_ are.
Contributors can only know what the
_documentedconventions_are.Life gets easier when you accept the fact that there are different conventions within the kernel, driven by maintainer preference. Which is why it is impossible to document a definite set of conventions too. CodingStyle really is just a good approximation
[...]
What can a contributor do when he comes across code which deviates from CodingStyle? He cannot tell whether the initial developer wasn't forced to adhere to CodingStyle or the maintainer wants it that way. So, the contributor
- could ask the maintainer for his ruleset before writing a patch, or
- could simply write the patch and wait if the maintainer feels need to demand adjustments.
I am not sure which strategy will consume less time of contributor and maintainer.
Signature · 3 lines
Stefan Richter -=====-=-==- -=== =--== http://arcgraph.de/sr/
Re: [PATCH] drivers: Conversions from kmalloc+memset tok(z|c)alloc.
In reply to Pekka J EnbergQuoted 10 lines · Pekka J Enberg
Quoted 7 lines · Panagiotis Issaris
Ah okay. Up until now, I thought it would be okay to change the style of the code if it was listed in the CodingStyle document and in any other cause should be left untouched as it would be left to the maintainers personal preference. That's why I explicitly asked about the "if ((buf = kmalloc(...)==NULL) -> buf = kmalloc(...); if (!buf)" type of changes.
Ofcourse, I should have put cosmetic changes in a separate patch anyway.
At least Andrew seems to prefer cleaning up in the same patch. Anyway, I don't think Jeff meant that you shouldn't do any cleanups, but that you should try to respect the existing style as much possible.
Correct.
Jeff
Quoted 17 lines · Rolf Eike Beer
Am Donnerstag, 20. Juli 2006 21:05 schrieb Panagiotis Issaris:
Quoted 4 lines
drivers/char/consolemap.c +0
-0@@ -443,12 +442,11 @@ int con_clear_unimap(struct vc_data *vc, p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;if (p && p->readonly)return -EIO ;if (!p || --p->refcount) {drivers/char/consolemap.c int con_clear_unimap(struct vc_data *vc, · line 452
Quoted 10 lines
drivers/char/consolemap.c +1
-2- q = (struct uni_pagedir *)kmalloc (sizeof (*p),GFP_KERNEL ); + q =kzalloc (sizeof (*p),GFP_KERNEL );if (!q) {if (p) p->refcount++;return -ENOMEM ; } -memset (q,0 ,sizeof (*q)); q->refcount=1 ; *vc->vc_uni_pagedir_loc = (unsigned long )q; }else {This one still changes the way the code works. Before your patch *p will be always zeroed out. Now if p is there before it will keep it's contents.
No, it doesn't, the data at *p is/was not zeroed inside the if { .. } block. Read carefully, the multiple statements on one line obfuscations might have thrown you off.
However, it is slightly confusing that the value assigned to `q' is kzalloced using sizeof(*p). It is an improvement though, as the old version kmalloced using sizeof(*p), and memset using sizeof(*q).
That was really strange.
Daniel K.
Hi,
Quoted 17 lines · Rolf Eike Beer
[...]
Space after comma.
[...]sizeof(*ltp)?[more of this snipped]
Quoted 9 lines
drivers/char/consolemap.c +1
-1@@ -443,12 +442,11 @@ int con_clear_unimap(struct vc_data *vc, p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;if (p && p->readonly)return -EIO ;if (!p || --p->refcount) { - q = (struct uni_pagedir *)kmalloc (sizeof (*p),GFP_KERNEL ); + q =kzalloc (sizeof (*p),GFP_KERNEL );if (!q) {if (p) p->refcount++;return -ENOMEM ;
Quoted 8 lines
drivers/char/consolemap.c int con_clear_unimap(struct vc_data *vc, · line 452
Quoted 5 lines
drivers/char/consolemap.c +0
-1} -memset (q,0 ,sizeof (*q)); q->refcount=1 ; *vc->vc_uni_pagedir_loc = (unsigned long )q; }else {This one still changes the way the code works. Before your patch *p will be always zeroed out. Now if p is there before it will keep it's contents.
Hmm. I do not really see the functional change here: If the memory allocation failed, then in both cases, q will be zero and the function will return. If the memory allocation succeeds, then in both cases a memset will occur. Is it more subtle than that?
Before change:
if (!p || --p->refcount) {
q = kmalloc(sizeof(*p), GFP_KERNEL);
if (!q) {
if (p)
p->refcount++;
return -ENOMEM;
}
memset(q, 0, sizeof(*q));
q->refcount=1;
*vc->vc_uni_pagedir_loc = (unsigned long)q;
}After change:
if (!p || --p->refcount) {
q = kzalloc(sizeof(*p), GFP_KERNEL);
if (!q) {
if (p)
p->refcount++;
return -ENOMEM;
}
q->refcount=1;
*vc->vc_uni_pagedir_loc = (unsigned long)q;
}If !p then in both cases, q will be assigned some memory, and if that succeeds, the block of memory will be cleared, if it fails, it will not be cleared and the function will exit.
If p then if --p->refcount<>0, a new block will be allocated and if the allocation succeeds, it will be cleared in both cases. If --p->refcount==0, nothing will be allocated nor cleared, in both cases.
With friendly regards,
Takis
Quoted 19 lines · Panagiotis Issaris
Quoted 10 lines
Quoted 10 lines
drivers/char/consolemap.c +1
-1@@ -443,12 +442,11 @@ int con_clear_unimap(struct vc_data *vc, p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;if (p && p->readonly)return -EIO ;if (!p || --p->refcount) { - q = (struct uni_pagedir *)kmalloc (sizeof (*p),GFP_KERNEL ); + q =kzalloc (sizeof (*p),GFP_KERNEL );if (!q) {if (p) p->refcount++;return -ENOMEM ; }Quoted 8 lines
drivers/char/consolemap.c int con_clear_unimap(struct vc_data *vc, · line 452
Quoted 4 lines
drivers/char/consolemap.c +0
-1-memset (q,0 ,sizeof (*q)); q->refcount=1 ; *vc->vc_uni_pagedir_loc = (unsigned long )q; }else {This one still changes the way the code works. Before your patch *p will be always zeroed out. Now if p is there before it will keep it's contents.
Quoted 4 lines
Hmm. I do not really see the functional change here: If the memory allocation failed, then in both cases, q will be zero and the function will return. If the memory allocation succeeds, then in both cases a memset will occur. Is it more subtle than that?
You're right, I got somehow confused by this p and q stuff.
Eike
Quoted 4 lines · Panagiotis Issaris
From: Panagiotis Issaris <[email protected]>
drivers: Conversions from kmalloc+memset to k(z|c)alloc.
Quoted 8 lines
Signed-off-by Panagiotis Issaris <[email protected]>---
Second editiondrivers/acpi/hotkey.c | 6 ++---- drivers/atm/zatm.c | 6 ++---- drivers/char/consolemap.c | 6 ++---- drivers/char/keyboard.c | 4 ++--
Hi,
Could you please drop drivers/char/keyboard.c changes? I already have patch in my queue that does kzalloc conversion there (among other things).
Thanks!
Signature · 1 line
Dmitry
Hi,
Quoted 14 lines · Dmitry Torokhov
Quoted 4 lines · Panagiotis Issaris
From: Panagiotis Issaris <[email protected]>
drivers: Conversions from kmalloc+memset to k(z|c)alloc.
Quoted 8 lines
Signed-off-by Panagiotis Issaris <[email protected]>---
Second editiondrivers/acpi/hotkey.c | 6 ++---- drivers/atm/zatm.c | 6 ++---- drivers/char/consolemap.c | 6 ++---- drivers/char/keyboard.c | 4 ++--
Quoted 7 lines
Hi,
Could you please drop
drivers/char/keyboard.cchanges? I already have patch in my queue that does kzalloc conversion there (among other things).Thanks!
Ofcourse! Consider it done! :)
With friendly regards,
Takis