public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Ladislav Michl <oss-lists@triops.cz>
To: Jimmy Hu <hhhuuu@google.com>
Cc: linux@roeck-us.net, heikki.krogerus@linux.intel.com,
	gregkh@linuxfoundation.org, kyletso@google.com,
	badhri@google.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] usb: typec: tcpm: IS_ERR_OR_NULL check for port->partner
Date: Fri, 4 Aug 2023 11:24:16 +0200	[thread overview]
Message-ID: <ZMzDwEBwJSB5k5Ci@lenoch> (raw)
In-Reply-To: <20230804084928.1153600-1-hhhuuu@google.com>

Hi Jimmy,

On Fri, Aug 04, 2023 at 08:49:28AM +0000, Jimmy Hu wrote:
> port->partner may be an error or NULL, so we must check it with
> IS_ERR_OR_NULL() before dereferencing it.
> 
> Move the check to the beginning of the tcpm_handle_vdm_request function.
> 
> Fixes: 5e1d4c49fbc8 ("usb: typec: tcpm: Determine common SVDM Version")
> Signed-off-by: Jimmy Hu <hhhuuu@google.com>
> ---
>  drivers/usb/typec/tcpm/tcpm.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 829d75ebab42..2c6a0af155ab 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -1683,10 +1683,6 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev,
>  			      (VDO_SVDM_VERS(typec_get_negotiated_svdm_version(typec)));
>  		break;
>  	case CMDT_RSP_ACK:
> -		/* silently drop message if we are not connected */
> -		if (IS_ERR_OR_NULL(port->partner))
> -			break;
> -
>  		tcpm_ams_finish(port);
>  
>  		switch (cmd) {
> @@ -1792,6 +1788,12 @@ static void tcpm_handle_vdm_request(struct tcpm_port *port,
>  	u32 response[8] = { };
>  	int i, rlen = 0;
>  
> +	/* silently drop message if we are not connected */

...comment moved.

> +	if (IS_ERR_OR_NULL(port->partner)) {
> +		dev_warn(port->dev, "port partner is an error or NULL\n");

But code is actually not silent. Also, does the verbsity make sense? And
if it does, is knowing what error port->partner is containing usefull?

> +		return;
> +	}
> +
>  	for (i = 0; i < cnt; i++)
>  		p[i] = le32_to_cpu(payload[i]);
>  
> -- 
> 2.41.0.585.gd2178a4bd4-goog

  reply	other threads:[~2023-08-04  9:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-04  8:49 [PATCH v2] usb: typec: tcpm: IS_ERR_OR_NULL check for port->partner Jimmy Hu
2023-08-04  9:24 ` Ladislav Michl [this message]
2023-08-04 14:36   ` Guenter Roeck

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=ZMzDwEBwJSB5k5Ci@lenoch \
    --to=oss-lists@triops.cz \
    --cc=badhri@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=hhhuuu@google.com \
    --cc=kyletso@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /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