The drm_atomic_get_private_obj_state() function manually computes the allocation size by multiplying the element count by the element size before passing it to krealloc().
krealloc_array() handles this multiplication internally and includes overflow checking. Switch to it and drop the now-unused size variable. Suggested-by: Thomas Zimmermann <[email protected]> Reviewed-by: Daniel Stone <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> --- drivers/gpu/drm/drm_atomic.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 9bb761eda59f..aa47c647df31 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1080,5 +1080,4 @@ drm_atomic_get_private_obj_state(struct drm_atomic_commit *state, { int index, num_objs, ret; - size_t size; struct __drm_private_objs_state *arr; struct drm_private_state *obj_state; @@ -1096,6 +1095,6 @@ drm_atomic_get_private_obj_state(struct drm_atomic_commit *state, num_objs = state->num_private_objs + 1; - size = sizeof(*state->private_objs) * num_objs; - arr = krealloc(state->private_objs, size, GFP_KERNEL); + arr = krealloc_array(state->private_objs, num_objs, + sizeof(*state->private_objs), GFP_KERNEL); if (!arr) return ERR_PTR(-ENOMEM); -- 2.55.0
