Linux USB
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Xu Yang <xu.yang_2@nxp.com>
Cc: linux@roeck-us.net, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, linux-imx@nxp.com, jun.li@nxp.com
Subject: Re: [PATCH] usb: typec: tcpm: fix warning when handle discover_identity message
Date: Wed, 15 Feb 2023 15:42:02 +0200	[thread overview]
Message-ID: <Y+zhKhCMeJ654XtE@kuha.fi.intel.com> (raw)
In-Reply-To: <20230215113136.2838773-1-xu.yang_2@nxp.com>

Hi,

On Wed, Feb 15, 2023 at 07:31:36PM +0800, Xu Yang wrote:
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 7f39cb9b3429..914bbaf4e25e 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -1445,10 +1445,19 @@ static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams)
>  static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
>  			   const u32 *data, int cnt)
>  {
> +	u32 vdo_hdr = port->vdo_data[0];
> +
>  	WARN_ON(!mutex_is_locked(&port->lock));
>  
> -	/* Make sure we are not still processing a previous VDM packet */
> -	WARN_ON(port->vdm_state > VDM_STATE_DONE);
> +	/* If is sending discover_identity, handle received message firstly */
> +	if (PD_VDO_SVDM(vdo_hdr) &&
> +		PD_VDO_CMD(vdo_hdr) == CMD_DISCOVER_IDENT) {

One line is enough.

> +		port->send_discover = true;
> +		mod_send_discover_delayed_work(port,
> +					SEND_DISCOVER_RETRY_MS);

Ditto.

> +	} else
> +		/* Make sure we are not still processing a previous VDM packet */
> +		WARN_ON(port->vdm_state > VDM_STATE_DONE);

You need braces around the else statement in this case.

>  
>  	port->vdo_count = cnt + 1;
>  	port->vdo_data[0] = header;
> @@ -1950,9 +1959,11 @@ static void vdm_run_state_machine(struct tcpm_port *port)
>  				res = tcpm_ams_start(port, DISCOVER_IDENTITY);
>  				if (res == 0)
>  					port->send_discover = false;
> -				else if (res == -EAGAIN)
> +				else if (res == -EAGAIN) {
> +					port->vdo_data[0] = 0;
>  					mod_send_discover_delayed_work(port,
>  								       SEND_DISCOVER_RETRY_MS);
> +				}
>  				break;
>  			case CMD_DISCOVER_SVID:
>  				res = tcpm_ams_start(port, DISCOVER_SVIDS);
> @@ -2035,6 +2046,7 @@ static void vdm_run_state_machine(struct tcpm_port *port)
>  			unsigned long timeout;
>  
>  			port->vdm_retries = 0;
> +			port->vdo_data[0] = 0;
>  			port->vdm_state = VDM_STATE_BUSY;
>  			timeout = vdm_ready_timeout(vdo_hdr);
>  			mod_vdm_delayed_work(port, timeout);

thanks,

-- 
heikki

  reply	other threads:[~2023-02-15 13:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15 11:31 [PATCH] usb: typec: tcpm: fix warning when handle discover_identity message Xu Yang
2023-02-15 13:42 ` Heikki Krogerus [this message]
2023-02-16  2:55   ` [EXT] " Xu Yang
2023-02-15 15:26 ` Guenter Roeck
2023-02-16  2:57   ` [EXT] " Xu Yang

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=Y+zhKhCMeJ654XtE@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jun.li@nxp.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=xu.yang_2@nxp.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