drm/amdgpu: convert bios_hardcoded_edid to drm_edid
authorThomas Weißschuh <linux@weissschuh.net>
Fri, 26 Jul 2024 13:40:15 +0000 (15:40 +0200)
committerAlex Deucher <alexander.deucher@amd.com>
Sat, 27 Jul 2024 21:35:05 +0000 (17:35 -0400)
Instead of manually passing around 'struct edid *' and its size,
use 'struct drm_edid', which encapsulates a validated combination of
both.

As the drm_edid_ can handle NULL gracefully, the explicit checks can be
dropped.

Also save a few characters by transforming '&array[0]' to the equivalent
'array' and using 'max_t(int, ...)' instead of manual casts.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c

index bd0fbdc5f55d495b73c25371bad4090d1eb461a2..344e0a9ee08a99a7e874e4ed31c28901b7ea25b0 100644 (file)
@@ -249,11 +249,7 @@ amdgpu_connector_find_encoder(struct drm_connector *connector,
 static struct edid *
 amdgpu_connector_get_hardcoded_edid(struct amdgpu_device *adev)
 {
-       if (adev->mode_info.bios_hardcoded_edid) {
-               return kmemdup((unsigned char *)adev->mode_info.bios_hardcoded_edid,
-                              adev->mode_info.bios_hardcoded_edid_size, GFP_KERNEL);
-       }
-       return NULL;
+       return drm_edid_duplicate(drm_edid_raw(adev->mode_info.bios_hardcoded_edid));
 }
 
 static void amdgpu_connector_get_edid(struct drm_connector *connector)
index d002b845d8acc2d4016748e4f5a821e8e2433801..5e3faefc5510914e8865147b9788e7093517eeb7 100644 (file)
@@ -51,6 +51,7 @@ struct amdgpu_encoder;
 struct amdgpu_router;
 struct amdgpu_hpd;
 struct edid;
+struct drm_edid;
 
 #define to_amdgpu_crtc(x) container_of(x, struct amdgpu_crtc, base)
 #define to_amdgpu_connector(x) container_of(x, struct amdgpu_connector, base)
@@ -326,8 +327,7 @@ struct amdgpu_mode_info {
        /* FMT dithering */
        struct drm_property *dither_property;
        /* hardcoded DFP edid from BIOS */
-       struct edid *bios_hardcoded_edid;
-       int bios_hardcoded_edid_size;
+       const struct drm_edid *bios_hardcoded_edid;
 
        /* firmware flags */
        u32 firmware_flags;
index 6415d0d039e1d11e8d4221edd43f15ddfa8b2f4b..e5f508d34ed83e676fe2317044c581495ed8c7c5 100644 (file)
@@ -549,7 +549,7 @@ static int amdgpu_vkms_sw_fini(void *handle)
 
        adev->mode_info.mode_config_initialized = false;
 
-       kfree(adev->mode_info.bios_hardcoded_edid);
+       drm_edid_free(adev->mode_info.bios_hardcoded_edid);
        kfree(adev->amdgpu_vkms_output);
        return 0;
 }
index ebf83fee43bb99267c22740a7c0f88a243159c24..8defca3705d5130ceb579cc385e519ccfb74409a 100644 (file)
@@ -2064,23 +2064,18 @@ amdgpu_atombios_encoder_get_lcd_info(struct amdgpu_encoder *encoder)
                                case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
                                        fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
                                        if (fake_edid_record->ucFakeEDIDLength) {
-                                               struct edid *edid;
+                                               const struct drm_edid *edid;
                                                int edid_size;
 
                                                if (fake_edid_record->ucFakeEDIDLength == 128)
                                                        edid_size = fake_edid_record->ucFakeEDIDLength;
                                                else
                                                        edid_size = fake_edid_record->ucFakeEDIDLength * 128;
-                                               edid = kmemdup(&fake_edid_record->ucFakeEDIDString[0],
-                                                              edid_size, GFP_KERNEL);
-                                               if (edid) {
-                                                       if (drm_edid_is_valid(edid)) {
-                                                               adev->mode_info.bios_hardcoded_edid = edid;
-                                                               adev->mode_info.bios_hardcoded_edid_size = edid_size;
-                                                       } else {
-                                                               kfree(edid);
-                                                       }
-                                               }
+                                               edid = drm_edid_alloc(fake_edid_record->ucFakeEDIDString, edid_size);
+                                               if (drm_edid_valid(edid))
+                                                       adev->mode_info.bios_hardcoded_edid = edid;
+                                               else
+                                                       drm_edid_free(edid);
                                                record += struct_size(fake_edid_record,
                                                                      ucFakeEDIDString,
                                                                      edid_size);
index dddb5fe16f2c53aab58ae5b66482395002b00572..742adbc460c9db1502a8d9294f340ecc3ff22527 100644 (file)
@@ -2846,7 +2846,7 @@ static int dce_v10_0_sw_fini(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-       kfree(adev->mode_info.bios_hardcoded_edid);
+       drm_edid_free(adev->mode_info.bios_hardcoded_edid);
 
        drm_kms_helper_poll_fini(adev_to_drm(adev));
 
index 11780e4d7e9f9df9b486fd5405cf4869b45643c7..8d46ebadfa4663ed940534a99766dcd53a665c1a 100644 (file)
@@ -2973,7 +2973,7 @@ static int dce_v11_0_sw_fini(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-       kfree(adev->mode_info.bios_hardcoded_edid);
+       drm_edid_free(adev->mode_info.bios_hardcoded_edid);
 
        drm_kms_helper_poll_fini(adev_to_drm(adev));
 
index 05c0df97f01d35b2d5c35a059b3ed6d24ed57c1e..f08dc6a3886f19c99b3941ff8eb95ffb28c18673 100644 (file)
@@ -2745,7 +2745,7 @@ static int dce_v6_0_sw_fini(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-       kfree(adev->mode_info.bios_hardcoded_edid);
+       drm_edid_free(adev->mode_info.bios_hardcoded_edid);
 
        drm_kms_helper_poll_fini(adev_to_drm(adev));
 
index dc73e301d9370098cf72dd323bf0ac11c1d4bc73..a6a3adf2ae134f560c46bae56f1be897bea50192 100644 (file)
@@ -2766,7 +2766,7 @@ static int dce_v8_0_sw_fini(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-       kfree(adev->mode_info.bios_hardcoded_edid);
+       drm_edid_free(adev->mode_info.bios_hardcoded_edid);
 
        drm_kms_helper_poll_fini(adev_to_drm(adev));