staging: lustre: libcfs: Prefer kmalloc_array over kmalloc
PATCH v2 1/1 staging: lustre: libcfs: Prefer kmalloc_array over kmalloc
Use kmalloc_array instead of kmalloc for arrays to prevent integer overflows.
This was done using Coccinelle:
@@
expression e1, e2;
constant C;
type t;
@@
(
- kmalloc(
+ kmalloc_array(
e2
- *
+ ,
sizeof(e1), C)
|
- kmalloc(
+ kmalloc_array(
e1
- *
+ ,
sizeof(t), C)
|
- kmalloc(
+ kmalloc_array(
- sizeof(e1)
- *
e2
+ ,
+ sizeof(e1)
, C)
|
- kmalloc(
+ kmalloc_array(
- sizeof(t)
- *
e1
+ ,
+ sizeof(t)
, C)
)
---
Changes in v2:
-Fixed type lusture to lustre in subject.
drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c +3 -2
@@ -61,8 +61,9 @@ int cfs_tracefile_init_arch(void)memset (cfs_trace_data,0 ,sizeof (cfs_trace_data));for (i =0 ; i <CFS_TCD_TYPE_MAX ; i++) { cfs_trace_data[i] = -kmalloc (sizeof (union cfs_trace_data_union ) * -num_possible_cpus (),GFP_KERNEL ); +kmalloc_array (num_possible_cpus (), +sizeof (union cfs_trace_data_union ), +GFP_KERNEL );if (!cfs_trace_data[i]) goto out; }
--
2.1.4
Greg KH
maintainerQuoted 56 lines · Bhaktipriya Shridhar
Use
kmalloc_arrayinstead of kmalloc for arrays to prevent integer overflows.
This was done using Coccinelle:@@
expression e1, e2;
constant C;
type t;
@@
(
- kmalloc(
+ kmalloc_array(
e2
- *
+ ,
sizeof(e1), C)
|
- kmalloc(
+ kmalloc_array(
e1
- *
+ ,
sizeof(t), C)
|
- kmalloc(
+ kmalloc_array(
- sizeof(e1)
- *
e2
+ ,
+ sizeof(e1)
, C)
|
- kmalloc(
+ kmalloc_array(
- sizeof(t)
- *
e1
+ ,
+ sizeof(t)
, C)
)Signed-off-by Bhaktipriya Shridhar <[email protected]>---
Changes in v2:
-Fixed type lusture to lustre in subject.drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c +0
-0
drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c int cfs_tracefile_init_arch(void) · line 65
Quoted 5 lines
drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c +0
-2@@ -61,8 +61,9 @@ int cfs_tracefile_init_arch(void)memset (cfs_trace_data,0 ,sizeof (cfs_trace_data));for (i =0 ; i <CFS_TCD_TYPE_MAX ; i++) { cfs_trace_data[i] = -kmalloc (sizeof (union cfs_trace_data_union ) * -num_possible_cpus (),GFP_KERNEL );
We know this can't overflow, it's a static number at build time, so this change isn't needed.
Greg KH
maintainerQuoted 56 lines · Bhaktipriya Shridhar
Use
kmalloc_arrayinstead of kmalloc for arrays to prevent integer overflows.
This was done using Coccinelle:@@
expression e1, e2;
constant C;
type t;
@@
(
- kmalloc(
+ kmalloc_array(
e2
- *
+ ,
sizeof(e1), C)
|
- kmalloc(
+ kmalloc_array(
e1
- *
+ ,
sizeof(t), C)
|
- kmalloc(
+ kmalloc_array(
- sizeof(e1)
- *
e2
+ ,
+ sizeof(e1)
, C)
|
- kmalloc(
+ kmalloc_array(
- sizeof(t)
- *
e1
+ ,
+ sizeof(t)
, C)
)Signed-off-by Bhaktipriya Shridhar <[email protected]>---
Changes in v2:
-Fixed type lusture to lustre in subject.drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c +0
-0
drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c int cfs_tracefile_init_arch(void) · line 65
Quoted 5 lines
drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c +0
-2@@ -61,8 +61,9 @@ int cfs_tracefile_init_arch(void)memset (cfs_trace_data,0 ,sizeof (cfs_trace_data));for (i =0 ; i <CFS_TCD_TYPE_MAX ; i++) { cfs_trace_data[i] = -kmalloc (sizeof (union cfs_trace_data_union ) * -num_possible_cpus (),GFP_KERNEL );
We know this can't overflow, it's a static number at build time, so this change isn't needed.