Unverified Commit 073667fc authored by Maxime Ripard's avatar Maxime Ripard
Browse files

drm/panel: panel-simple: make panel_dpi_probe return a panel_desc



If the panel-simple driver is probed from a panel-dpi compatible, the
driver will use an empty panel_desc structure as a descriminant. It
will then allocate and fill another panel_desc as part of its probe.

However, that allocation needs to happen after the panel_simple
structure has been allocated, since panel_dpi_probe(), the function
doing the panel_desc allocation and initialization, takes a panel_simple
pointer as an argument.

This pointer is used to fill the panel_simple->desc pointer that is
still initialized with the empty panel_desc when panel_dpi_probe() is
called.

Since commit de04bb00 ("drm/panel/panel-simple: Use the new
allocation in place of devm_kzalloc()"), we will need the panel
connector type found in panel_desc to allocate panel_simple. This
creates a circular dependency where we need panel_desc to create
panel_simple, and need panel_simple to create panel_desc.

Let's break that dependency by making panel_dpi_probe simply return the
panel_desc it initialized and move the panel_simple->desc assignment to
the caller.

This will not fix the breaking commit entirely, but will move us towards
the right direction.

Fixes: de04bb00 ("drm/panel/panel-simple: Use the new allocation in place of devm_kzalloc()")
Reviewed-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Tested-by: Francesco Dolcini <francesco.dolcini@toradex.com> # Toradex Colibri iMX6
Link: https://lore.kernel.org/r/20250626-drm-panel-simple-fixes-v2-2-5afcaa608bdc@kernel.org


Signed-off-by: default avatarMaxime Ripard <mripard@kernel.org>
parent 2d22b63f
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -432,8 +432,7 @@ static const struct drm_panel_funcs panel_simple_funcs = {

static struct panel_desc panel_dpi;

static int panel_dpi_probe(struct device *dev,
			   struct panel_simple *panel)
static struct panel_desc *panel_dpi_probe(struct device *dev)
{
	struct display_timing *timing;
	const struct device_node *np;
@@ -445,17 +444,17 @@ static int panel_dpi_probe(struct device *dev,
	np = dev->of_node;
	desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
	if (!desc)
		return -ENOMEM;
		return ERR_PTR(-ENOMEM);

	timing = devm_kzalloc(dev, sizeof(*timing), GFP_KERNEL);
	if (!timing)
		return -ENOMEM;
		return ERR_PTR(-ENOMEM);

	ret = of_get_display_timing(np, "panel-timing", timing);
	if (ret < 0) {
		dev_err(dev, "%pOF: no panel-timing node found for \"panel-dpi\" binding\n",
			np);
		return ret;
		return ERR_PTR(ret);
	}

	desc->timings = timing;
@@ -473,9 +472,7 @@ static int panel_dpi_probe(struct device *dev,
	/* We do not know the connector for the DT node, so guess it */
	desc->connector_type = DRM_MODE_CONNECTOR_DPI;

	panel->desc = desc;

	return 0;
	return desc;
}

#define PANEL_SIMPLE_BOUNDS_CHECK(to_check, bounds, field) \
@@ -613,10 +610,13 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)

	if (desc == &panel_dpi) {
		/* Handle the generic panel-dpi binding */
		err = panel_dpi_probe(dev, panel);
		if (err)
		desc = panel_dpi_probe(dev);
		if (IS_ERR(desc)) {
			err = PTR_ERR(desc);
			goto free_ddc;
		desc = panel->desc;
		}

		panel->desc = desc;
	} else {
		if (!of_get_display_timing(dev->of_node, "panel-timing", &dt))
			panel_simple_parse_panel_timing_node(dev, panel, &dt);