* [PATCH] drm/etnaviv: use kzalloc_flex
@ 2026-03-20 1:07 Rosen Penev
2026-03-21 17:59 ` Claude review: " Claude Code Review Bot
2026-03-21 17:59 ` Claude Code Review Bot
0 siblings, 2 replies; 3+ messages in thread
From: Rosen Penev @ 2026-03-20 1:07 UTC (permalink / raw)
To: dri-devel
Cc: Lucas Stach, Russell King, Christian Gmeiner, David Airlie,
Simona Vetter, moderated list:DRM DRIVERS FOR VIVANTE GPU IP
A local helper was developed previously for struct_size.
kzalloc_flex can be used now.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/gpu/drm/etnaviv/etnaviv_drv.h | 12 ------------
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 3 +--
2 files changed, 1 insertion(+), 14 deletions(-)
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
index 20dad16fd554..55a9e745604d 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h
+++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
@@ -93,18 +93,6 @@ void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv,
#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
#define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
-/*
- * Return the storage size of a structure with a variable length array.
- * The array is nelem elements of elem_size, where the base structure
- * is defined by base. If the size overflows size_t, return zero.
- */
-static inline size_t size_vstruct(size_t nelem, size_t elem_size, size_t base)
-{
- if (elem_size && nelem > (SIZE_MAX - base) / elem_size)
- return 0;
- return base + nelem * elem_size;
-}
-
/*
* Etnaviv timeouts are specified wrt CLOCK_MONOTONIC, not jiffies.
* We need to calculate the timeout in terms of number of jiffies
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
index fbf693addd74..1a77a09b3377 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
@@ -32,9 +32,8 @@ static struct etnaviv_gem_submit *submit_create(struct drm_device *dev,
struct etnaviv_gpu *gpu, size_t nr_bos, size_t nr_pmrs)
{
struct etnaviv_gem_submit *submit;
- size_t sz = size_vstruct(nr_bos, sizeof(submit->bos[0]), sizeof(*submit));
- submit = kzalloc(sz, GFP_KERNEL);
+ submit = kzalloc_flex(*submit, bos, nr_bos);
if (!submit)
return NULL;
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Claude review: drm/etnaviv: use kzalloc_flex
2026-03-20 1:07 [PATCH] drm/etnaviv: use kzalloc_flex Rosen Penev
@ 2026-03-21 17:59 ` Claude Code Review Bot
2026-03-21 17:59 ` Claude Code Review Bot
1 sibling, 0 replies; 3+ messages in thread
From: Claude Code Review Bot @ 2026-03-21 17:59 UTC (permalink / raw)
To: dri-devel-reviews
Overall Series Review
Subject: drm/etnaviv: use kzalloc_flex
Author: Rosen Penev <rosenp@gmail.com>
Patches: 1
Reviewed: 2026-03-22T03:59:28.038126
---
This is a single-patch cleanup that replaces a local `size_vstruct()` helper and manual `kzalloc()` call with the newer kernel `kzalloc_flex()` API. The conversion is straightforward and correct. The patch is small, clean, and removes dead code.
**Verdict: Looks good.**
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 3+ messages in thread
* Claude review: drm/etnaviv: use kzalloc_flex
2026-03-20 1:07 [PATCH] drm/etnaviv: use kzalloc_flex Rosen Penev
2026-03-21 17:59 ` Claude review: " Claude Code Review Bot
@ 2026-03-21 17:59 ` Claude Code Review Bot
1 sibling, 0 replies; 3+ messages in thread
From: Claude Code Review Bot @ 2026-03-21 17:59 UTC (permalink / raw)
To: dri-devel-reviews
Patch Review
**Correctness: OK**
The conversion is semantically correct:
- The old code computed the size manually via `size_vstruct(nr_bos, sizeof(submit->bos[0]), sizeof(*submit))` and passed it to `kzalloc(sz, GFP_KERNEL)`.
- The new code `kzalloc_flex(*submit, bos, nr_bos)` expands (via `__alloc_flex`) to use `struct_size_t()` for the same computation, and `default_gfp()` with no extra args defaults to `GFP_KERNEL` — matching the original behavior.
- `bos` is indeed the trailing flexible array member of `struct etnaviv_gem_submit` (declared as `struct etnaviv_gem_submit_bo bos[];` at `etnaviv_gem.h:108`).
- The removed `size_vstruct()` has no other callers in the etnaviv driver after this change, so its removal is safe.
**Overflow handling difference (minor):** The old `size_vstruct()` returned 0 on overflow, which would cause `kzalloc(0, GFP_KERNEL)` to return `ZERO_SIZE_PTR` — a non-NULL pointer that faults on dereference (a latent bug, though practically unreachable). The new `kzalloc_flex` uses `struct_size_t()` which returns `SIZE_MAX` on overflow, causing `kzalloc` to return NULL — which is actually the safer and correct behavior. So this is a minor improvement.
**Additional benefit:** `__alloc_flex` also calls `__set_flex_counter()` which, if the `bos` member is annotated with `__counted_by()`, will automatically set the counter field. This is a nice bonus for future hardening.
**Nit:** The commit message says "A local helper was developed previously for struct_size" — this is slightly inaccurate; the helper (`size_vstruct`) predates `struct_size` and is a hand-rolled size calculation, not built on `struct_size`. The message could be clearer, but it's not a blocking issue.
**Reviewed-by worthy: Yes.** The patch is a clean, correct conversion to the preferred kernel API.
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-21 17:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 1:07 [PATCH] drm/etnaviv: use kzalloc_flex Rosen Penev
2026-03-21 17:59 ` Claude review: " Claude Code Review Bot
2026-03-21 17:59 ` Claude Code Review Bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox