Re: [PATCH v3 6/6] drm/radeon: change drm_dev_alloc to devm_drm_dev_alloc

From: Alex Deucher
Date: Mon Jul 08 2024 - 16:04:54 EST


Applied the series. Thanks!

Alex

On Wed, Jul 3, 2024 at 4:55 AM Thomas Zimmermann <tzimmermann@xxxxxxx> wrote:
>
>
>
> Am 30.06.24 um 18:59 schrieb Wu Hoi Pok:
> > "drm_dev_alloc" is deprecated, in order to use the newer "devm_drm_dev_alloc",
> > the "drm_device" is stored inside "radeon_device", by changing "rdev_to_drm(rdev)"
> > other functions still gain access to the member "drm_device". Also, "devm_drm_dev_alloc"
> > is now allocating "radeon_device", allocation inside "radeon_driver_load_kms" has to be
> > removed.
> >
> > In "radeon_device_init", it originally assigned "rdev->dev" etc. However it is already
> > done right after "devm_drm_dev_alloc" as you can see down below. It is better remove them.
> >
> > Signed-off-by: Wu Hoi Pok <wuhoipok@xxxxxxxxx>
>
> Reviewed-by: Thomas Zimmermann <tzimmermann@xxxxxxx>
> Tested-by: Thomas Zimmermann <tzimmermann@xxxxxxx>
>
>
> > ---
> > drivers/gpu/drm/radeon/radeon.h | 4 ++--
> > drivers/gpu/drm/radeon/radeon_device.c | 3 ---
> > drivers/gpu/drm/radeon/radeon_drv.c | 12 +++++++++---
> > drivers/gpu/drm/radeon/radeon_kms.c | 8 +-------
> > 4 files changed, 12 insertions(+), 15 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
> > index ae35c102a487..fd8a4513025f 100644
> > --- a/drivers/gpu/drm/radeon/radeon.h
> > +++ b/drivers/gpu/drm/radeon/radeon.h
> > @@ -2297,7 +2297,7 @@ typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
> >
> > struct radeon_device {
> > struct device *dev;
> > - struct drm_device *ddev;
> > + struct drm_device ddev;
> > struct pci_dev *pdev;
> > #ifdef __alpha__
> > struct pci_controller *hose;
> > @@ -2478,7 +2478,7 @@ void cik_mm_wdoorbell(struct radeon_device *rdev, u32 index, u32 v);
> >
> > static inline struct drm_device *rdev_to_drm(struct radeon_device *rdev)
> > {
> > - return rdev->ddev;
> > + return &rdev->ddev;
> > }
> >
> > /*
> > diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
> > index 32851632643d..554b236c2328 100644
> > --- a/drivers/gpu/drm/radeon/radeon_device.c
> > +++ b/drivers/gpu/drm/radeon/radeon_device.c
> > @@ -1285,9 +1285,6 @@ int radeon_device_init(struct radeon_device *rdev,
> > bool runtime = false;
> >
> > rdev->shutdown = false;
> > - rdev->dev = &pdev->dev;
> > - rdev->ddev = ddev;
> > - rdev->pdev = pdev;
> > rdev->flags = flags;
> > rdev->family = flags & RADEON_FAMILY_MASK;
> > rdev->is_atom_bios = false;
> > diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
> > index 7b8aa8406751..f36aa71c57c7 100644
> > --- a/drivers/gpu/drm/radeon/radeon_drv.c
> > +++ b/drivers/gpu/drm/radeon/radeon_drv.c
> > @@ -260,6 +260,7 @@ static int radeon_pci_probe(struct pci_dev *pdev,
> > {
> > unsigned long flags = 0;
> > struct drm_device *ddev;
> > + struct radeon_device *rdev;
> > int ret;
> >
> > if (!ent)
> > @@ -300,9 +301,14 @@ static int radeon_pci_probe(struct pci_dev *pdev,
> > if (ret)
> > return ret;
> >
> > - ddev = drm_dev_alloc(&kms_driver, &pdev->dev);
> > - if (IS_ERR(ddev))
> > - return PTR_ERR(ddev);
> > + rdev = devm_drm_dev_alloc(&pdev->dev, &kms_driver, typeof(*rdev), ddev);
> > + if (IS_ERR(rdev))
> > + return PTR_ERR(rdev);
> > +
> > + rdev->dev = &pdev->dev;
> > + rdev->pdev = pdev;
> > + ddev = rdev_to_drm(rdev);
> > + ddev->dev_private = rdev;
> >
> > ret = pci_enable_device(pdev);
> > if (ret)
> > diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
> > index a16590c6247f..645e33bf7947 100644
> > --- a/drivers/gpu/drm/radeon/radeon_kms.c
> > +++ b/drivers/gpu/drm/radeon/radeon_kms.c
> > @@ -104,15 +104,9 @@ void radeon_driver_unload_kms(struct drm_device *dev)
> > int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
> > {
> > struct pci_dev *pdev = to_pci_dev(dev->dev);
> > - struct radeon_device *rdev;
> > + struct radeon_device *rdev = dev->dev_private;
> > int r, acpi_status;
> >
> > - rdev = kzalloc(sizeof(struct radeon_device), GFP_KERNEL);
> > - if (rdev == NULL) {
> > - return -ENOMEM;
> > - }
> > - dev->dev_private = (void *)rdev;
> > -
> > #ifdef __alpha__
> > rdev->hose = pdev->sysdata;
> > #endif
>
> --
> --
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Frankenstrasse 146, 90461 Nuernberg, Germany
> GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
> HRB 36809 (AG Nuernberg)
>