sched: Use kcalloc instead of kzalloc to allocate array
PATCH 1/1 sched: Use kcalloc instead of kzalloc to allocate array
The advantage of kcalloc is, that will prevent integer overflows which could result from the multiplication of number of elements and size and it is also a bit nicer to read.
The semantic patch that makes this change is available in https://lkml.org/lkml/2011/11/25/107
Signed-off-by Thomas Meyer <[email protected]>
---
kernel/rcutorture.c 2011-11-28 20:09:11.653518946 +0100 renamed from kernel/rcutorture.c 2011-11-13 11:08:11.807536650 +0100 +2 -2
@@ -1494,7 +1494,7 @@ rcu_torture_init(void) writer_task = NULL; goto unwind; } - fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), + fakewriter_tasks = kcalloc(nfakewriters, sizeof(fakewriter_tasks[0]), GFP_KERNEL); if (fakewriter_tasks == NULL) { VERBOSE_PRINTK_ERRSTRING("out of memory");
@@ -1512,7 +1512,7 @@ rcu_torture_init(void) goto unwind; } } - reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), + reader_tasks = kcalloc(nrealreaders, sizeof(reader_tasks[0]), GFP_KERNEL); if (reader_tasks == NULL) { VERBOSE_PRINTK_ERRSTRING("out of memory");
kernel/sched.c 2011-11-28 20:09:30.620411188 +0100 renamed from kernel/sched.c 2011-11-13 11:08:11.917538384 +0100 +4 -4
@@ -8527,10 +8527,10 @@ int alloc_fair_sched_group(struct task_g struct sched_entity *se; int i; - tg->cfs_rq = kzalloc(sizeof(cfs_rq) * nr_cpu_ids, GFP_KERNEL); + tg->cfs_rq = kcalloc(nr_cpu_ids, sizeof(cfs_rq), GFP_KERNEL); if (!tg->cfs_rq) goto err; - tg->se = kzalloc(sizeof(se) * nr_cpu_ids, GFP_KERNEL); + tg->se = kcalloc(nr_cpu_ids, sizeof(se), GFP_KERNEL); if (!tg->se) goto err;
@@ -8619,10 +8619,10 @@ int alloc_rt_sched_group(struct task_gro struct sched_rt_entity *rt_se; int i; - tg->rt_rq = kzalloc(sizeof(rt_rq) * nr_cpu_ids, GFP_KERNEL); + tg->rt_rq = kcalloc(nr_cpu_ids, sizeof(rt_rq), GFP_KERNEL); if (!tg->rt_rq) goto err; - tg->rt_se = kzalloc(sizeof(rt_se) * nr_cpu_ids, GFP_KERNEL); + tg->rt_se = kcalloc(nr_cpu_ids, sizeof(rt_se), GFP_KERNEL); if (!tg->rt_se) goto err;