Skip to content

Commit 96e0e3e

Browse files
committed
drm: xlnx: zynqmp_dpsub: Don't use drmm_kcalloc() for temporary data
The array of formats passed to drm_universal_plane_init() doesn't need to outlive the function call, as it's copied internally. Use kcalloc() instead of drmm_kcalloc() to allocate it, and free it right after usage. While at it, move the allocation and initialization of the formats array to a separate function, to prepare for splitting the DRM plane handling to a separate file. Signed-off-by: Laurent Pinchart <[email protected]>
1 parent 531306f commit 96e0e3e

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

drivers/gpu/drm/xlnx/zynqmp_disp.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,33 @@ zynqmp_disp_layer_find_format(struct zynqmp_disp_layer *layer,
10001000
return NULL;
10011001
}
10021002

1003+
/**
1004+
* zynqmp_disp_layer_drm_formats - Return the DRM formats supported by the layer
1005+
* @layer: The layer
1006+
* @num_formats: Pointer to the returned number of formats
1007+
*
1008+
* Return: A newly allocated u32 array that stores all the DRM formats
1009+
* supported by the layer. The number of formats in the array is returned
1010+
* through the num_formats argument.
1011+
*/
1012+
static u32 *zynqmp_disp_layer_drm_formats(struct zynqmp_disp_layer *layer,
1013+
unsigned int *num_formats)
1014+
{
1015+
unsigned int i;
1016+
u32 *formats;
1017+
1018+
formats = kcalloc(layer->info->num_formats, sizeof(*formats),
1019+
GFP_KERNEL);
1020+
if (!formats)
1021+
return NULL;
1022+
1023+
for (i = 0; i < layer->info->num_formats; ++i)
1024+
formats[i] = layer->info->formats[i].drm_fmt;
1025+
1026+
*num_formats = layer->info->num_formats;
1027+
return formats;
1028+
}
1029+
10031030
/**
10041031
* zynqmp_disp_layer_enable - Enable a layer
10051032
* @layer: The layer
@@ -1219,31 +1246,27 @@ static const struct drm_plane_funcs zynqmp_disp_plane_funcs = {
12191246

12201247
static int zynqmp_disp_create_planes(struct zynqmp_disp *disp)
12211248
{
1222-
unsigned int i, j;
1249+
unsigned int i;
12231250
int ret;
12241251

12251252
for (i = 0; i < ARRAY_SIZE(disp->layers); i++) {
12261253
struct zynqmp_disp_layer *layer = &disp->layers[i];
12271254
enum drm_plane_type type;
1228-
u32 *drm_formats;
1255+
unsigned int num_formats;
1256+
u32 *formats;
12291257

1230-
drm_formats = drmm_kcalloc(disp->drm, sizeof(*drm_formats),
1231-
layer->info->num_formats,
1232-
GFP_KERNEL);
1233-
if (!drm_formats)
1258+
formats = zynqmp_disp_layer_drm_formats(layer, &num_formats);
1259+
if (!formats)
12341260
return -ENOMEM;
12351261

1236-
for (j = 0; j < layer->info->num_formats; ++j)
1237-
drm_formats[j] = layer->info->formats[j].drm_fmt;
1238-
12391262
/* Graphics layer is primary, and video layer is overlay. */
12401263
type = zynqmp_disp_layer_is_video(layer)
12411264
? DRM_PLANE_TYPE_OVERLAY : DRM_PLANE_TYPE_PRIMARY;
12421265
ret = drm_universal_plane_init(disp->drm, &layer->plane, 0,
12431266
&zynqmp_disp_plane_funcs,
1244-
drm_formats,
1245-
layer->info->num_formats,
1267+
formats, num_formats,
12461268
NULL, type, NULL);
1269+
kfree(formats);
12471270
if (ret)
12481271
return ret;
12491272

0 commit comments

Comments
 (0)