mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-18 03:23:53 -04:00
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to avoid scalar types (which need careful case-by-case checking), and instead replace kmalloc-family calls that allocate struct or union object instances: Single allocations: kmalloc(sizeof(TYPE), ...) are replaced with: kmalloc_obj(TYPE, ...) Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...) are replaced with: kmalloc_objs(TYPE, COUNT, ...) Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...) are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...) (where TYPE may also be *VAR) The resulting allocations no longer return "void *", instead returning "TYPE *". Signed-off-by: Kees Cook <kees@kernel.org>
This commit is contained in:
@@ -329,7 +329,7 @@ static void __igt_breadcrumbs_smoketest(struct kthread_work *work)
|
||||
* that the fences were marked as signaled.
|
||||
*/
|
||||
|
||||
requests = kcalloc(total, sizeof(*requests), GFP_KERNEL);
|
||||
requests = kzalloc_objs(*requests, total, GFP_KERNEL);
|
||||
if (!requests) {
|
||||
thread->result = -ENOMEM;
|
||||
return;
|
||||
@@ -472,11 +472,11 @@ static int mock_breadcrumbs_smoketest(void *arg)
|
||||
* See __igt_breadcrumbs_smoketest();
|
||||
*/
|
||||
|
||||
threads = kcalloc(ncpus, sizeof(*threads), GFP_KERNEL);
|
||||
threads = kzalloc_objs(*threads, ncpus, GFP_KERNEL);
|
||||
if (!threads)
|
||||
return -ENOMEM;
|
||||
|
||||
t.contexts = kcalloc(t.ncontexts, sizeof(*t.contexts), GFP_KERNEL);
|
||||
t.contexts = kzalloc_objs(*t.contexts, t.ncontexts, GFP_KERNEL);
|
||||
if (!t.contexts) {
|
||||
ret = -ENOMEM;
|
||||
goto out_threads;
|
||||
@@ -1203,7 +1203,7 @@ static int live_all_engines(void *arg)
|
||||
* block doing so, and that they don't complete too soon.
|
||||
*/
|
||||
|
||||
request = kcalloc(nengines, sizeof(*request), GFP_KERNEL);
|
||||
request = kzalloc_objs(*request, nengines, GFP_KERNEL);
|
||||
if (!request)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1333,7 +1333,7 @@ static int live_sequential_engines(void *arg)
|
||||
* they are running on independent engines.
|
||||
*/
|
||||
|
||||
request = kcalloc(nengines, sizeof(*request), GFP_KERNEL);
|
||||
request = kzalloc_objs(*request, nengines, GFP_KERNEL);
|
||||
if (!request)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1626,7 +1626,7 @@ static int live_parallel_engines(void *arg)
|
||||
* tests that we load up the system maximally.
|
||||
*/
|
||||
|
||||
threads = kcalloc(nengines, sizeof(*threads), GFP_KERNEL);
|
||||
threads = kzalloc_objs(*threads, nengines, GFP_KERNEL);
|
||||
if (!threads)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1754,13 +1754,13 @@ static int live_breadcrumbs_smoketest(void *arg)
|
||||
goto out_rpm;
|
||||
}
|
||||
|
||||
smoke = kcalloc(nengines, sizeof(*smoke), GFP_KERNEL);
|
||||
smoke = kzalloc_objs(*smoke, nengines, GFP_KERNEL);
|
||||
if (!smoke) {
|
||||
ret = -ENOMEM;
|
||||
goto out_file;
|
||||
}
|
||||
|
||||
threads = kcalloc(ncpus * nengines, sizeof(*threads), GFP_KERNEL);
|
||||
threads = kzalloc_objs(*threads, ncpus * nengines, GFP_KERNEL);
|
||||
if (!threads) {
|
||||
ret = -ENOMEM;
|
||||
goto out_smoke;
|
||||
@@ -1768,9 +1768,8 @@ static int live_breadcrumbs_smoketest(void *arg)
|
||||
|
||||
smoke[0].request_alloc = __live_request_alloc;
|
||||
smoke[0].ncontexts = 64;
|
||||
smoke[0].contexts = kcalloc(smoke[0].ncontexts,
|
||||
sizeof(*smoke[0].contexts),
|
||||
GFP_KERNEL);
|
||||
smoke[0].contexts = kzalloc_objs(*smoke[0].contexts, smoke[0].ncontexts,
|
||||
GFP_KERNEL);
|
||||
if (!smoke[0].contexts) {
|
||||
ret = -ENOMEM;
|
||||
goto out_threads;
|
||||
@@ -2838,11 +2837,11 @@ static int perf_series_engines(void *arg)
|
||||
unsigned int idx;
|
||||
int err = 0;
|
||||
|
||||
stats = kcalloc(nengines, sizeof(*stats), GFP_KERNEL);
|
||||
stats = kzalloc_objs(*stats, nengines, GFP_KERNEL);
|
||||
if (!stats)
|
||||
return -ENOMEM;
|
||||
|
||||
ps = kzalloc(struct_size(ps, ce, nengines), GFP_KERNEL);
|
||||
ps = kzalloc_flex(*ps, ce, nengines, GFP_KERNEL);
|
||||
if (!ps) {
|
||||
kfree(stats);
|
||||
return -ENOMEM;
|
||||
@@ -3194,7 +3193,7 @@ static int perf_parallel_engines(void *arg)
|
||||
struct p_thread *engines;
|
||||
int err = 0;
|
||||
|
||||
engines = kcalloc(nengines, sizeof(*engines), GFP_KERNEL);
|
||||
engines = kzalloc_objs(*engines, nengines, GFP_KERNEL);
|
||||
if (!engines)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user