--- initial
+++ final
@@ -1,161 +1,160 @@
 static int __init pcidev_init(struct pci_dev *pdev, const struct pci_device_id *id) {
   struct net_device *dev;
   struct dev_priv *priv;
   struct dev_info *hw_priv;
   struct ksz_hw *hw;
   struct platform_info *info;
   struct ksz_port *port;
   unsigned long reg_base;
   unsigned long reg_len;
   int cnt;
   int i;
   int mib_port_count;
   int pi;
   int port_count;
   int result;
   char banner[sizeof(version)];
   struct ksz_switch *sw = NULL;
   result = pci_enable_device(pdev);
   if (result) return result;
   result = -ENODEV;
   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) || pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) return result;
   reg_base = pci_resource_start(pdev, 0);
   reg_len = pci_resource_len(pdev, 0);
   if ((pci_resource_flags(pdev, 0) & IORESOURCE_IO) != 0) return result;
   if (!request_mem_region(reg_base, reg_len, DRV_NAME)) return result;
   pci_set_master(pdev);
   result = -ENOMEM;
   info = kzalloc(sizeof(struct platform_info), GFP_KERNEL);
   if (!info) goto pcidev_init_dev_err;
   hw_priv = &info->dev_info;
   hw_priv->pdev = pdev;
   hw = &hw_priv->hw;
   hw->io = ioremap(reg_base, reg_len);
   if (!hw->io) goto pcidev_init_io_err;
   cnt = hw_init(hw);
   if (!cnt) {
     if (msg_enable & NETIF_MSG_PROBE) pr_alert("chip not detected\n");
     result = -ENODEV;
     goto pcidev_init_alloc_err;
   }
   snprintf(banner, sizeof(banner), "%s", version);
   banner[13] = cnt + '0'; /* Replace x in "Micrel KSZ884x" */
   dev_info(&hw_priv->pdev->dev, "%s\n", banner);
   dev_dbg(&hw_priv->pdev->dev, "Mem = %p; IRQ = %d\n", hw->io, pdev->irq);
   /* Assume device is KSZ8841. */
   hw->dev_count = 1;
   port_count = 1;
   mib_port_count = 1;
   hw->addr_list_size = 0;
   hw->mib_cnt = PORT_COUNTER_NUM;
   hw->mib_port_cnt = 1;
   /* KSZ8842 has a switch with multiple ports. */
   if (2 == cnt) {
     if (fast_aging) hw->overrides |= FAST_AGING;
     hw->mib_cnt = TOTAL_PORT_COUNTER_NUM;
     /* Multiple network device interfaces are required. */
     if (multi_dev) {
       hw->dev_count = SWITCH_PORT_NUM;
       hw->addr_list_size = SWITCH_PORT_NUM - 1;
     }
     /* Single network device has multiple ports. */
     if (1 == hw->dev_count) {
       port_count = SWITCH_PORT_NUM;
       mib_port_count = SWITCH_PORT_NUM;
     }
     hw->mib_port_cnt = TOTAL_PORT_NUM;
-    hw->ksz_switch = kmalloc(sizeof(struct ksz_switch), GFP_KERNEL);
+    hw->ksz_switch = kzalloc(sizeof(struct ksz_switch), GFP_KERNEL);
     if (!hw->ksz_switch) goto pcidev_init_alloc_err;
-    memset(hw->ksz_switch, 0, sizeof(struct ksz_switch));
     sw = hw->ksz_switch;
   }
   for (i = 0; i < hw->mib_port_cnt; i++)
     hw->port_mib[i].mib_start = 0;
   hw->parent = hw_priv;
   /* Default MTU is 1500. */
   hw_priv->mtu = (REGULAR_RX_BUF_SIZE + 3) & ~3;
   if (ksz_alloc_mem(hw_priv)) goto pcidev_init_mem_err;
   hw_priv->hw.id = net_device_present;
   spin_lock_init(&hw_priv->hwlock);
   mutex_init(&hw_priv->lock);
   /* tasklet is enabled. */
   tasklet_init(&hw_priv->rx_tasklet, rx_proc_task, (unsigned long)hw_priv);
   tasklet_init(&hw_priv->tx_tasklet, tx_proc_task, (unsigned long)hw_priv);
   /* tasklet_enable will decrement the atomic counter. */
   tasklet_disable(&hw_priv->rx_tasklet);
   tasklet_disable(&hw_priv->tx_tasklet);
   for (i = 0; i < TOTAL_PORT_NUM; i++)
     init_waitqueue_head(&hw_priv->counter[i].counter);
   if (macaddr[0] != ':') get_mac_addr(hw_priv, macaddr, MAIN_PORT);
   /* Read MAC address and initialize override address if not overrided. */
   hw_read_addr(hw);
   /* Multiple device interfaces mode requires a second MAC address. */
   if (hw->dev_count > 1) {
     memcpy(sw->other_addr, hw->override_addr, MAC_ADDR_LEN);
     read_other_addr(hw);
     if (mac1addr[0] != ':') get_mac_addr(hw_priv, mac1addr, OTHER_PORT);
   }
   hw_setup(hw);
   if (hw->ksz_switch)
     sw_setup(hw);
   else {
     hw_priv->wol_support = WOL_SUPPORT;
     hw_priv->wol_enable = 0;
   }
   INIT_WORK(&hw_priv->mib_read, mib_read_work);
   /* 500 ms timeout */
   ksz_init_timer(&hw_priv->mib_timer_info, 500 * HZ / 1000, mib_monitor, hw_priv);
   for (i = 0; i < hw->dev_count; i++) {
     dev = alloc_etherdev(sizeof(struct dev_priv));
     if (!dev) goto pcidev_init_reg_err;
     info->netdev[i] = dev;
     priv = netdev_priv(dev);
     priv->adapter = hw_priv;
     priv->id = net_device_present++;
     port = &priv->port;
     port->port_cnt = port_count;
     port->mib_port_cnt = mib_port_count;
     port->first_port = i;
     port->flow_ctrl = PHY_FLOW_CTRL;
     port->hw = hw;
     port->linked = &hw->port_info[port->first_port];
     for (cnt = 0, pi = i; cnt < port_count; cnt++, pi++) {
       hw->port_info[pi].port_id = pi;
       hw->port_info[pi].pdev = dev;
       hw->port_info[pi].state = media_disconnected;
     }
     dev->mem_start = (unsigned long)hw->io;
     dev->mem_end = dev->mem_start + reg_len - 1;
     dev->irq = pdev->irq;
     if (MAIN_PORT == i)
       memcpy(dev->dev_addr, hw_priv->hw.override_addr, MAC_ADDR_LEN);
     else {
       memcpy(dev->dev_addr, sw->other_addr, MAC_ADDR_LEN);
       if (!memcmp(sw->other_addr, hw->override_addr, MAC_ADDR_LEN)) dev->dev_addr[5] += port->first_port;
     }
     dev->netdev_ops = &netdev_ops;
     SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
     if (register_netdev(dev)) goto pcidev_init_reg_err;
     port_set_power_saving(port, true);
   }
   pci_dev_get(hw_priv->pdev);
   pci_set_drvdata(pdev, info);
   return 0;
 pcidev_init_reg_err:
   for (i = 0; i < hw->dev_count; i++) {
     if (info->netdev[i]) {
       netdev_free(info->netdev[i]);
       info->netdev[i] = NULL;
     }
   }
 pcidev_init_mem_err:
   ksz_free_mem(hw_priv);
   kfree(hw->ksz_switch);
 pcidev_init_alloc_err:
   iounmap(hw->io);
 pcidev_init_io_err:
   kfree(info);
 pcidev_init_dev_err:
   release_mem_region(reg_base, reg_len);
   return result;
 }<sep>@@
expression e1,e2,e3;
identifier print1,print2;
constant char[] c1;
constant char[] c2;
statement S;
@@

-       e3 = kmalloc(e1, e2)
+       e3 = kzalloc(e1, e2)
        <... when != e3
(
	print1(...,c1,...,e3,...);
|
	kfree(e3);
)
       ...>
        if (e3 == NULL || ...) S
        <... when != e3
(
	print2(...,c2,...,e3,...);
|
	kfree(e3);
)
        ...>
-       memset(e3, 0, e1);