Hi Tommaso,
> -----Original Message-----
> From: Tommaso Merciai <[email protected]>
> Sent: 24 November 2026 09:21
> Subject: Re: [PATCH v10 08/12] drm: renesas: rz-du: Separate the DU instance
> from the DRM device
>
> Hi Biju,
> Thanks for your review.
>
> On Mon, Nov 23, 2026 at 04:59:32PM +0000, Biju Das wrote:
> > Hi Tommaso,
> >
> > > -----Original Message-----
> > > From: Tommaso Merciai <[email protected]>
> > > Sent: 13 November 2026 12:20
> > > Subject: [PATCH v10 08/12] drm: renesas: rz-du: Separate the DU
> > > instance from the DRM device
> > >
> > > On RZ/G3E two DU instances share a DRM device, which can only be
> > > created once both instances have been probed.
> > >
> > > Split the DU device structure: keep the match data and the registers
> > > in a structure allocated with the platform device, and allocate the
> > > KMS objects with the DRM device in a new rzg2l_du_instance_init() helper,
> > > as they are released
> with it.
> > >
> > > No functional change intended.
> > >
> > > Signed-off-by: Tommaso Merciai <[email protected]>
> > > ---
> > > v9->v10:
> > > - New patch.
> > >
> > > drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c | 61
> > > ++++++++++++++------
> > > 1 file changed, 44 insertions(+), 17 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c
> > > b/drivers/gpu/drm/renesas/rz- du/rzg2l_du_drv.c index
> > > d3cccbdf9012..d102876c07e1 100644
> > > --- a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c
> > > +++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c
> > > @@ -162,6 +162,27 @@ static int rzg2l_du_pm_resume(struct device
> > > *dev) static DEFINE_SIMPLE_DEV_PM_OPS(rzg2l_du_pm_ops,
> > > rzg2l_du_pm_suspend, rzg2l_du_pm_resume);
> > >
> > > +/*
> > > +-------------------------------------------------------------------
> > > +----
> > > +------
> > > + * DU instance
> > > + */
> > > +
> > > +static int rzg2l_du_instance_init(struct rzg2l_du_device *du,
> > > + struct drm_device *ddev)
> > > +{
> > > + struct rzg2l_du_device *rcdu;
> > > +
> > > + rcdu = drmm_kzalloc(ddev, sizeof(*rcdu), GFP_KERNEL);
> > > + if (!rcdu)
> > > + return -ENOMEM;
> >
> > Why there is duplicate allocation of rcdu? One in probe() and here
>
> The two allocations have different lifetimes.
>
> The one in rzg2l_du_probe() is tied to the platform device. It holds what is
> needed before the DRM
> device exists and outside of the component bind (dev, info, mmio, and
> ddev/is_master for the master,
> PM and remove), as on RZ/G3E the DRM device is only created once both
> instances have been probed.
>
> The one in rzg2l_du_instance_init() holds the KMS objects (crtcs, vsps, lvds,
> index). Their drmm
> cleanup handlers point into it and run when the DRM device is released, which
> can happen after the
> platform device has been unbound, so it has to be allocated with the DRM
> device.
Then there is an issue right, platform unbound will unmap mmio and other data
structures it allocated
in rzg2l_du_probe()and drm driver is using after that( Use after free Bug)
Cheers,
Biju
>
> Thanks, Tommaso
>
> >
> > Cheers,
> > Biju
> >
> > > +
> > > + rcdu->dev = du->dev;
> > > + rcdu->info = du->info;
> > > + rcdu->mmio = du->mmio;
> > > + rcdu->ddev = ddev;
> > > +
> > > + return rzg2l_du_modeset_init_du(rcdu); }
> > > +
> > > /*
> > > -----------------------------------------------------------------------------
> > > * Platform driver
> > > */
> > > @@ -190,44 +211,48 @@ static void rzg2l_du_shutdown(struct
> > > platform_device *pdev)
> > >
> > > static int rzg2l_du_probe(struct platform_device *pdev) {
> > > + const struct rzg2l_du_device_info *info;
> > > struct rzg2l_du_device *rcdu;
> > > struct rzg2l_du_drm *rzgdrm;
> > > + void __iomem *mmio;
> > > int ret;
> > >
> > > if (drm_firmware_drivers_only())
> > > return -ENODEV;
> > >
> > > - /* Allocate and initialize the RZ/G2L device structure. */
> > > - rzgdrm = devm_drm_dev_alloc(&pdev->dev, &rzg2l_du_driver,
> > > - struct rzg2l_du_drm, ddev);
> > > - if (IS_ERR(rzgdrm))
> > > - return PTR_ERR(rzgdrm);
> > > + info = of_device_get_match_data(&pdev->dev);
> > > +
> > > + /* I/O resources */
> > > + mmio = devm_platform_ioremap_resource(pdev, 0);
> > > + if (IS_ERR(mmio))
> > > + return PTR_ERR(mmio);
> > > +
> > > + ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
> > > + if (ret)
> > > + return ret;
> > >
> > > - rcdu = drmm_kzalloc(&rzgdrm->ddev, sizeof(*rcdu), GFP_KERNEL);
> > > + /* Allocate and initialize the RZ/G2L device structure. */
> > > + rcdu = devm_kzalloc(&pdev->dev, sizeof(*rcdu), GFP_KERNEL);
> > > if (!rcdu)
> > > return -ENOMEM;
> > >
> > > platform_set_drvdata(pdev, rcdu);
> > >
> > > rcdu->dev = &pdev->dev;
> > > - rcdu->info = of_device_get_match_data(rcdu->dev);
> > > - rcdu->ddev = &rzgdrm->ddev;
> > > -
> > > - /* I/O resources */
> > > - rcdu->mmio = devm_platform_ioremap_resource(pdev, 0);
> > > - if (IS_ERR(rcdu->mmio))
> > > - return PTR_ERR(rcdu->mmio);
> > > + rcdu->info = info;
> > > + rcdu->mmio = mmio;
> > >
> > > - ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
> > > - if (ret)
> > > - return ret;
> > > + rzgdrm = devm_drm_dev_alloc(&pdev->dev, &rzg2l_du_driver,
> > > + struct rzg2l_du_drm, ddev);
> > > + if (IS_ERR(rzgdrm))
> > > + return PTR_ERR(rzgdrm);
> > >
> > > /* DRM/KMS objects */
> > > ret = rzg2l_du_modeset_init_drm(&rzgdrm->ddev);
> > > if (ret < 0)
> > > goto error;
> > >
> > > - ret = rzg2l_du_modeset_init_du(rcdu);
> > > + ret = rzg2l_du_instance_init(rcdu, &rzgdrm->ddev);
> > > if (ret < 0)
> > > goto error;
> > >
> > > @@ -243,6 +268,8 @@ static int rzg2l_du_probe(struct platform_device
> > > *pdev)
> > > if (ret)
> > > goto error_fini;
> > >
> > > + rcdu->ddev = &rzgdrm->ddev;
> > > +
> > > drm_info(&rzgdrm->ddev, "Device %s probed\n",
> > > dev_name(&pdev->dev));
> > >
> > > drm_client_setup(&rzgdrm->ddev, NULL);
> > > --
> > > 2.54.0
> >