Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/vkms: raw 64-bit divisions in apply_lut32_to_channel_value() break 32-bit builds - [Medium] drm/vkms: NULL dereference on init failure in vkms_initialize_color_pipeline() --
commit 780023413d21504e42acdc03ff98ae1aafe4ed37 Author: Oarora Etimis <[email protected]> drm/vkms: add a programmable 1D LUT colorop This commit adds a 256-entry 1D LUT colorop with linear interpolation to the VKMS plane color pipeline, implements its lookup in the composer, and adds KUnit tests for the interpolation. > diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c > b/drivers/gpu/drm/vkms/vkms_colorop.c > index 01b1ed2a59911..584305b0abfdd 100644 > --- a/drivers/gpu/drm/vkms/vkms_colorop.c > +++ b/drivers/gpu/drm/vkms/vkms_colorop.c > @@ -119,6 +119,25 @@ static int vkms_initialize_color_pipeline(struct > drm_plane *plane, struct drm_pr > > drm_colorop_set_next_property(ops[i - 1], ops[i]); > > + i++; > + > + /* 6th op: 1D LUT */ > + ops[i] = kzalloc_obj(*ops[i]); > + if (!ops[i]) { > + drm_err(dev, "KMS: Failed to allocate colorop\n"); > + ret = -ENOMEM; > + goto cleanup; > + } > + > + ret = drm_plane_colorop_curve_1d_lut_init(dev, ops[i], plane, > &vkms_colorop_funcs, > + VKMS_LUT1D_SIZE, > + > DRM_COLOROP_LUT1D_INTERPOLATION_LINEAR, > + > DRM_COLOROP_FLAG_ALLOW_BYPASS); > + if (ret) > + goto cleanup; [Severity: Medium] Can this error jump dereference a NULL pointer in drm_colorop_cleanup()? If drm_plane_colorop_curve_1d_lut_init() -> drm_plane_colorop_init() fails in drm_mode_object_add(), it returns before setting ops[i]->dev or linking ops[i]->head: drivers/gpu/drm/drm_colorop.c:drm_plane_colorop_init() { ... ret = drm_mode_object_add(dev, &colorop->base, DRM_MODE_OBJECT_COLOROP); if (ret) return ret; colorop->base.properties = &colorop->properties; colorop->dev = dev; ... list_add_tail(&colorop->head, &config->colorop_list); ... } The cleanup loop in vkms_initialize_color_pipeline() iterates up to j <= i and calls drm_colorop_cleanup(ops[i]), which runs list_del(&colorop->head) on zeroed list pointers and dereferences colorop->dev. > diff --git a/drivers/gpu/drm/vkms/vkms_composer.c > b/drivers/gpu/drm/vkms/vkms_composer.c > index 2cd909bc8adcf..e00d1d0b2f2d9 100644 > --- a/drivers/gpu/drm/vkms/vkms_composer.c > +++ b/drivers/gpu/drm/vkms/vkms_composer.c [ ... ] > @@ -198,6 +201,61 @@ VISIBLE_IF_KUNIT u16 apply_lut_to_channel_value(const > struct vkms_color_lut *lut [ ... ] > +VISIBLE_IF_KUNIT u16 apply_lut32_to_channel_value(const struct > drm_color_lut32 *lut, > + u32 lut_size, u16 > channel_value, > + enum lut_channel channel) > +{ > + u64 position; > + u32 index, fraction; > + s64 delta, result; > + u16 floor_value, ceil_value; > + > + if (!lut_size) > + return channel_value; > + > + if (lut_size == 1) > + return lut32_channel_value(&lut[0], channel); > + > + position = (u64)channel_value * (lut_size - 1); > + index = position / U16_MAX; > + > + if (index >= lut_size - 1) > + return lut32_channel_value(&lut[lut_size - 1], channel); > + > + fraction = position - (u64)index * U16_MAX; > + > + floor_value = lut32_channel_value(&lut[index], channel); > + ceil_value = lut32_channel_value(&lut[index + 1], channel); > + > + delta = (s64)ceil_value - (s64)floor_value; > + result = (s64)floor_value + > + DIV_ROUND_CLOSEST(delta * fraction, (s64)U16_MAX); [Severity: High] Do the 64-bit divisions in apply_lut32_to_channel_value() break 32-bit builds? position is u64 and delta is s64, so dividing position by U16_MAX with / and dividing delta * fraction by (s64)U16_MAX with DIV_ROUND_CLOSEST() emit __udivdi3 and __divdi3 libcalls on 32-bit architectures, failing at link or modpost time when CONFIG_DRM_VKMS is enabled. Using helpers from linux/math64.h such as div_u64_rem() and DIV_S64_ROUND_CLOSEST() avoids raw 64-bit divisions. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=4
