Message ID | 20190925110219.GN3264@mwanda (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | usb: typec: tcpm: Fix a signedness bug in tcpm_fw_get_caps() | expand |
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 >
On Thu, Sep 26, 2019 at 05:53:10AM -0700, Guenter Roeck wrote: > 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'm happy that you think there is a tool which generates warnings like that but it's just people manually complaining. :P I'll resend though. regards, dan carpenter
On 10/1/19 4:54 AM, Dan Carpenter wrote: > On Thu, Sep 26, 2019 at 05:53:10AM -0700, Guenter Roeck wrote: >> 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'm happy that you think there is a tool which generates warnings like > that but it's just people manually complaining. :P > I am quite sure there is, or at least used to be - I have seen such warnings. Maybe it was removed. Guenter
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; } @@ -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;
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(-)