mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -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:
@@ -689,7 +689,7 @@ struct regmap *__regmap_init(struct device *dev,
|
||||
if (!config)
|
||||
goto err;
|
||||
|
||||
map = kzalloc(sizeof(*map), GFP_KERNEL);
|
||||
map = kzalloc_obj(*map, GFP_KERNEL);
|
||||
if (map == NULL) {
|
||||
ret = -ENOMEM;
|
||||
goto err;
|
||||
@@ -1117,7 +1117,7 @@ skip_format_initialization:
|
||||
}
|
||||
}
|
||||
|
||||
new = kzalloc(sizeof(*new), GFP_KERNEL);
|
||||
new = kzalloc_obj(*new, GFP_KERNEL);
|
||||
if (new == NULL) {
|
||||
ret = -ENOMEM;
|
||||
goto err_range;
|
||||
@@ -1274,7 +1274,7 @@ int regmap_field_bulk_alloc(struct regmap *regmap,
|
||||
struct regmap_field *rf;
|
||||
int i;
|
||||
|
||||
rf = kcalloc(num_fields, sizeof(*rf), GFP_KERNEL);
|
||||
rf = kzalloc_objs(*rf, num_fields, GFP_KERNEL);
|
||||
if (!rf)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1384,7 +1384,7 @@ EXPORT_SYMBOL_GPL(devm_regmap_field_free);
|
||||
struct regmap_field *regmap_field_alloc(struct regmap *regmap,
|
||||
struct reg_field reg_field)
|
||||
{
|
||||
struct regmap_field *rm_field = kzalloc(sizeof(*rm_field), GFP_KERNEL);
|
||||
struct regmap_field *rm_field = kzalloc_obj(*rm_field, GFP_KERNEL);
|
||||
|
||||
if (!rm_field)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
Reference in New Issue
Block a user