Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] video/hdmi: hdmi_infoframe_pack_only() missing EMP support - [Medium] video/hdmi: missing bounds and type checks in hdmi_emp_infoframe_vtem_pack() - [Low] video/hdmi: missing @vtem kernel-doc entry in union hdmi_infoframe --
commit 435f43f92e62fa2ad37ec03ba43478dd2a0e2bba Author: Derek Foreman <[email protected]> video/hdmi: Add VTEM EMP packing This commit adds structures and helpers to initialize, pack, and log HDMI Video Timing Extended Metadata (VTEM) Extended Metadata Packets (EMPs) for Variable Refresh Rate support. > diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c > index 45b42f14a7503..ed9abc7ad2285 100644 > --- a/drivers/video/hdmi.c > +++ b/drivers/video/hdmi.c > @@ -983,6 +983,10 @@ hdmi_infoframe_pack(union hdmi_infoframe *frame, > length = hdmi_vendor_any_infoframe_pack(&frame->vendor, > buffer, size); > break; > + case HDMI_INFOFRAME_TYPE_EMP: > + length = hdmi_emp_infoframe_vtem_pack(&frame->vtem, > + buffer, size); > + break; > default: > WARN(1, "Bad infoframe type %d\n", frame->any.type); > length = -EINVAL; [Severity: Medium] As reported by Sashiko on RFC [1], hdmi_infoframe_pack() handles HDMI_INFOFRAME_TYPE_EMP, but hdmi_infoframe_pack_only() in drivers/video/hdmi.c was not updated to handle it: drivers/video/hdmi.c:hdmi_infoframe_pack_only() { switch (frame->any.type) { case HDMI_INFOFRAME_TYPE_AVI: ... case HDMI_INFOFRAME_TYPE_VENDOR: length = hdmi_vendor_any_infoframe_pack_only(&frame->vendor, buffer, size); break; default: WARN(1, "Bad infoframe type %d\n", frame->any.type); length = -EINVAL; } } If a driver packs an EMP infoframe stored in union hdmi_infoframe via hdmi_infoframe_pack_only(), won't it hit the default branch, trigger the WARN(1), and fail with -EINVAL? Also, since hdmi_emp_infoframe_vtem_pack() does not modify its vtem argument, should its parameter be const struct hdmi_emp_infoframe_vtem * (or have a corresponding _pack_only helper) so hdmi_infoframe_pack_only() can call it with a const union hdmi_infoframe *? [ ... ] > @@ -1919,3 +1951,66 @@ int hdmi_infoframe_unpack(union hdmi_infoframe *frame, > return ret; > } > EXPORT_SYMBOL(hdmi_infoframe_unpack); > + > +/** > + * hdmi_emp_infoframe_vtem_init() - initialize an HDMI VTEM EMP > + * @emp: HDMI VTEM EMP > + */ > +void hdmi_emp_infoframe_vtem_init(struct hdmi_emp_infoframe_vtem *emp) > +{ > + memset(emp, 0, sizeof(*emp)); > + emp->type = HDMI_INFOFRAME_TYPE_EMP; > +} > +EXPORT_SYMBOL(hdmi_emp_infoframe_vtem_init); > + > +/** > + * hdmi_emp_infoframe_vtem_pack() - pack a vtem into a binary buffer > + * @vtem: pointer to &struct hdmi_emp_infoframe_vtem to pack > + * @buffer: pointer to pre-allocated output buffer > + * @size: maximum size in bytes of @buffer > + * > + * Pack a VTEM infoframe struct into a binary buffer in a way that's suitable > + * to be sent out over the wire. > + * > + * Returns the number of bytes packed into the binary buffer or a negative > + * error code on failure. > + */ > +ssize_t hdmi_emp_infoframe_vtem_pack(struct hdmi_emp_infoframe_vtem *vtem, > + void *buffer, size_t size) > +{ > + u8 *ptr = buffer; > + > + if (size < HDMI_INFOFRAME_SIZE(VTEM)) > + return -EINVAL; > + > + /* 4 bits max */ > + if (vtem->fva_factor_m1 > 0xF) > + return -EINVAL; > + > + memset(buffer, 0, size); > + > + /* Header Data */ > + ptr[0] = vtem->type; > + ptr[1] = BIT(7) | BIT(6); > + ptr[2] = 0; > + > + ptr[3] = BIT(7) | BIT(2); > + > + ptr[4] = 0; > + ptr[5] = 1; > + ptr[6] = 0; > + ptr[7] = 1; > + ptr[8] = 0; > + ptr[9] = 4; > + > + /* This is where the VTEM part starts */ > + ptr[10] = (vtem->fva_factor_m1 << 4) | > + (vtem->m_const ? BIT(1) : 0) | > + (vtem->game_vrr_en ? BIT(0) : 0); > + ptr[11] = vtem->base_vfront; > + ptr[12] = vtem->base_refresh_rate >> 8 & 0x3; > + ptr[13] = vtem->base_refresh_rate & 0xFF; > + > + return 14; > +} > +EXPORT_SYMBOL(hdmi_emp_infoframe_vtem_pack); [Severity: Medium] As reported by Sashiko on RFC [2], hdmi_emp_infoframe_vtem_pack() checks that vtem->fva_factor_m1 fits in 4 bits and returns -EINVAL if exceeded, but silently masks the u16 vtem->base_refresh_rate to 10 bits when writing ptr[12] and ptr[13] instead of rejecting values above 0x3ff. It also writes ptr[0] = vtem->type without verifying that vtem->type is HDMI_INFOFRAME_TYPE_EMP. In the DRM HDMI state helper path added later in this series, drm_atomic_helper_connector_hdmi_check() calls hdmi_validate_vrr(), which returns early when new_crtc_state->vrr_enabled is false and skips its refresh rate check, while hdmi_generate_emp_infoframe_vtem() still runs and sets vtem->base_refresh_rate from drm_mode_vrefresh(&crtc_state->mode) for non-VIC modes before calling hdmi_infoframe_pack(). Should hdmi_emp_infoframe_vtem_pack() validate that vtem->base_refresh_rate <= 0x3ff and vtem->type == HDMI_INFOFRAME_TYPE_EMP, returning -EINVAL on invalid input rather than transmitting a truncated or malformed packet? > diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h > index b80a5ee63bb23..71e2b36896afe 100644 > --- a/include/linux/hdmi.h > +++ b/include/linux/hdmi.h [ ... ] > @@ -457,6 +475,7 @@ union hdmi_infoframe { > union hdmi_vendor_any_infoframe vendor; > struct hdmi_audio_infoframe audio; > struct hdmi_drm_infoframe drm; > + struct hdmi_emp_infoframe_vtem vtem; > }; [Severity: Low] This isn't a runtime bug, but union hdmi_infoframe in include/linux/hdmi.h has a kernel-doc comment block above it (included by Documentation/gpu/drm-kms-helpers.rst): include/linux/hdmi.h: /** * union hdmi_infoframe - overall union of all abstract infoframe representations * @any: generic infoframe * @avi: avi infoframe * @spd: spd infoframe * @vendor: union of all vendor infoframes * @audio: audio infoframe * @drm: Dynamic Range and Mastering infoframe Should an @vtem entry be added to the kernel-doc comment for union hdmi_infoframe to avoid a scripts/kernel-doc warning during W=1 or htmldocs builds? [1] https://lore.kernel.org/r/[email protected] [2] https://lore.kernel.org/r/[email protected] -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=3
