diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/gpu/drm/drm_client_modeset.c | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
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>
Diffstat (limited to 'drivers/gpu/drm/drm_client_modeset.c')
| -rw-r--r-- | drivers/gpu/drm/drm_client_modeset.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/drivers/gpu/drm/drm_client_modeset.c b/drivers/gpu/drm/drm_client_modeset.c index fc4caf7da5fc..fce35c27b361 100644 --- a/drivers/gpu/drm/drm_client_modeset.c +++ b/drivers/gpu/drm/drm_client_modeset.c @@ -44,7 +44,8 @@ int drm_client_modeset_create(struct drm_client_dev *client) int i = 0; /* Add terminating zero entry to enable index less iteration */ - client->modesets = kcalloc(num_crtc + 1, sizeof(*client->modesets), GFP_KERNEL); + client->modesets = kzalloc_objs(*client->modesets, num_crtc + 1, + GFP_KERNEL); if (!client->modesets) return -ENOMEM; @@ -58,8 +59,9 @@ int drm_client_modeset_create(struct drm_client_dev *client) max_connector_count = DRM_CLIENT_MAX_CLONED_CONNECTORS; for (modeset = client->modesets; modeset->crtc; modeset++) { - modeset->connectors = kcalloc(max_connector_count, - sizeof(*modeset->connectors), GFP_KERNEL); + modeset->connectors = kzalloc_objs(*modeset->connectors, + max_connector_count, + GFP_KERNEL); if (!modeset->connectors) goto err_free; } @@ -565,7 +567,7 @@ static int drm_client_pick_crtcs(struct drm_client_dev *client, if (modes[n] == NULL) return best_score; - crtcs = kcalloc(connector_count, sizeof(*crtcs), GFP_KERNEL); + crtcs = kzalloc_objs(*crtcs, connector_count, GFP_KERNEL); if (!crtcs) return best_score; @@ -641,7 +643,7 @@ static bool drm_client_firmware_config(struct drm_client_dev *client, if (drm_WARN_ON(dev, count <= 0)) return false; - save_enabled = kcalloc(count, sizeof(bool), GFP_KERNEL); + save_enabled = kzalloc_objs(bool, count, GFP_KERNEL); if (!save_enabled) return false; @@ -853,10 +855,10 @@ int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, if (!connector_count) return 0; - crtcs = kcalloc(connector_count, sizeof(*crtcs), GFP_KERNEL); - modes = kcalloc(connector_count, sizeof(*modes), GFP_KERNEL); - offsets = kcalloc(connector_count, sizeof(*offsets), GFP_KERNEL); - enabled = kcalloc(connector_count, sizeof(bool), GFP_KERNEL); + crtcs = kzalloc_objs(*crtcs, connector_count, GFP_KERNEL); + modes = kzalloc_objs(*modes, connector_count, GFP_KERNEL); + offsets = kzalloc_objs(*offsets, connector_count, GFP_KERNEL); + enabled = kzalloc_objs(bool, connector_count, GFP_KERNEL); if (!crtcs || !modes || !enabled || !offsets) { ret = -ENOMEM; goto out; |
