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:
@@ -891,7 +891,7 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
|
||||
if (head->block == AMDGPU_RAS_BLOCK__GFX &&
|
||||
!amdgpu_sriov_vf(adev) &&
|
||||
!amdgpu_ras_intr_triggered()) {
|
||||
info = kzalloc(sizeof(union ta_ras_cmd_input), GFP_KERNEL);
|
||||
info = kzalloc_obj(union ta_ras_cmd_input, GFP_KERNEL);
|
||||
if (!info)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1904,7 +1904,7 @@ static ssize_t amdgpu_ras_sysfs_badpages_read(struct file *f,
|
||||
memset(buf, 0, count);
|
||||
|
||||
bps_count = end - start;
|
||||
bps = kmalloc_array(bps_count, sizeof(*bps), GFP_KERNEL);
|
||||
bps = kmalloc_objs(*bps, bps_count, GFP_KERNEL);
|
||||
if (!bps)
|
||||
return 0;
|
||||
|
||||
@@ -2811,7 +2811,7 @@ static int amdgpu_uniras_badpages_read(struct amdgpu_device *adev,
|
||||
if (!bps || !count)
|
||||
return -EINVAL;
|
||||
|
||||
output = kmalloc(sizeof(*output), GFP_KERNEL);
|
||||
output = kmalloc_obj(*output, GFP_KERNEL);
|
||||
if (!output)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -2991,7 +2991,7 @@ static int amdgpu_ras_realloc_eh_data_space(struct amdgpu_device *adev,
|
||||
unsigned int old_space = data->count + data->space_left;
|
||||
unsigned int new_space = old_space + pages;
|
||||
unsigned int align_space = ALIGN(new_space, 512);
|
||||
void *bps = kmalloc_array(align_space, sizeof(*data->bps), GFP_KERNEL);
|
||||
void *bps = kmalloc_objs(*data->bps, align_space, GFP_KERNEL);
|
||||
|
||||
if (!bps) {
|
||||
return -ENOMEM;
|
||||
@@ -3238,8 +3238,8 @@ int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
|
||||
|
||||
if (from_rom) {
|
||||
err_data.err_addr =
|
||||
kcalloc(adev->umc.retire_unit,
|
||||
sizeof(struct eeprom_table_record), GFP_KERNEL);
|
||||
kzalloc_objs(struct eeprom_table_record,
|
||||
adev->umc.retire_unit, GFP_KERNEL);
|
||||
if (!err_data.err_addr) {
|
||||
dev_warn(adev->dev, "Failed to alloc UMC error address record in mca2pa conversion!\n");
|
||||
return -ENOMEM;
|
||||
@@ -3375,7 +3375,7 @@ static int amdgpu_ras_load_bad_pages(struct amdgpu_device *adev)
|
||||
if (control->ras_num_recs == 0 || amdgpu_bad_page_threshold == 0)
|
||||
return 0;
|
||||
|
||||
bps = kcalloc(control->ras_num_recs, sizeof(*bps), GFP_KERNEL);
|
||||
bps = kzalloc_objs(*bps, control->ras_num_recs, GFP_KERNEL);
|
||||
if (!bps)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -3863,7 +3863,7 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev, bool init_bp_info)
|
||||
return 0;
|
||||
|
||||
data = &con->eh_data;
|
||||
*data = kzalloc(sizeof(**data), GFP_KERNEL);
|
||||
*data = kzalloc_obj(**data, GFP_KERNEL);
|
||||
if (!*data) {
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
@@ -4499,7 +4499,7 @@ int amdgpu_ras_block_late_init(struct amdgpu_device *adev,
|
||||
|
||||
/* Those are the cached values at init.
|
||||
*/
|
||||
query_info = kzalloc(sizeof(*query_info), GFP_KERNEL);
|
||||
query_info = kzalloc_obj(*query_info, GFP_KERNEL);
|
||||
if (!query_info)
|
||||
return -ENOMEM;
|
||||
memcpy(&query_info->head, ras_block, sizeof(struct ras_common_if));
|
||||
@@ -5188,7 +5188,7 @@ int amdgpu_ras_register_ras_block(struct amdgpu_device *adev,
|
||||
if (!adev || !ras_block_obj)
|
||||
return -EINVAL;
|
||||
|
||||
ras_node = kzalloc(sizeof(*ras_node), GFP_KERNEL);
|
||||
ras_node = kzalloc_obj(*ras_node, GFP_KERNEL);
|
||||
if (!ras_node)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -5389,7 +5389,7 @@ static struct ras_err_node *amdgpu_ras_error_node_new(void)
|
||||
{
|
||||
struct ras_err_node *err_node;
|
||||
|
||||
err_node = kvzalloc(sizeof(*err_node), GFP_KERNEL);
|
||||
err_node = kvzalloc_obj(*err_node, GFP_KERNEL);
|
||||
if (!err_node)
|
||||
return NULL;
|
||||
|
||||
@@ -5682,7 +5682,7 @@ int amdgpu_ras_add_critical_region(struct amdgpu_device *adev,
|
||||
|
||||
/* Record new critical amdgpu bo */
|
||||
list_for_each_entry(block, &vres->blocks, link) {
|
||||
region = kzalloc(sizeof(*region), GFP_KERNEL);
|
||||
region = kzalloc_obj(*region, GFP_KERNEL);
|
||||
if (!region) {
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
|
||||
Reference in New Issue
Block a user