From 5631f6a0436ac30eecfb2e6fdcd0a517f90add8a Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Thu, 16 Feb 2023 22:44:59 +0200 Subject: [PATCH] drm/displayid: return struct displayid_header from validate_displayid() Avoid figuring out the header pointer multiple times. Cc: Iaroslav Boliukin Cc: Dmitry Osipenko Signed-off-by: Jani Nikula Tested-by: Dmitry Osipenko Reviewed-by: Dmitry Osipenko Signed-off-by: Dmitry Osipenko Link: https://patchwork.freedesktop.org/patch/msgid/e840c744d165608a41db5a5e2bd4b0205783c697.1676580180.git.jani.nikula@intel.com --- drivers/gpu/drm/drm_displayid.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_displayid.c b/drivers/gpu/drm/drm_displayid.c index 7d03159..0de9b55 100644 --- a/drivers/gpu/drm/drm_displayid.c +++ b/drivers/gpu/drm/drm_displayid.c @@ -20,7 +20,8 @@ displayid_get_header(const u8 *displayid, int length, int index) return base; } -static int validate_displayid(const u8 *displayid, int length, int idx) +static const struct displayid_header * +validate_displayid(const u8 *displayid, int length, int idx) { int i, dispid_length; u8 csum = 0; @@ -28,7 +29,7 @@ static int validate_displayid(const u8 *displayid, int length, int idx) base = displayid_get_header(displayid, length, idx); if (IS_ERR(base)) - return PTR_ERR(base); + return base; DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n", base->rev, base->bytes, base->prod_id, base->ext_count); @@ -36,16 +37,16 @@ static int validate_displayid(const u8 *displayid, int length, int idx) /* +1 for DispID checksum */ dispid_length = sizeof(*base) + base->bytes + 1; if (dispid_length > length - idx) - return -EINVAL; + return ERR_PTR(-EINVAL); for (i = 0; i < dispid_length; i++) csum += displayid[idx + i]; if (csum) { DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum); - return -EINVAL; + return ERR_PTR(-EINVAL); } - return 0; + return base; } static const u8 *drm_find_displayid_extension(const struct drm_edid *drm_edid, @@ -54,7 +55,6 @@ static const u8 *drm_find_displayid_extension(const struct drm_edid *drm_edid, { const u8 *displayid = drm_find_edid_extension(drm_edid, DISPLAYID_EXT, ext_index); const struct displayid_header *base; - int ret; if (!displayid) return NULL; @@ -63,11 +63,10 @@ static const u8 *drm_find_displayid_extension(const struct drm_edid *drm_edid, *length = EDID_LENGTH - 1; *idx = 1; - ret = validate_displayid(displayid, *length, *idx); - if (ret) + base = validate_displayid(displayid, *length, *idx); + if (IS_ERR(base)) return NULL; - base = (const struct displayid_header *)&displayid[*idx]; *length = *idx + sizeof(*base) + base->bytes; return displayid; -- 2.7.4