From: Guenter Roeck <linux@roeck-us.net>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] usb: typec: tcpm: Fix a signedness bug in tcpm_fw_get_caps()
Date: Thu, 26 Sep 2019 12:53:10 +0000 [thread overview]
Message-ID: <20190926125310.GA9967@roeck-us.net> (raw)
In-Reply-To: <20190925110219.GN3264@mwanda>
On Wed, Sep 25, 2019 at 02:02:19PM +0300, Dan Carpenter wrote:
> The "port->typec_caps.data" and "port->typec_caps.type" variables are
> enums and in this context GCC will treat them as an unsigned int so they
> can never be less than zero.
>
> Fixes: ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/usb/typec/tcpm/tcpm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 96562744101c..d3b63e000ae2 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -4410,7 +4410,7 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,
> ret = fwnode_property_read_string(fwnode, "data-role", &cap_str);
> if (ret = 0) {
> port->typec_caps.data = typec_find_port_data_role(cap_str);
> - if (port->typec_caps.data < 0)
> + if ((int)port->typec_caps.data < 0)
> return -EINVAL;
Doesn't that also cause a warning about overwriting error return codes ?
I would prefer something like
ret = typec_find_port_data_role(cap_str);
if (ret < 0)
return ret;
port->typec_caps.data = ret;
Guenter
> }
>
> @@ -4419,7 +4419,7 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,
> return ret;
>
> port->typec_caps.type = typec_find_port_power_role(cap_str);
> - if (port->typec_caps.type < 0)
> + if ((int)port->typec_caps.type < 0)
> return -EINVAL;
> port->port_type = port->typec_caps.type;
>
> --
> 2.20.1
>
WARNING: multiple messages have this Message-ID (diff)
From: Guenter Roeck <linux@roeck-us.net>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] usb: typec: tcpm: Fix a signedness bug in tcpm_fw_get_caps()
Date: Thu, 26 Sep 2019 05:53:10 -0700 [thread overview]
Message-ID: <20190926125310.GA9967@roeck-us.net> (raw)
In-Reply-To: <20190925110219.GN3264@mwanda>
On Wed, Sep 25, 2019 at 02:02:19PM +0300, Dan Carpenter wrote:
> The "port->typec_caps.data" and "port->typec_caps.type" variables are
> enums and in this context GCC will treat them as an unsigned int so they
> can never be less than zero.
>
> Fixes: ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/usb/typec/tcpm/tcpm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 96562744101c..d3b63e000ae2 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -4410,7 +4410,7 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,
> ret = fwnode_property_read_string(fwnode, "data-role", &cap_str);
> if (ret == 0) {
> port->typec_caps.data = typec_find_port_data_role(cap_str);
> - if (port->typec_caps.data < 0)
> + if ((int)port->typec_caps.data < 0)
> return -EINVAL;
Doesn't that also cause a warning about overwriting error return codes ?
I would prefer something like
ret = typec_find_port_data_role(cap_str);
if (ret < 0)
return ret;
port->typec_caps.data = ret;
Guenter
> }
>
> @@ -4419,7 +4419,7 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,
> return ret;
>
> port->typec_caps.type = typec_find_port_power_role(cap_str);
> - if (port->typec_caps.type < 0)
> + if ((int)port->typec_caps.type < 0)
> return -EINVAL;
> port->port_type = port->typec_caps.type;
>
> --
> 2.20.1
>
next prev parent reply other threads:[~2019-09-26 12:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-25 11:02 [PATCH] usb: typec: tcpm: Fix a signedness bug in tcpm_fw_get_caps() Dan Carpenter
2019-09-25 11:02 ` Dan Carpenter
2019-09-26 12:53 ` Guenter Roeck [this message]
2019-09-26 12:53 ` Guenter Roeck
2019-10-01 11:54 ` Dan Carpenter
2019-10-01 11:54 ` Dan Carpenter
2019-10-01 13:40 ` Guenter Roeck
2019-10-01 13:40 ` Guenter Roeck
2019-10-01 12:01 ` [PATCH v2] usb: typec: tcpm: " Dan Carpenter
2019-10-01 12:01 ` Dan Carpenter
2019-10-01 12:04 ` Heikki Krogerus
2019-10-01 12:04 ` Heikki Krogerus
2019-10-01 13:42 ` Guenter Roeck
2019-10-01 13:42 ` 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=20190926125310.GA9967@roeck-us.net \
--to=linux@roeck-us.net \
--cc=dan.carpenter@oracle.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.