[PATCH v2 1/2] drm/amdgpu: convert bios_hardcoded_edid to drm_edid

Jani Nikula jani.nikula at linux.intel.com
Mon Jul 29 09:46:30 UTC 2024


On Fri, 26 Jul 2024, Thomas Weißschuh <linux at weissschuh.net> wrote:
> 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 at weissschuh.net>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c |  6 +-----
>  drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h       |  4 ++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c       |  2 +-
>  drivers/gpu/drm/amd/amdgpu/atombios_encoders.c | 17 ++++++-----------
>  drivers/gpu/drm/amd/amdgpu/dce_v10_0.c         |  2 +-
>  drivers/gpu/drm/amd/amdgpu/dce_v11_0.c         |  2 +-
>  drivers/gpu/drm/amd/amdgpu/dce_v6_0.c          |  2 +-
>  drivers/gpu/drm/amd/amdgpu/dce_v8_0.c          |  2 +-
>  8 files changed, 14 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> index bd0fbdc5f55d..344e0a9ee08a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> @@ -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)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
> index d002b845d8ac..5e3faefc5510 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
> @@ -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;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> index 6415d0d039e1..e5f508d34ed8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> @@ -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;
>  }
> diff --git a/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c b/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
> index ebf83fee43bb..8defca3705d5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
> +++ b/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
> @@ -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;

Bikeshedding follows, up to you and the AMD maintainers to decide
whether it matters.

I know it's a bit verbose, but personally I've named the struct drm_edid
variables drm_edid everywhere when making conversions, just to make a
clear distinction from struct edid. And I like the fact that it forces
you to account for every place the variable is used, in particular
passing it to functions that don't have type safety e.g. kfree().

>  						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);

It also makes review easier because you don't have to check what goes on
outside of the patch context here. It just won't build.

> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> index dddb5fe16f2c..742adbc460c9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> @@ -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));
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> index 11780e4d7e9f..8d46ebadfa46 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> @@ -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));
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> index 05c0df97f01d..f08dc6a3886f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> @@ -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));
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> index dc73e301d937..a6a3adf2ae13 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> @@ -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));

-- 
Jani Nikula, Intel


More information about the dri-devel mailing list