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/gud | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
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/gud')
| -rw-r--r-- | drivers/gpu/drm/gud/gud_connector.c | 10 | ||||
| -rw-r--r-- | drivers/gpu/drm/gud/gud_drv.c | 9 |
2 files changed, 11 insertions, 8 deletions
diff --git a/drivers/gpu/drm/gud/gud_connector.c b/drivers/gpu/drm/gud/gud_connector.c index 1726a3fadff8..b3d5df5f7a5c 100644 --- a/drivers/gpu/drm/gud/gud_connector.c +++ b/drivers/gpu/drm/gud/gud_connector.c @@ -246,7 +246,8 @@ static int gud_connector_get_modes(struct drm_connector *connector) if (drm_edid && edid_ctx.edid_override) goto out; - reqmodes = kmalloc_array(GUD_CONNECTOR_MAX_NUM_MODES, sizeof(*reqmodes), GFP_KERNEL); + reqmodes = kmalloc_objs(*reqmodes, GUD_CONNECTOR_MAX_NUM_MODES, + GFP_KERNEL); if (!reqmodes) goto out; @@ -479,7 +480,8 @@ static int gud_connector_add_properties(struct gud_device *gdrm, struct gud_conn unsigned int i, num_properties; int ret; - properties = kcalloc(GUD_CONNECTOR_PROPERTIES_MAX_NUM, sizeof(*properties), GFP_KERNEL); + properties = kzalloc_objs(*properties, GUD_CONNECTOR_PROPERTIES_MAX_NUM, + GFP_KERNEL); if (!properties) return -ENOMEM; @@ -619,7 +621,7 @@ static int gud_connector_create(struct gud_device *gdrm, unsigned int index, int ret, connector_type; u32 flags; - gconn = kzalloc(sizeof(*gconn), GFP_KERNEL); + gconn = kzalloc_obj(*gconn, GFP_KERNEL); if (!gconn) return -ENOMEM; @@ -698,7 +700,7 @@ int gud_get_connectors(struct gud_device *gdrm) unsigned int i, num_connectors; int ret; - descs = kmalloc_array(GUD_CONNECTORS_MAX_NUM, sizeof(*descs), GFP_KERNEL); + descs = kmalloc_objs(*descs, GUD_CONNECTORS_MAX_NUM, GFP_KERNEL); if (!descs) return -ENOMEM; diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c index 42135a48d92e..66780b9f6026 100644 --- a/drivers/gpu/drm/gud/gud_drv.c +++ b/drivers/gpu/drm/gud/gud_drv.c @@ -82,7 +82,7 @@ static int gud_get_display_descriptor(struct usb_interface *intf, void *buf; int ret; - buf = kmalloc(sizeof(*desc), GFP_KERNEL); + buf = kmalloc_obj(*desc, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -135,7 +135,7 @@ static int gud_usb_get_status(struct usb_interface *intf) int ret, status = -EIO; u8 *buf; - buf = kmalloc(sizeof(*buf), GFP_KERNEL); + buf = kmalloc_obj(*buf, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -255,7 +255,8 @@ static int gud_plane_add_properties(struct gud_device *gdrm) unsigned int i, num_properties; int ret; - properties = kcalloc(GUD_PROPERTIES_MAX_NUM, sizeof(*properties), GFP_KERNEL); + properties = kzalloc_objs(*properties, GUD_PROPERTIES_MAX_NUM, + GFP_KERNEL); if (!properties) return -ENOMEM; @@ -401,7 +402,7 @@ static int gud_alloc_bulk_buffer(struct gud_device *gdrm) return -ENOMEM; num_pages = DIV_ROUND_UP(gdrm->bulk_len, PAGE_SIZE); - pages = kmalloc_array(num_pages, sizeof(struct page *), GFP_KERNEL); + pages = kmalloc_objs(struct page *, num_pages, GFP_KERNEL); if (!pages) return -ENOMEM; |
