Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: Convert to using devm_drm_dev_alloc() (v2)

Convert to using devm_drm_dev_alloc(),
as drm_dev_init() is going away.

v2: Remove drm_dev_put() since
a) devres doesn't do refcounting, see
Documentation/driver-api/driver-model/devres.rst,
Section 4, paragraph 1; and since
b) devres acts as garbage collector when
the DRM device's parent's devres "action" callback
is called to free the container device (amdgpu_device),
which embeds the DRM dev.

Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Luben Tuikov <luben.tuikov@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20200918132505.2316382-4-daniel.vetter@ffwll.ch

authored by

Luben Tuikov and committed by
Daniel Vetter
df2ce459 cd01269d

+4 -12
+4 -12
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
··· 1142 1142 if (ret) 1143 1143 return ret; 1144 1144 1145 - adev = kzalloc(sizeof(*adev), GFP_KERNEL); 1146 - if (!adev) 1147 - return -ENOMEM; 1145 + adev = devm_drm_dev_alloc(&pdev->dev, &kms_driver, typeof(*adev), ddev); 1146 + if (IS_ERR(adev)) 1147 + return PTR_ERR(adev); 1148 1148 1149 1149 adev->dev = &pdev->dev; 1150 1150 adev->pdev = pdev; 1151 1151 ddev = adev_to_drm(adev); 1152 - ret = drm_dev_init(ddev, &kms_driver, &pdev->dev); 1153 - if (ret) 1154 - goto err_free; 1155 - 1156 - drmm_add_final_kfree(ddev, adev); 1157 1152 1158 1153 if (!supports_atomic) 1159 1154 ddev->driver_features &= ~DRIVER_ATOMIC; 1160 1155 1161 1156 ret = pci_enable_device(pdev); 1162 1157 if (ret) 1163 - goto err_free; 1158 + return ret; 1164 1159 1165 1160 ddev->pdev = pdev; 1166 1161 pci_set_drvdata(pdev, ddev); ··· 1183 1188 1184 1189 err_pci: 1185 1190 pci_disable_device(pdev); 1186 - err_free: 1187 - drm_dev_put(ddev); 1188 1191 return ret; 1189 1192 } 1190 1193 ··· 1199 1206 amdgpu_driver_unload_kms(dev); 1200 1207 pci_disable_device(pdev); 1201 1208 pci_set_drvdata(pdev, NULL); 1202 - drm_dev_put(dev); 1203 1209 } 1204 1210 1205 1211 static void