drm/amd/amdgpu: Use kmemdup to simplify kmalloc and memcpy logic
authorChen Jiahao <chenjiahao16@huawei.com>
Wed, 16 Aug 2023 02:19:58 +0000 (10:19 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 30 Aug 2023 18:56:47 +0000 (14:56 -0400)
Using kmemdup() helper function rather than implementing it again
with kmalloc() + memcpy(), which improves the code readability.

Signed-off-by: Chen Jiahao <chenjiahao16@huawei.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c

index d34037b..7473a42 100644 (file)
@@ -264,16 +264,9 @@ struct edid *amdgpu_connector_edid(struct drm_connector *connector)
 static struct edid *
 amdgpu_connector_get_hardcoded_edid(struct amdgpu_device *adev)
 {
-       struct edid *edid;
-
        if (adev->mode_info.bios_hardcoded_edid) {
-               edid = kmalloc(adev->mode_info.bios_hardcoded_edid_size, GFP_KERNEL);
-               if (edid) {
-                       memcpy((unsigned char *)edid,
-                              (unsigned char *)adev->mode_info.bios_hardcoded_edid,
-                              adev->mode_info.bios_hardcoded_edid_size);
-                       return edid;
-               }
+               return kmemdup((unsigned char *)adev->mode_info.bios_hardcoded_edid,
+                              adev->mode_info.bios_hardcoded_edid_size, GFP_KERNEL);
        }
        return NULL;
 }