Commit 9c399719 authored by Luca Ceresoli's avatar Luca Ceresoli
Browse files

drm: convert many bridge drivers from devm_kzalloc() to devm_drm_bridge_alloc() API



devm_drm_bridge_alloc() is the new API to be used for allocating (and
partially initializing) a private driver struct embedding a struct
drm_bridge.

For many drivers having a simple code flow in the probe function, this
commit does a mass conversion automatically with the following semantic
patch. The changes have been reviewed manually for correctness as well as
to find any false positives.

The patch has been applied with the explicit exclusion of bridge/panel.c,
handled by a separate patch.

After applying the semantic patch, manually fixed these issues:

 - 4 drivers need ERR_CAST() instead of PTR_ERR() as the function calling
   devm_drm_bridge_alloc() returns a pointer
 - re-added empty lines and comments that the script had removed but that
   should stay

  @@
  type T;
  identifier C;
  identifier BR;
  expression DEV;
  expression FUNCS;
  @@
  -T *C;
  +T *C;
   ...
  (
  -C = devm_kzalloc(DEV, ...);
  -if (!C)
  -    return -ENOMEM;
  +C = devm_drm_bridge_alloc(DEV, T, BR, FUNCS);
  +if (IS_ERR(C))
  +     return PTR_ERR(C);
  |
  -C = devm_kzalloc(DEV, ...);
  -if (!C)
  -    return ERR_PTR(-ENOMEM);
  +C = devm_drm_bridge_alloc(DEV, T, BR, FUNCS);
  +if (IS_ERR(C))
  +     return PTR_ERR(C);
  )
   ...
  -C->BR.funcs = FUNCS;

Reviewed-by: Manikandan Muralidharan <manikandan.m@microchip.com> # microchip-lvds.c
Reviewed-by: Douglas Anderson <dianders@chromium.org> # parade-ps8640
Tested-by: Douglas Anderson <dianders@chromium.org> # parade-ps8640
Acked-by: default avatarMaxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/r/20250509-drm-bridge-convert-to-alloc-api-v3-2-b8bc1f16d7aa@bootlin.com


[Luca: fixed trivial patch conflict in adv7511_drv.c while applying]
Signed-off-by: default avatarLuca Ceresoli <luca.ceresoli@bootlin.com>
parent 9528e541
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -229,9 +229,10 @@ static int adp_mipi_probe(struct platform_device *pdev)
{
	struct adp_mipi_drv_private *adp;

	adp = devm_kzalloc(&pdev->dev, sizeof(*adp), GFP_KERNEL);
	if (!adp)
		return -ENOMEM;
	adp = devm_drm_bridge_alloc(&pdev->dev, struct adp_mipi_drv_private,
				    bridge, &adp_dsi_bridge_funcs);
	if (IS_ERR(adp))
		return PTR_ERR(adp);

	adp->mipi = devm_platform_ioremap_resource(pdev, 0);
	if (IS_ERR(adp->mipi)) {
@@ -241,7 +242,6 @@ static int adp_mipi_probe(struct platform_device *pdev)

	adp->dsi.dev = &pdev->dev;
	adp->dsi.ops = &adp_dsi_host_ops;
	adp->bridge.funcs = &adp_dsi_bridge_funcs;
	adp->bridge.of_node = pdev->dev.of_node;
	adp->bridge.type = DRM_MODE_CONNECTOR_DSI;
	dev_set_drvdata(&pdev->dev, adp);
+4 −4
Original line number Diff line number Diff line
@@ -1153,9 +1153,10 @@ static int adv7511_probe(struct i2c_client *i2c)
	if (!dev->of_node)
		return -EINVAL;

	adv7511 = devm_kzalloc(dev, sizeof(*adv7511), GFP_KERNEL);
	if (!adv7511)
		return -ENOMEM;
	adv7511 = devm_drm_bridge_alloc(dev, struct adv7511, bridge,
					&adv7511_bridge_funcs);
	if (IS_ERR(adv7511))
		return PTR_ERR(adv7511);

	adv7511->i2c_main = i2c;
	adv7511->powered = false;
@@ -1255,7 +1256,6 @@ static int adv7511_probe(struct i2c_client *i2c)
	regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL,
		     ADV7511_CEC_CTRL_POWER_DOWN);

	adv7511->bridge.funcs = &adv7511_bridge_funcs;
	adv7511->bridge.ops = DRM_BRIDGE_OP_DETECT |
		DRM_BRIDGE_OP_EDID |
		DRM_BRIDGE_OP_HDMI |
+4 −5
Original line number Diff line number Diff line
@@ -1193,9 +1193,10 @@ static int anx78xx_i2c_probe(struct i2c_client *client)
	bool found = false;
	int err;

	anx78xx = devm_kzalloc(&client->dev, sizeof(*anx78xx), GFP_KERNEL);
	if (!anx78xx)
		return -ENOMEM;
	anx78xx = devm_drm_bridge_alloc(&client->dev, struct anx78xx, bridge,
					&anx78xx_bridge_funcs);
	if (IS_ERR(anx78xx))
		return PTR_ERR(anx78xx);

	pdata = &anx78xx->pdata;

@@ -1306,8 +1307,6 @@ static int anx78xx_i2c_probe(struct i2c_client *client)
		goto err_poweroff;
	}

	anx78xx->bridge.funcs = &anx78xx_bridge_funcs;

	drm_bridge_add(&anx78xx->bridge);

	/* If cable is pulled out, just poweroff and wait for HPD event */
+4 −4
Original line number Diff line number Diff line
@@ -109,9 +109,10 @@ static int drm_aux_bridge_probe(struct auxiliary_device *auxdev,
{
	struct drm_aux_bridge_data *data;

	data = devm_kzalloc(&auxdev->dev, sizeof(*data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;
	data = devm_drm_bridge_alloc(&auxdev->dev, struct drm_aux_bridge_data,
				     bridge, &drm_aux_bridge_funcs);
	if (IS_ERR(data))
		return PTR_ERR(data);

	data->dev = &auxdev->dev;
	data->next_bridge = devm_drm_of_get_bridge(&auxdev->dev, auxdev->dev.of_node, 0, 0);
@@ -119,7 +120,6 @@ static int drm_aux_bridge_probe(struct auxiliary_device *auxdev,
		return dev_err_probe(&auxdev->dev, PTR_ERR(data->next_bridge),
				     "failed to acquire drm_bridge\n");

	data->bridge.funcs = &drm_aux_bridge_funcs;
	data->bridge.of_node = data->dev->of_node;

	/* passthrough data, allow everything */
+5 −4
Original line number Diff line number Diff line
@@ -171,12 +171,13 @@ static int drm_aux_hpd_bridge_probe(struct auxiliary_device *auxdev,
{
	struct drm_aux_hpd_bridge_data *data;

	data = devm_kzalloc(&auxdev->dev, sizeof(*data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;
	data = devm_drm_bridge_alloc(&auxdev->dev,
				     struct drm_aux_hpd_bridge_data, bridge,
				     &drm_aux_hpd_bridge_funcs);
	if (IS_ERR(data))
		return PTR_ERR(data);

	data->dev = &auxdev->dev;
	data->bridge.funcs = &drm_aux_hpd_bridge_funcs;
	data->bridge.of_node = dev_get_platdata(data->dev);
	data->bridge.ops = DRM_BRIDGE_OP_HPD;
	data->bridge.type = id->driver_data;
Loading