[PATCH 1/1] drm/amdgpu: Convert to using devm_drm_dev_alloc()

Luben Tuikov luben.tuikov at amd.com
Tue Sep 8 19:43:00 UTC 2020


On 2020-09-05 11:50, Alex Deucher wrote:
> On Thu, Sep 3, 2020 at 9:22 PM Luben Tuikov <luben.tuikov at amd.com> wrote:
>>
>> Convert to using devm_drm_dev_alloc(),
>> as drm_dev_init() is going away.
>>
>> Signed-off-by: Luben Tuikov <luben.tuikov at amd.com>
> 
> I think we can drop the final drm_put in the error case?  I think the
> unwinding in current devm code should take care of it.

We get to the error case if devm_drm_dev_alloc() succeeds,
but we get an error thereafter, thus we do a drm_dev_put()
past the err_free label, all in amdgpu_pci_probe().

However, devm_drm_dev_alloc() calls devm_drm_dev_init(), which
calls drm_dev_init(), which does a kref_init() on &dev->ref,
which sets the kref to 1.

The drm_dev_put(), in the error case, would decrement it,
and if it is 0 after being decremented, then drm_dev_release()
is called, which does the "managed" free.

Regards,
Luben

> 
> Alex
> 
>> ---
>>  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++--------
>>  1 file changed, 3 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
>> index 146a85c8df1c..06d994187c24 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
>> @@ -1142,18 +1142,13 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
>>         if (ret)
>>                 return ret;
>>
>> -       adev = kzalloc(sizeof(*adev), GFP_KERNEL);
>> -       if (!adev)
>> -               return -ENOMEM;
>> +       adev = devm_drm_dev_alloc(&pdev->dev, &kms_driver, typeof(*adev), ddev);
>> +       if (IS_ERR(adev))
>> +               return PTR_ERR(adev);
>>
>>         adev->dev  = &pdev->dev;
>>         adev->pdev = pdev;
>>         ddev = adev_to_drm(adev);
>> -       ret = drm_dev_init(ddev, &kms_driver, &pdev->dev);
>> -       if (ret)
>> -               goto err_free;
>> -
>> -       drmm_add_final_kfree(ddev, adev);
>>
>>         if (!supports_atomic)
>>                 ddev->driver_features &= ~DRIVER_ATOMIC;
>> --
>> 2.28.0.394.ge197136389
>>
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx at lists.freedesktop.org
>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cluben.tuikov%40amd.com%7C17ffbdbf1cfb4aa34d1c08d851b362cb%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637349178195046108&sdata=tSTqRZ27GuQVAP8g7jmXAmM%2BhiGn3RUa72flIapYp9c%3D&reserved=0



More information about the amd-gfx mailing list