mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/
synced 2026-04-18 06:33:43 -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:
@@ -545,13 +545,15 @@ static void schedule_dc_vmin_vmax(struct amdgpu_device *adev,
|
||||
struct dc_stream_state *stream,
|
||||
struct dc_crtc_timing_adjust *adjust)
|
||||
{
|
||||
struct vupdate_offload_work *offload_work = kzalloc(sizeof(*offload_work), GFP_NOWAIT);
|
||||
struct vupdate_offload_work *offload_work = kzalloc_obj(*offload_work,
|
||||
GFP_NOWAIT);
|
||||
if (!offload_work) {
|
||||
drm_dbg_driver(adev_to_drm(adev), "Failed to allocate vupdate_offload_work\n");
|
||||
return;
|
||||
}
|
||||
|
||||
struct dc_crtc_timing_adjust *adjust_copy = kzalloc(sizeof(*adjust_copy), GFP_NOWAIT);
|
||||
struct dc_crtc_timing_adjust *adjust_copy = kzalloc_obj(*adjust_copy,
|
||||
GFP_NOWAIT);
|
||||
if (!adjust_copy) {
|
||||
drm_dbg_driver(adev_to_drm(adev), "Failed to allocate adjust_copy\n");
|
||||
kfree(offload_work);
|
||||
@@ -1023,7 +1025,8 @@ static void dm_dmub_outbox1_low_irq(void *interrupt_params)
|
||||
continue;
|
||||
}
|
||||
if (dm->dmub_thread_offload[notify.type] == true) {
|
||||
dmub_hpd_wrk = kzalloc(sizeof(*dmub_hpd_wrk), GFP_ATOMIC);
|
||||
dmub_hpd_wrk = kzalloc_obj(*dmub_hpd_wrk,
|
||||
GFP_ATOMIC);
|
||||
if (!dmub_hpd_wrk) {
|
||||
drm_err(adev_to_drm(adev), "Failed to allocate dmub_hpd_wrk");
|
||||
return;
|
||||
@@ -1647,7 +1650,8 @@ static struct hpd_rx_irq_offload_work_queue *hpd_rx_irq_create_workqueue(struct
|
||||
int i = 0;
|
||||
struct hpd_rx_irq_offload_work_queue *hpd_rx_offload_wq = NULL;
|
||||
|
||||
hpd_rx_offload_wq = kcalloc(max_caps, sizeof(*hpd_rx_offload_wq), GFP_KERNEL);
|
||||
hpd_rx_offload_wq = kzalloc_objs(*hpd_rx_offload_wq, max_caps,
|
||||
GFP_KERNEL);
|
||||
|
||||
if (!hpd_rx_offload_wq)
|
||||
return NULL;
|
||||
@@ -1720,7 +1724,7 @@ dm_allocate_gpu_mem(
|
||||
AMDGPU_GEM_DOMAIN_GTT : AMDGPU_GEM_DOMAIN_VRAM;
|
||||
int ret;
|
||||
|
||||
da = kzalloc(sizeof(struct dal_allocation), GFP_KERNEL);
|
||||
da = kzalloc_obj(struct dal_allocation, GFP_KERNEL);
|
||||
if (!da)
|
||||
return NULL;
|
||||
|
||||
@@ -2126,7 +2130,8 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
|
||||
}
|
||||
if (dc_is_dmub_outbox_supported(adev->dm.dc)) {
|
||||
init_completion(&adev->dm.dmub_aux_transfer_done);
|
||||
adev->dm.dmub_notify = kzalloc(sizeof(struct dmub_notification), GFP_KERNEL);
|
||||
adev->dm.dmub_notify = kzalloc_obj(struct dmub_notification,
|
||||
GFP_KERNEL);
|
||||
if (!adev->dm.dmub_notify) {
|
||||
drm_info(adev_to_drm(adev), "fail to allocate adev->dm.dmub_notify");
|
||||
goto error;
|
||||
@@ -2521,7 +2526,7 @@ static int dm_dmub_sw_init(struct amdgpu_device *adev)
|
||||
}
|
||||
|
||||
|
||||
adev->dm.dmub_srv = kzalloc(sizeof(*adev->dm.dmub_srv), GFP_KERNEL);
|
||||
adev->dm.dmub_srv = kzalloc_obj(*adev->dm.dmub_srv, GFP_KERNEL);
|
||||
dmub_srv = adev->dm.dmub_srv;
|
||||
|
||||
if (!dmub_srv) {
|
||||
@@ -2602,8 +2607,7 @@ static int dm_dmub_sw_init(struct amdgpu_device *adev)
|
||||
memory_params.region_info = ®ion_info;
|
||||
memory_params.window_memory_type = window_memory_type;
|
||||
|
||||
adev->dm.dmub_fb_info =
|
||||
kzalloc(sizeof(*adev->dm.dmub_fb_info), GFP_KERNEL);
|
||||
adev->dm.dmub_fb_info = kzalloc_obj(*adev->dm.dmub_fb_info, GFP_KERNEL);
|
||||
fb_info = adev->dm.dmub_fb_info;
|
||||
|
||||
if (!fb_info) {
|
||||
@@ -3359,7 +3363,7 @@ static void dm_gpureset_commit_state(struct dc_state *dc_state,
|
||||
} *bundle __free(kfree);
|
||||
int k, m;
|
||||
|
||||
bundle = kzalloc(sizeof(*bundle), GFP_KERNEL);
|
||||
bundle = kzalloc_obj(*bundle, GFP_KERNEL);
|
||||
|
||||
if (!bundle) {
|
||||
drm_err(dm->ddev, "Failed to allocate update bundle\n");
|
||||
@@ -3927,7 +3931,7 @@ void amdgpu_dm_update_connector_after_detect(
|
||||
|
||||
if (!aconnector->timing_requested) {
|
||||
aconnector->timing_requested =
|
||||
kzalloc(sizeof(struct dc_crtc_timing), GFP_KERNEL);
|
||||
kzalloc_obj(struct dc_crtc_timing, GFP_KERNEL);
|
||||
if (!aconnector->timing_requested)
|
||||
drm_err(dev,
|
||||
"failed to create aconnector->requested_timing\n");
|
||||
@@ -4156,8 +4160,8 @@ static void handle_hpd_irq(void *param)
|
||||
static void schedule_hpd_rx_offload_work(struct amdgpu_device *adev, struct hpd_rx_irq_offload_work_queue *offload_wq,
|
||||
union hpd_irq_data hpd_irq_data)
|
||||
{
|
||||
struct hpd_rx_irq_offload_work *offload_work =
|
||||
kzalloc(sizeof(*offload_work), GFP_KERNEL);
|
||||
struct hpd_rx_irq_offload_work *offload_work = kzalloc_obj(*offload_work,
|
||||
GFP_KERNEL);
|
||||
|
||||
if (!offload_work) {
|
||||
drm_err(adev_to_drm(adev), "Failed to allocate hpd_rx_irq_offload_work.\n");
|
||||
@@ -4878,7 +4882,7 @@ dm_atomic_duplicate_state(struct drm_private_obj *obj)
|
||||
{
|
||||
struct dm_atomic_state *old_state, *new_state;
|
||||
|
||||
new_state = kzalloc(sizeof(*new_state), GFP_KERNEL);
|
||||
new_state = kzalloc_obj(*new_state, GFP_KERNEL);
|
||||
if (!new_state)
|
||||
return NULL;
|
||||
|
||||
@@ -4935,7 +4939,7 @@ static int amdgpu_dm_mode_config_init(struct amdgpu_device *adev)
|
||||
/* indicates support for immediate flip */
|
||||
adev_to_drm(adev)->mode_config.async_page_flip = true;
|
||||
|
||||
state = kzalloc(sizeof(*state), GFP_KERNEL);
|
||||
state = kzalloc_obj(*state, GFP_KERNEL);
|
||||
if (!state)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -5363,7 +5367,7 @@ static int initialize_plane(struct amdgpu_display_manager *dm,
|
||||
unsigned long possible_crtcs;
|
||||
int ret = 0;
|
||||
|
||||
plane = kzalloc(sizeof(struct drm_plane), GFP_KERNEL);
|
||||
plane = kzalloc_obj(struct drm_plane, GFP_KERNEL);
|
||||
if (!plane) {
|
||||
drm_err(adev_to_drm(dm->adev), "KMS: Failed to allocate plane\n");
|
||||
return -ENOMEM;
|
||||
@@ -5602,7 +5606,8 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
|
||||
link = dc_get_link_at_index(dm->dc, i);
|
||||
|
||||
if (link->connector_signal == SIGNAL_TYPE_VIRTUAL) {
|
||||
struct amdgpu_dm_wb_connector *wbcon = kzalloc(sizeof(*wbcon), GFP_KERNEL);
|
||||
struct amdgpu_dm_wb_connector *wbcon = kzalloc_obj(*wbcon,
|
||||
GFP_KERNEL);
|
||||
|
||||
if (!wbcon) {
|
||||
drm_err(adev_to_drm(adev), "KMS: Failed to allocate writeback connector\n");
|
||||
@@ -5621,11 +5626,11 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
|
||||
continue;
|
||||
}
|
||||
|
||||
aconnector = kzalloc(sizeof(*aconnector), GFP_KERNEL);
|
||||
aconnector = kzalloc_obj(*aconnector, GFP_KERNEL);
|
||||
if (!aconnector)
|
||||
goto fail;
|
||||
|
||||
aencoder = kzalloc(sizeof(*aencoder), GFP_KERNEL);
|
||||
aencoder = kzalloc_obj(*aencoder, GFP_KERNEL);
|
||||
if (!aencoder)
|
||||
goto fail;
|
||||
|
||||
@@ -7819,7 +7824,7 @@ void amdgpu_dm_connector_funcs_reset(struct drm_connector *connector)
|
||||
|
||||
kfree(state);
|
||||
|
||||
state = kzalloc(sizeof(*state), GFP_KERNEL);
|
||||
state = kzalloc_obj(*state, GFP_KERNEL);
|
||||
|
||||
if (state) {
|
||||
state->scaling = RMX_OFF;
|
||||
@@ -9094,7 +9099,7 @@ static int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,
|
||||
if (!ddc_service->ddc_pin)
|
||||
return result;
|
||||
|
||||
cmd.payloads = kcalloc(num, sizeof(struct i2c_payload), GFP_KERNEL);
|
||||
cmd.payloads = kzalloc_objs(struct i2c_payload, num, GFP_KERNEL);
|
||||
|
||||
if (!cmd.payloads)
|
||||
return result;
|
||||
@@ -9143,7 +9148,7 @@ create_i2c(struct ddc_service *ddc_service, bool oem)
|
||||
struct amdgpu_device *adev = ddc_service->ctx->driver_context;
|
||||
struct amdgpu_i2c_adapter *i2c;
|
||||
|
||||
i2c = kzalloc(sizeof(struct amdgpu_i2c_adapter), GFP_KERNEL);
|
||||
i2c = kzalloc_obj(struct amdgpu_i2c_adapter, GFP_KERNEL);
|
||||
if (!i2c)
|
||||
return NULL;
|
||||
i2c->base.owner = THIS_MODULE;
|
||||
@@ -9944,7 +9949,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
|
||||
struct dc_stream_update stream_update;
|
||||
} *bundle;
|
||||
|
||||
bundle = kzalloc(sizeof(*bundle), GFP_KERNEL);
|
||||
bundle = kzalloc_obj(*bundle, GFP_KERNEL);
|
||||
|
||||
if (!bundle) {
|
||||
drm_err(dev, "Failed to allocate update bundle\n");
|
||||
@@ -10619,7 +10624,7 @@ static void dm_set_writeback(struct amdgpu_display_manager *dm,
|
||||
struct amdgpu_framebuffer *afb;
|
||||
int i = 0;
|
||||
|
||||
wb_info = kzalloc(sizeof(*wb_info), GFP_KERNEL);
|
||||
wb_info = kzalloc_obj(*wb_info, GFP_KERNEL);
|
||||
if (!wb_info) {
|
||||
drm_err(adev_to_drm(adev), "Failed to allocate wb_info\n");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user