From: Jani Nikula <jani.nikula@linux.intel.com>
To: "Thomas Weißschuh" <linux@weissschuh.net>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Xinhui Pan" <Xinhui.Pan@amd.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
"Thomas Weißschuh" <linux@weissschuh.net>
Subject: Re: [PATCH v2 1/2] drm/amdgpu: convert bios_hardcoded_edid to drm_edid
Date: Mon, 29 Jul 2024 12:46:30 +0300 [thread overview]
Message-ID: <877cd4zg21.fsf@intel.com> (raw)
In-Reply-To: <20240726-amdgpu-edid-bios-v2-1-8a0326654253@weissschuh.net>
On Fri, 26 Jul 2024, Thomas Weißschuh <linux@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@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
next prev parent reply other threads:[~2024-07-29 9:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-26 13:40 [PATCH v2 0/2] drm/{amdgpu,radeon}: convert bios_hardcoded_edid to drm_edid Thomas Weißschuh
2024-07-26 13:40 ` [PATCH v2 1/2] drm/amdgpu: " Thomas Weißschuh
2024-07-29 9:46 ` Jani Nikula [this message]
2024-07-26 13:40 ` [PATCH v2 2/2] drm/radeon: " Thomas Weißschuh
2024-07-26 14:24 ` Alex Deucher
2024-07-29 9:47 ` Jani Nikula
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877cd4zg21.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=Xinhui.Pan@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.