From: Jani Nikula <jani.nikula@linux.intel.com>
To: Luca Coelho <luciano.coelho@intel.com>, intel-gfx@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 4/4] drm/i915/display: harden shift in intel_pmdemand_update_phys_mask()
Date: Tue, 19 May 2026 15:08:04 +0300 [thread overview]
Message-ID: <6162483ab91a8d80f313b4668c105a9afbd3fa61@intel.com> (raw)
In-Reply-To: <20260519112243.1454375-5-luciano.coelho@intel.com>
On Tue, 19 May 2026, Luca Coelho <luciano.coelho@intel.com> wrote:
> BIT() takes a non-negative shift amount, but phy is of type enum phy,
> which can in theory be PHY_NONE (-1).
>
> This is not a problem with the current implementation, because phy is
> always valid when this code is reached (Type-C encoders are rejected
> earlier), but it's more robust to store it as unsigned int so the
> shifts are always well-defined.
>
> Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
> ---
> drivers/gpu/drm/i915/display/intel_pmdemand.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_pmdemand.c b/drivers/gpu/drm/i915/display/intel_pmdemand.c
> index 7819b724795b..d02ac2408e29 100644
> --- a/drivers/gpu/drm/i915/display/intel_pmdemand.c
> +++ b/drivers/gpu/drm/i915/display/intel_pmdemand.c
> @@ -150,7 +150,7 @@ intel_pmdemand_update_phys_mask(struct intel_display *display,
> struct intel_pmdemand_state *pmdemand_state,
> bool set_bit)
> {
> - enum phy phy;
> + unsigned int phy;
I think it's useful to keep the enum here. That's the type.
I also don't believe in using unsigned types to enforce something is
positive, because this just turns -1 into 4294967295, which isn't better
at all.
I'd rather see a (redundant and silly) assert for phy being >= 0 than
using this trick to enforce it's >= 0.
But let's take a step back instead.
Look at all the places that reference PHY_NONE. Looks like
icl_aux_pw_to_phy() is the only place that actually uses PHY_NONE, and
all the other places are there just to work around the fact that
theoretically phy might be < 0. Which is never. And the return value of
icl_aux_pw_to_phy() is never even checked, it's just passed directly to
phy_name().
Maybe the solution is to just open code icl_aux_pw_to_phy(), handling
encoder being NULL inline, and nuke PHY_NONE and the checks for PHY_NONE
altogether?
*shrug*
BR,
Jani.
>
> if (DISPLAY_VER(display) < 14)
> return;
--
Jani Nikula, Intel
next prev parent reply other threads:[~2026-05-19 12:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 11:11 [PATCH 0/4] drm/i915/display: harden some bit-shifting operations Luca Coelho
2026-05-19 11:11 ` [PATCH 1/4] drm/i915/display: harden masks in HSW_AUD_PIN_ELD_CP_VLD macros Luca Coelho
2026-05-19 11:49 ` Jani Nikula
2026-05-21 6:47 ` Luca Coelho
2026-05-19 11:11 ` [PATCH 2/4] drm/i915/display: harden shifts in ICL_DPCLKA_CFGCR0_DDI_CLK_SEL macros Luca Coelho
2026-05-19 11:50 ` Jani Nikula
2026-05-19 11:11 ` [PATCH 3/4] drm/i915/display: harden shift in intel_ddi_compute_config_late() Luca Coelho
2026-05-19 11:11 ` [PATCH 4/4] drm/i915/display: harden shift in intel_pmdemand_update_phys_mask() Luca Coelho
2026-05-19 12:08 ` Jani Nikula [this message]
2026-05-19 13:41 ` ✓ i915.CI.BAT: success for drm/i915/display: harden some bit-shifting operations Patchwork
2026-05-20 13:52 ` ✓ i915.CI.Full: " Patchwork
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=6162483ab91a8d80f313b4668c105a9afbd3fa61@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=luciano.coelho@intel.com \
/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