aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-08-06 14:29:52 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-10-19 16:51:04 +0300
commit96e0e3e3a210ab9c4894da2250bb583dd61ab3a2 (patch)
tree2063166eb6b782b9c787284ecdf9ecc17ae3ab95
parent531306f54e84b9502f18db66f81729df7bc5fbe3 (diff)
downloadaccel-96e0e3e3a210ab9c4894da2250bb583dd61ab3a2.tar.gz
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 <laurent.pinchart@ideasonboard.com>
-rw-r--r--drivers/gpu/drm/xlnx/zynqmp_disp.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/drivers/gpu/drm/xlnx/zynqmp_disp.c b/drivers/gpu/drm/xlnx/zynqmp_disp.c
index e722af0e59a99f..4f6c9af799e9f7 100644
--- a/drivers/gpu/drm/xlnx/zynqmp_disp.c
+++ b/drivers/gpu/drm/xlnx/zynqmp_disp.c
@@ -1001,6 +1001,33 @@ zynqmp_disp_layer_find_format(struct zynqmp_disp_layer *layer,
}
/**
+ * zynqmp_disp_layer_drm_formats - Return the DRM formats supported by the layer
+ * @layer: The layer
+ * @num_formats: Pointer to the returned number of formats
+ *
+ * Return: A newly allocated u32 array that stores all the DRM formats
+ * supported by the layer. The number of formats in the array is returned
+ * through the num_formats argument.
+ */
+static u32 *zynqmp_disp_layer_drm_formats(struct zynqmp_disp_layer *layer,
+ unsigned int *num_formats)
+{
+ unsigned int i;
+ u32 *formats;
+
+ formats = kcalloc(layer->info->num_formats, sizeof(*formats),
+ GFP_KERNEL);
+ if (!formats)
+ return NULL;
+
+ for (i = 0; i < layer->info->num_formats; ++i)
+ formats[i] = layer->info->formats[i].drm_fmt;
+
+ *num_formats = layer->info->num_formats;
+ return formats;
+}
+
+/**
* zynqmp_disp_layer_enable - Enable a layer
* @layer: The layer
*
@@ -1219,31 +1246,27 @@ static const struct drm_plane_funcs zynqmp_disp_plane_funcs = {
static int zynqmp_disp_create_planes(struct zynqmp_disp *disp)
{
- unsigned int i, j;
+ unsigned int i;
int ret;
for (i = 0; i < ARRAY_SIZE(disp->layers); i++) {
struct zynqmp_disp_layer *layer = &disp->layers[i];
enum drm_plane_type type;
- u32 *drm_formats;
+ unsigned int num_formats;
+ u32 *formats;
- drm_formats = drmm_kcalloc(disp->drm, sizeof(*drm_formats),
- layer->info->num_formats,
- GFP_KERNEL);
- if (!drm_formats)
+ formats = zynqmp_disp_layer_drm_formats(layer, &num_formats);
+ if (!formats)
return -ENOMEM;
- for (j = 0; j < layer->info->num_formats; ++j)
- drm_formats[j] = layer->info->formats[j].drm_fmt;
-
/* Graphics layer is primary, and video layer is overlay. */
type = zynqmp_disp_layer_is_video(layer)
? DRM_PLANE_TYPE_OVERLAY : DRM_PLANE_TYPE_PRIMARY;
ret = drm_universal_plane_init(disp->drm, &layer->plane, 0,
&zynqmp_disp_plane_funcs,
- drm_formats,
- layer->info->num_formats,
+ formats, num_formats,
NULL, type, NULL);
+ kfree(formats);
if (ret)
return ret;