Transform kzalloc calls to kcalloc
Subsystems (5)
v2 cover Transform kzalloc calls to kcalloc
[changes in v2]
In version v2, I break the original patchset into two. One for kmalloc -> k{z,c}alloc and other for kzalloc -> kcalloc. This patchset includes patches for kzalloc to kmalloc conversion.
[original cover letter]
This patchset changes some kzalloc calls to kcalloc and kmalloc to kzalloc.
The semantic patch used to make this change is:
@@
type T, T2;
expression x;
identifier f,f1;
expression E1,E2,E3,E4;
statement S,S1,S2;
@@
- x = (T)kmalloc(E1,E2)
+ x = kzalloc(E1,E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
if ((x!=NULL)&&...) {
... when != \(f1(...,x,...)\|<+...x...+>=E4\)
when != \(while(...) S1\|for(...;...;...) S1\)
- memset((T2)x,0,E1);
...
} else S2
|
- memset((T2)x,0,E1);
)
@@
type T, T2;
type T1;
T1 *x;
T1 *y;
identifier f,f1;
expression E2,E3,E4;
statement S,S1,S2;
@@
- x = (T)kmalloc(sizeof(T1),E2)
+ x = kzalloc(sizeof(T1),E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
if ((x!=NULL)&&...) {
... when != \(f1(...,x,...)\|<+...x...+>=E4\)
when != \(while(...) S1\|for(...;...;...) S1\)
- memset((T2)x,0,sizeof(*y));
...
} else S2
|
- memset((T2)x,0,sizeof(*y));
)
@@
type T, T2;
type T1;
T1 *x;
T1 *y;
identifier f,f1;
expression E,E2,E3,E4;
statement S,S1,S2;
@@
- x = (T)kmalloc(sizeof(T1)*E,E2)
+ x = kzalloc(sizeof(T1)*E,E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
if ((x!=NULL)&&...) {
... when != \(f1(...,x,...)\|<+...x...+>=E4\)
when != \(while(...) S1\|for(...;...;...) S1\)
- memset((T2)x,0,sizeof(*y)*E);
...
} else S2
|
- memset((T2)x,0,sizeof(*y)*E);
)
@@
type T, T2;
type T1;
T1 *x;
T1 *y;
identifier f,f1;
expression E2,E3,E4;
statement S,S1,S2;
@@
- x = (T)kmalloc(sizeof(*y),E2)
+ x = kzalloc(sizeof(*y),E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
if ((x!=NULL)&&...) {
... when != \(f1(...,x,...)\|<+...x...+>=E4\)
when != \(while(...) S1\|for(...;...;...) S1\)
- memset((T2)x,0,sizeof(T1));
...
} else S2
|
- memset((T2)x,0,sizeof(T1));
)
@@
type T, T2;
type T1;
T1 *x;
T1 *y;
identifier f,f1;
expression E,E2,E3,E4;
statement S,S1,S2;
@@
- x = (T)kmalloc(sizeof(*y)*E,E2)
+ x = kzalloc(sizeof(*y)*E,E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
if ((x!=NULL)&&...) {
... when != \(f1(...,x,...)\|<+...x...+>=E4\)
when != \(while(...) S1\|for(...;...;...) S1\)
- memset((T2)x,0,sizeof(T1)*E);
...
} else S2
|
- memset((T2)x,0,sizeof(T1)*E);
)
@ disable neg_if, mult_comm @
type T, T2;
expression x;
identifier f,f1;
expression E0,E1,E2,E3,E4;
statement S,S1,S2;
@@
- x = (T)kmalloc(E0 * E1,E2)
+ x = kzalloc(E0 * E1,E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
if ((x!=NULL)&&...) {
... when != \(f1(...,x,...)\|<+...x...+>=E4\)
when != \(while(...) S1\|for(...;...;...) S1\)
- memset((T2)x,0,E1 * E0);
...
} else S2
|
- memset((T2)x,0,E1 * E0);
)
// --------------------------------------------------------------------- // --------------------------------------------------------------------- // have to duplicate everything again to make a version with no braces //\(x->fld\|f(...,x,...)\|x=E\)
@@
type T, T2;
expression x;
identifier f;
expression E1,E2,E3;
statement S,S2;
@@
- x = (T)kmalloc(E1,E2)
+ x = kzalloc(E1,E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
- if ((x!=NULL)&&...) memset((T2)x,0,E1);
|
+ if (!x)
- if ((x!=NULL)&&...) memset((T2)x,0,E1); else
S2
)
@ @
type T, T2;
type T1;
T1 *x;
T1 *y;
identifier f;
expression E2,E3;
statement S,S2;
@@
- x = (T)kmalloc(sizeof(T1),E2)
+ x = kzalloc(sizeof(T1),E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
- if ((x!=NULL)&&...) memset((T2)x,0,sizeof(*y));
|
+ if (!x)
- if ((x!=NULL)&&...) memset((T2)x,0,sizeof(*y)); else
S2
)
@@
type T, T2;
type T1;
T1 *x;
T1 *y;
identifier f;
expression E,E2,E3;
statement S,S2;
@@
- x = (T)kmalloc(sizeof(T1)*E,E2)
+ x = kzalloc(sizeof(T1)*E,E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
- if ((x!=NULL)&&...) memset((T2)x,0,sizeof(*y)*E);
|
+ if (!x)
- if ((x!=NULL)&&...) memset((T2)x,0,sizeof(*y)*E); else
S2
)
@@
type T, T2;
type T1;
T1 *x;
T1 *y;
identifier f;
expression E2,E3;
statement S,S2;
@@
- x = (T)kmalloc(sizeof(*y),E2)
+ x = kzalloc(sizeof(*y),E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
- if ((x!=NULL)&&...) memset((T2)x,0,sizeof(T1));
|
+ if (!x)
- if ((x!=NULL)&&...) memset((T2)x,0,sizeof(T1)); else
S2
)
@@
type T, T2;
type T1;
T1 *x;
T1 *y;
identifier f;
expression E,E2,E3;
statement S,S2;
@@
- x = (T)kmalloc(sizeof(*y)*E,E2)
+ x = kzalloc(sizeof(*y)*E,E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
- if ((x!=NULL)&&...) memset((T2)x,0,sizeof(T1)*E);
|
+ if (!x)
- if ((x!=NULL)&&...) memset((T2)x,0,sizeof(T1)*E); else
S2
)
@ disable neg_if, mult_comm @
type T, T2;
expression x;
identifier f;
expression E0,E1,E2,E3;
statement S,S2;
@@
- x = (T)kmalloc(E0 * E1,E2)
+ x = kzalloc(E0 * E1,E2)
... when != \(f(...,x,...)\|<+...x...+>=E3\)
when != \(while(...) S\|for(...;...;...) S\)
(
- if ((x!=NULL)&&...) memset((T2)x,0,E1 * E0);
|
+ if (!x)
- if ((x!=NULL)&&...) memset((T2)x,0,E1 * E0); else
S2
)
// --------------------------------------------------------------------- @@
expression E;
statement S;
@@
kzalloc(...)
...
if (E) S
- else { }
// --------------------------------------------------------------------- // --------------------------------------------------------------------- @@
expression E1,E2,E3;
@@
- kzalloc(E1*sizeof(E2),E3)
+ kcalloc(E1,sizeof(E2),E3)
@@
expression E1,E3;
type T;
@@
- kzalloc(E1*sizeof(T),E3)
+ kcalloc(E1,sizeof(T),E3)
@@
expression E1,E2,E3,E4;
@@
- kzalloc(E1*E2*sizeof(E3),E4)
+ kcalloc(E1*E2,sizeof(E3),E4)
@@
expression E1,E2,E3;
type T;
@@
- kzalloc(E1*E2*sizeof(T),E3)
+ kcalloc(E1*E2,sizeof(T),E3)
@@
expression E1,E2,E3,E4;
@@
- kzalloc(sizeof(E3)*E1*E2,E4)
+ kcalloc(E1*E2,sizeof(E3),E4)
@@
expression E1,E2,E3;
type T;
@@
- kzalloc(sizeof(T)*E1*E2,E3)
+ kcalloc(E1*E2,sizeof(T),E3)
@@
constant E1;
expression E2,E3;
@@
- kzalloc(E1*E2,E3)
+ kcalloc(E1,E2,E3)
Navya Sri Nizamkari (8):
staging: rtl8188eu: Use kcalloc instead of kzalloc.
staging: rtl8188eu: Use kcalloc instead of kzalloc
staging: dgnc: Use kcalloc instead of kzalloc.
staging: iio: Use kcalloc instead of kzalloc.
staging: iio: Use kcalloc instead of kzalloc
staging: media: Use kcalloc instead of kzalloc.
staging: media: Use kcalloc instead of kzalloc
staging: unisys: Use kcalloc instead of kzalloc.
drivers/staging/dgnc/dgnc_driver.c | 2 +- drivers/staging/iio/accel/lis3l02dq_ring.c | 2 +- drivers/staging/iio/adc/ad7280a.c | 5 +++-- drivers/staging/media/bcm2048/radio-bcm2048.c | 2 +- drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c | 7 ++++--- drivers/staging/rtl8188eu/core/rtw_xmit.c | 3 ++- drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c | 2 +- drivers/staging/unisys/visorutil/procobjecttree.c | 6 +++--- 8 files changed, 16 insertions(+), 13 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/8 staging: rtl8188eu: Use kcalloc instead of kzalloc.
This patch uses kcalloc instead of kzalloc function. A coccinelle script was used to make this change.
---
Changes in v2:
- Make commit message shorter by removing the coccinelle script.
drivers/staging/rtl8188eu/core/rtw_xmit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8188eu/core/rtw_xmit.c +2 -1
@@ -1634,7 +1634,8 @@ void rtw_alloc_hwxmits(struct adapter *padapter) pxmitpriv->hwxmit_entry =HWXMIT_ENTRY ; - pxmitpriv->hwxmits =kzalloc (sizeof (struct hw_xmit ) * pxmitpriv->hwxmit_entry,GFP_KERNEL ); + pxmitpriv->hwxmits =kcalloc (pxmitpriv->hwxmit_entry, +sizeof (struct hw_xmit ),GFP_KERNEL ); hwxmits = pxmitpriv->hwxmits;
Signature · 1 line
1.9.1
PATCH v2 2/8 staging: rtl8188eu: Use kcalloc instead of kzalloc
In reply to Navya Sri NizamkariThis patch uses kcalloc instead of kzalloc function. A coccinelle script was used to make this change.
---
Changes in v2:
- Make commit message shorter by removing the coccinelle script.
drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c +1 -1
@@ -42,7 +42,7 @@ int rtl8188eu_init_recv_priv(struct adapter *padapter)_rtw_init_queue (&precvpriv->free_recv_buf_queue); precvpriv->pallocated_recv_buf = -kzalloc (NR_RECVBUFF *sizeof (struct recv_buf ),GFP_KERNEL ); +kcalloc (NR_RECVBUFF ,sizeof (struct recv_buf ),GFP_KERNEL );if (precvpriv->pallocated_recv_buf ==NULL ) { res = _FAIL; RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
Signature · 1 line
1.9.1
PATCH v2 3/8 staging: dgnc: Use kcalloc instead of kzalloc.
In reply to Navya Sri NizamkariThis patch uses kcalloc instead of kzalloc function. A coccinelle script was used to make this change.
---
Changes in v2:
- Make commit message shorter by removing the coccinelle script.
drivers/staging/dgnc/dgnc_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/dgnc/dgnc_driver.c +1 -1
@@ -408,7 +408,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)return -ENOMEM ;/* make a temporary message buffer for the boot messages */ - brd->msgbuf_head =kzalloc (sizeof (u8) *8192 ,GFP_KERNEL ); + brd->msgbuf_head =kcalloc (8192 ,sizeof (u8),GFP_KERNEL ); brd->msgbuf = brd->msgbuf_head;if (!brd->msgbuf) {
Signature · 1 line
1.9.1
PATCH v2 4/8 staging: iio: Use kcalloc instead of kzalloc.
In reply to Navya Sri NizamkariThis patch uses kcalloc instead of kzalloc function. A coccinelle script was used to make this change.
---
Changes in v2:
- Make commit message shorter by removing the coccinelle script.
drivers/staging/iio/adc/ad7280a.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/iio/adc/ad7280a.c +3 -2
@@ -547,8 +547,9 @@ static int ad7280_attr_init(struct ad7280_state *st) {int dev, ch, cnt; - st->iio_attr =kzalloc (sizeof (*st->iio_attr) * (st->slave_num +1 ) * -AD7280A_CELLS_PER_DEV *2 ,GFP_KERNEL ); + st->iio_attr =kcalloc (2 ,sizeof (*st->iio_attr) * + (st->slave_num +1 ) *AD7280A_CELLS_PER_DEV , +GFP_KERNEL );if (st->iio_attr ==NULL )return -ENOMEM ;
Signature · 1 line
1.9.1
PATCH v2 5/8 staging: iio: Use kcalloc instead of kzalloc
In reply to Navya Sri NizamkariThis patch uses kcalloc instead of kzalloc function. A coccinelle script was used to make this change.
---
Changes in v2:
- Make commit message shorter by removing the coccinelle script.
drivers/staging/iio/accel/lis3l02dq_ring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/accel/lis3l02dq_ring.c +1 -1
@@ -118,7 +118,7 @@ static int lis3l02dq_get_buffer_element(struct iio_dev *indio_dev,int scan_count =bitmap_weight (indio_dev->active_scan_mask, indio_dev->masklength); - rx_array =kzalloc (4 * scan_count,GFP_KERNEL ); + rx_array =kcalloc (4 , scan_count,GFP_KERNEL );if (rx_array ==NULL )return -ENOMEM ; ret =lis3l02dq_read_all (indio_dev, rx_array);
Signature · 1 line
1.9.1
PATCH v2 6/8 staging: media: Use kcalloc instead of kzalloc.
In reply to Navya Sri NizamkariThis patch uses kcalloc instead of kzalloc function. A coccinelle script was used to make this change.
---
Changes in v2:
- Make commit message shorter by removing the coccinelle script.
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +4 -3
@@ -226,8 +226,8 @@ static int vpfe_enable_clock(struct vpfe_device *vpfe_dev)if (!vpfe_cfg->num_clocks)return 0 ; - vpfe_dev->clks =kzalloc (vpfe_cfg->num_clocks * -sizeof (struct clock *),GFP_KERNEL ); + vpfe_dev->clks =kcalloc (vpfe_cfg->num_clocks, +sizeof (struct clock *),GFP_KERNEL );if (vpfe_dev->clks ==NULL )return -ENOMEM ;
@@ -346,7 +346,8 @@ static int register_i2c_devices(struct vpfe_device *vpfe_dev) i2c_adap =i2c_get_adapter (1 ); num_subdevs = vpfe_cfg->num_subdevs; vpfe_dev->sd = -kzalloc (sizeof (struct v4l2_subdev *)*num_subdevs,GFP_KERNEL ); +kcalloc (num_subdevs,sizeof (struct v4l2_subdev *), +GFP_KERNEL );if (vpfe_dev->sd ==NULL )return -ENOMEM ;
Signature · 1 line
1.9.1
PATCH v2 7/8 staging: media: Use kcalloc instead of kzalloc
In reply to Navya Sri NizamkariThis patch uses kcalloc instead of kzalloc function. A coccinelle script was used to make this change.
---
Changes in v2:
- Make commit message shorter by removing the coccinelle script.
drivers/staging/media/bcm2048/radio-bcm2048.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/bcm2048/radio-bcm2048.c +1 -1
@@ -1792,7 +1792,7 @@ static int bcm2048_get_rds_data(struct bcm2048_device *bdev, char *data) goto unlock; } - data_buffer =kzalloc (BCM2048_MAX_RDS_RADIO_TEXT *5 ,GFP_KERNEL ); + data_buffer =kcalloc (BCM2048_MAX_RDS_RADIO_TEXT ,5 ,GFP_KERNEL );if (!data_buffer) { err = -ENOMEM ; goto unlock;
Signature · 1 line
1.9.1
PATCH v2 8/8 staging: unisys: Use kcalloc instead of kzalloc.
In reply to Navya Sri NizamkariThis patch uses kcalloc instead of kzalloc function. A coccinelle script was used to make this change.
---
Changes in v2:
- Make commit message shorter by removing the coccinelle script.
drivers/staging/unisys/visorutil/procobjecttree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/unisys/visorutil/procobjecttree.c +3 -3
@@ -159,7 +159,7 @@ MYPROCTYPE *visor_proc_CreateType(struct proc_dir_entry *procDirRoot, type->nProperties++;while (type->name[type->nNames] !=NULL ) type->nNames++; - type->procDirs =kzalloc ((type->nNames +1 ) * + type->procDirs =kcalloc ((type->nNames +1 ),sizeof (struct proc_dir_entry *),GFP_KERNEL | __GFP_NORETRY);if (type->procDirs ==NULL )
@@ -247,12 +247,12 @@ MYPROCOBJECT *visor_proc_CreateObject(MYPROCTYPE *type, goto Away; } obj->procDirPropertyContexts = -kzalloc ((type->nProperties +1 ) * +kcalloc ((type->nProperties +1 ),sizeof (struct proc_dir_entry_context ),GFP_KERNEL | __GFP_NORETRY);if (obj->procDirPropertyContexts ==NULL ) goto Away; - obj->procDirProperties =kzalloc ((type->nProperties +1 ) * + obj->procDirProperties =kcalloc ((type->nProperties +1 ),sizeof (struct proc_dir_entry *),GFP_KERNEL | __GFP_NORETRY);if (obj->procDirProperties ==NULL )
Signature · 1 line
1.9.1