Re: [PATCH 1/2] usb: typec: tcpm: add interface for passing supported_pd_rev from tcpc_dev

From: Greg Kroah-Hartman
Date: Tue Feb 08 2022 - 03:42:05 EST


On Tue, Feb 08, 2022 at 04:20:25PM +0800, Potin Lai wrote:
> Current TCPM allways assume using PD_MAX_REV for negotiation,
> but for some USB controller only support PD 2.0, adding an interface
> for passing supported_pd_rev from tcpc_dev.
>
> Signed-off-by: Potin Lai <potin.lai@xxxxxxxxxxxx>
> ---
> drivers/usb/typec/tcpm/tcpm.c | 14 ++++++++++++--
> include/linux/usb/tcpm.h | 4 ++++
> 2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 59d4fa2443f2..31770fa8643d 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -571,6 +571,16 @@ static bool tcpm_port_is_disconnected(struct tcpm_port *port)
> port->cc2 == TYPEC_CC_OPEN)));
> }
>
> +static u32 tcpm_pd_supported_rev(struct tcpm_port *port)
> +{
> + u32 rev = PD_MAX_REV;
> +
> + if (port->tcpc->supported_pd_rev)
> + rev = port->tcpc->supported_pd_rev(port->tcpc);
> +
> + return (rev > PD_MAX_REV) ? PD_MAX_REV : rev;

Please spell this out in a real if statement to make it obvious:
if (rev > PD_MAX_REV)
return PD_MAX_REV
return rev

Or better yet:
return min(PD_MAX_REV, rev);

right?

thanks,

greg k-h