Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Medium] drm/amd/display: missing ogam_ram check when applying CRTC regamma colorop - [Medium] drm/amd/display: stale out_transfer_func.tf in __set_dm_crtc_colorop_regamma() - [Medium] drm/amd/display: colorop leak in amdgpu_dm_initialize_crtc_default_pipeline() - [Medium] drm/amd/display: unchecked kasprintf() in CRTC default pipeline init - [Low] drm/amd/display: unused param and variable in __set_dm_crtc_colorop_regamma() --
commit a10135e3487a34c61aa5df0ce12f0d6b9ae37b7c Author: Melissa Wen <[email protected]> drm/amd/display: add support to post-blend 1D-Curve colorop This commit adds a 1D curve regamma transfer function colorop to the AMD CRTC post-blend color pipeline and applies its state during atomic check and commit. > diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c > b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c > index 12665810708e2..f807a2e8c0f71 100644 > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c > @@ -1287,6 +1287,41 @@ __set_dm_crtc_colorop_3x4_matrix(struct drm_crtc_state > *crtc_state, > return 0; > } > > +static int > +__set_dm_crtc_colorop_regamma(struct drm_crtc_state *crtc_state, > + struct dc_stream_state *dc_stream_state, > + struct drm_colorop *colorop, > + struct dc_transfer_func *tf) > +{ > + struct drm_colorop_state *colorop_state = NULL; > + struct drm_atomic_commit *state = crtc_state->state; > + enum dc_transfer_func_predefined default_tf = TRANSFER_FUNCTION_LINEAR; > + struct drm_device *dev = crtc_state->state->dev; > + int ret = 0; > + > + tf->type = TF_TYPE_BYPASS; > + > + /* 1D Curve - Regamma TF */ > + if (colorop->type != DRM_COLOROP_1D_CURVE) > + return -EINVAL; [Severity: Medium] Does setting only tf->type = TF_TYPE_BYPASS leave a stale transfer function in dc_stream_state->out_transfer_func.tf when this colorop is bypassed? Other transfer function helpers use __set_tf_bypass(), which also resets tf->tf to TRANSFER_FUNCTION_LINEAR. Downstream DC paths such as set_avi_info_frame() and get_hdr_visual_confirm_color() check stream->out_transfer_func.tf without checking whether out_transfer_func.type is TF_TYPE_BYPASS, so a prior TRANSFER_FUNCTION_GAMMA22 or TRANSFER_FUNCTION_PQ value stays active for AVI InfoFrame colorimetry and HDR visual confirm even after regamma is bypassed. > + > + colorop_state = drm_atomic_get_new_colorop_state(state, colorop); > + if (!colorop_state) > + colorop_state = colorop->state; > + > + if (!colorop_state->bypass) { > + drm_dbg(dev, "Regamma TF colorop with ID: %d\n", > colorop->base.id); > + tf->type = TF_TYPE_DISTRIBUTED_POINTS; > + tf->tf = default_tf = > amdgpu_colorop_tf_to_dc_tf(colorop_state->curve_1d_type); [Severity: Low] dc_stream_state is unused in __set_dm_crtc_colorop_regamma(), and default_tf is assigned here without being read in this patch, which triggers -Wunused-but-set-variable under W=1 builds until commit "drm/amd/display: add support to post-blend 1D-LUT colorop" uses it. > + tf->sdr_ref_white_level = SDR_WHITE_LEVEL_INIT_VALUE; > + ret = __set_output_tf(tf, 0, 0, false); > + if (ret) > + return ret; > + } > + > + return 0; > +} > + > /* > * amdgpu_dm_crtc_set_colorop_properties: Set colorop props if programmable > by DC. > * @crtc_state: DRM crtc state > @@ -1312,6 +1347,7 @@ amdgpu_dm_crtc_set_colorop_properties(struct > drm_crtc_state *crtc_state, > { > struct drm_colorop *colorop = crtc_state->color_pipeline; > struct drm_device *dev = crtc_state->crtc->dev; > + struct dc_transfer_func *out_tf; > int ret; > > if (drm_WARN_ON(dev, !colorop)) > @@ -1319,6 +1355,28 @@ amdgpu_dm_crtc_set_colorop_properties(struct > drm_crtc_state *crtc_state, > > /* 3x4 matrix */ > ret = __set_dm_crtc_colorop_3x4_matrix(crtc_state, dc_stream_state, > colorop, check_only); > + if (ret) > + return ret; > + > + /* 1D Curve - REGAMMA TF */ > + colorop = colorop->next; > + if (!colorop) { > + drm_dbg(dev, "no regamma TF colorop found\n"); > + return -EINVAL; > + } [Severity: Medium] Should this check adev->dm.dc->caps.color.mpc.ogam_ram before requiring the regamma colorop? amdgpu_dm_initialize_crtc_default_pipeline() only appends the 1D curve colorop when mpc.ogam_ram is set, so when it is false the pipeline still registers with just the 3x4 CTM (ops[0]->next == NULL) and every atomic check or commit using that pipeline will fail here with -EINVAL. [ ... ] > diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c > b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c > index dcd497b644c11..f5991f29973d5 100644 > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c > @@ -311,6 +311,7 @@ int amdgpu_dm_initialize_crtc_default_pipeline(struct > drm_crtc *crtc, > { > struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS]; > struct drm_device *dev = crtc->dev; > + struct amdgpu_device *adev = drm_to_adev(dev); > int ret; > int i = 0; > > @@ -332,6 +333,25 @@ int amdgpu_dm_initialize_crtc_default_pipeline(struct > drm_crtc *crtc, > > i++; > > + if (adev->dm.dc->caps.color.mpc.ogam_ram) { > + /* 1D Curve - REGAMMA TF */ > + ops[i] = kzalloc_obj(*ops[0]); > + if (!ops[i]) { > + ret = -ENOMEM; > + goto cleanup; > + } > + > + ret = drm_crtc_colorop_curve_1d_init(dev, ops[i], crtc, > &dm_colorop_funcs, > + > amdgpu_dm_supported_shaper_tfs, > + > DRM_COLOROP_FLAG_ALLOW_BYPASS); > + if (ret) > + goto cleanup; [Severity: Medium] Does jumping to cleanup leak ops[i] if drm_crtc_colorop_curve_1d_init() fails before linking it into dev->mode_config.colorop_list? drm_common_colorop_init() returns early if drm_mode_object_add() fails before list_add_tail(&colorop->head, &config->colorop_list), and drm_colorop_pipeline_destroy() only frees colorops already on colorop_list. > + > + drm_colorop_set_next_property(ops[i-1], ops[i]); > + > + i++; > + } > + > list->name = kasprintf(GFP_KERNEL, "Color Pipeline %d", > ops[0]->base.id); > > return 0; [Severity: Medium] This problem wasn't introduced by this patch (it comes from commit "drm/amd/display: enable post-blend CTM colorop" earlier in the series), but what happens if kasprintf() returns NULL for list->name? Returning 0 skips drm_colorop_pipeline_destroy() and leaves a NULL name in pipelines[] when dm_crtc_init_colorops() calls drm_crtc_create_color_pipeline_property(), leading to a NULL pointer dereference in strlen(name) inside drm_property_add_enum(). -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=18
