Re: [PATCH 1/3] usb: typec: tcpm: only call get_current_limit() for cc=Rp-def
From: André Draszik
Date: Fri Oct 02 2026 - 05:51:32 EST
Hi Amit,
On Thu, 2026-10-01 at 22:51 +0000, Amit Sunil Dhamne via B4 Relay wrote:
> From: Amit Sunil Dhamne <amitsd@xxxxxxxxxx>
>
> tcpm_get_current_limit() folds the default label into the
> TYPEC_CC_RP_DEF case, so tcpc_dev::get_current_limit() is also called
> for CC states that do not advertise Rp, such as TYPEC_CC_OPEN,
> TYPEC_CC_RA and TYPEC_CC_RD. Its kerneldoc has always scoped it to
> cc=Rp-def:
>
> @get_current_limit:
> Optional; called by the tcpm core when configured as a snk
> and cc=Rp-def. This allows the tcpm to provide a fallback
> current-limit detection method for the cc=Rp-def case.
>
> A chip driver has nothing to interpret in the other states. Therefore,
> split the cases and report 0 when CC is not an Rp.
>
> Assisted-by: LLM
> Signed-off-by: Amit Sunil Dhamne <amitsd@xxxxxxxxxx>
> Reviewed-by: Badhri Jagan Sridharan <badhri@xxxxxxxxxx>
> ---
> drivers/usb/typec/tcpm/tcpm.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 2d6b14aa20856..2e7371ada8642 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -1268,7 +1268,7 @@ static int tcpm_set_vconn(struct tcpm_port *port, bool enable)
> static u32 tcpm_get_current_limit(struct tcpm_port *port)
> {
> enum typec_cc_status cc;
> - u32 limit;
> + u32 limit = 0;
Greedy init is usually not recommended, as it prevents the compiler from
warning about use of a variable without initialising a useful value.
Cheers,
Andre'
>
> cc = port->polarity ? port->cc2 : port->cc1;
> switch (cc) {
> @@ -1279,11 +1279,10 @@ static u32 tcpm_get_current_limit(struct tcpm_port *port)
> limit = 3000;
> break;
> case TYPEC_CC_RP_DEF:
> - default:
> if (port->tcpc->get_current_limit)
> limit = port->tcpc->get_current_limit(port->tcpc);
> - else
> - limit = 0;
> + break;
> + default:
> break;
> }
>