diff mbox series

[-next,v3] drm/amd/amdgpu: Use kmemdup to simplify kmalloc and memcpy logic

Message ID 20230816021958.1921084-1-chenjiahao16@huawei.com (mailing list archive)
State New, archived
Headers show
Series [-next,v3] drm/amd/amdgpu: Use kmemdup to simplify kmalloc and memcpy logic | expand

Commit Message

Chen Jiahao Aug. 16, 2023, 2:19 a.m. UTC
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>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

Comments

Alex Deucher Aug. 16, 2023, 8:53 p.m. UTC | #1
Applied.  Thanks!

Alex

On Tue, Aug 15, 2023 at 10:20 PM Chen Jiahao <chenjiahao16@huawei.com> wrote:
>
> 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>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 11 ++---------
>  1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> index d34037b85cf8..7473a42f7d45 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> @@ -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;
>  }
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
index d34037b85cf8..7473a42f7d45 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
@@ -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;
 }