Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ATM-iphase: Use kmalloc_array() in tx_init()

* Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of data types by pointer dereferences
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Markus Elfring and committed by
David S. Miller
e808bb6e 171a6c52

+9 -4
+9 -4
drivers/atm/iphase.c
··· 1975 1975 buf_desc_ptr++; 1976 1976 tx_pkt_start += iadev->tx_buf_sz; 1977 1977 } 1978 - iadev->tx_buf = kmalloc(iadev->num_tx_desc*sizeof(struct cpcs_trailer_desc), GFP_KERNEL); 1978 + iadev->tx_buf = kmalloc_array(iadev->num_tx_desc, 1979 + sizeof(*iadev->tx_buf), 1980 + GFP_KERNEL); 1979 1981 if (!iadev->tx_buf) { 1980 1982 printk(KERN_ERR DEV_LABEL " couldn't get mem\n"); 1981 1983 goto err_free_dle; ··· 1997 1995 sizeof(*cpcs), 1998 1996 DMA_TO_DEVICE); 1999 1997 } 2000 - iadev->desc_tbl = kmalloc(iadev->num_tx_desc * 2001 - sizeof(struct desc_tbl_t), GFP_KERNEL); 1998 + iadev->desc_tbl = kmalloc_array(iadev->num_tx_desc, 1999 + sizeof(*iadev->desc_tbl), 2000 + GFP_KERNEL); 2002 2001 if (!iadev->desc_tbl) { 2003 2002 printk(KERN_ERR DEV_LABEL " couldn't get mem\n"); 2004 2003 goto err_free_all_tx_bufs; ··· 2127 2124 memset((caddr_t)(iadev->seg_ram+i), 0, iadev->num_vc*4); 2128 2125 vc = (struct main_vc *)iadev->MAIN_VC_TABLE_ADDR; 2129 2126 evc = (struct ext_vc *)iadev->EXT_VC_TABLE_ADDR; 2130 - iadev->testTable = kmalloc(sizeof(long)*iadev->num_vc, GFP_KERNEL); 2127 + iadev->testTable = kmalloc_array(iadev->num_vc, 2128 + sizeof(*iadev->testTable), 2129 + GFP_KERNEL); 2131 2130 if (!iadev->testTable) { 2132 2131 printk("Get freepage failed\n"); 2133 2132 goto err_free_desc_tbl;