AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Melissa Wen" <mwen@igalia.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 18/19] drm/amd/display: add support to post-blend 1D-Curve colorop
Date: Tue, 24 Nov 2026 18:42:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-231843@kernel.org> (raw)
In-Reply-To: <20261124181652.1333986-19-mwen@igalia.com>

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 <mwen@igalia.com>

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/20261124181652.1333986-1-mwen@igalia.com?part=18

  reply	other threads:[~2026-11-24 18:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 18:03 [PATCH v3 00/19] drm/drm_colorop: add post-blend colorop support to AMD display driver Melissa Wen
2026-11-24 18:03 ` [PATCH v3 01/19] drm/crtc: Add color pipeline to CRTC state Melissa Wen
2026-11-24 18:03 ` [PATCH v3 02/19] drm/colorop: Allow parenting colorop to CRTC Melissa Wen
2026-11-24 18:03 ` [PATCH v3 03/19] drm/atomic: handle CRTC colorops in drm_atomic_commit_set_colorop_state() Melissa Wen
2026-11-24 18:03 ` [PATCH v3 04/19] drm/atomic: duplicate CRTC colorop states Melissa Wen
2026-11-24 18:03 ` [PATCH v3 05/19] drm: Factor out common color_pipeline property initialization code Melissa Wen
2026-11-24 18:03 ` [PATCH v3 06/19] drm/crtc: Add COLOR_PIPELINE property Melissa Wen
2026-11-24 18:03 ` [PATCH v3 07/19] drm/atomic: track individual CRTC colorop updates Melissa Wen
2026-11-24 18:03 ` [PATCH v3 08/19] drm: Introduce DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE Melissa Wen
2026-11-24 18:03 ` [PATCH v3 09/19] drm/atomic: Print the color pipeline as part of the CRTC state print Melissa Wen
2026-11-24 18:03 ` [PATCH v3 10/19] drm/colorop: Factor out common paths from colorops helpers Melissa Wen
2026-11-24 18:36   ` sashiko-bot
2026-11-24 18:03 ` [PATCH v3 11/19] drm/colorop: Introduce colorop helpers for crtc Melissa Wen
2026-11-24 18:36   ` sashiko-bot
2026-11-24 18:03 ` [PATCH v3 12/19] drm/colorop: distinguish whether a colorop belongs to a plane or a CRTC Melissa Wen
2026-11-24 18:03 ` [PATCH v3 13/19] drm/drm_mode_object: hide deprecated CRTC color mgmt props if colorop is set Melissa Wen
2026-11-24 18:03 ` [PATCH v3 14/19] drm/atomic: set hidden CRTC color mgmt model to default values Melissa Wen
2026-11-24 18:42   ` sashiko-bot
2026-11-24 18:03 ` [PATCH v3 15/19] drm/drm_ioctl: guard DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE Melissa Wen
2026-11-24 18:03 ` [PATCH v3 16/19] drm/amd/display: move CRTC CTM color mgmt prop to check helper Melissa Wen
2026-11-24 18:03 ` [PATCH v3 17/19] drm/amd/display: enable post-blend CTM colorop Melissa Wen
2026-11-24 18:46   ` sashiko-bot
2026-11-24 18:03 ` [PATCH v3 18/19] drm/amd/display: add support to post-blend 1D-Curve colorop Melissa Wen
2026-11-24 18:42   ` sashiko-bot [this message]
2026-11-24 18:03 ` [PATCH v3 19/19] drm/amd/display: add support to post-blend 1D-LUT colorop Melissa Wen
2026-11-24 18:38   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-231843@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=mwen@igalia.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox