Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1541860 > unrolled thread
| Started by | Geert Uytterhoeven <geert@linux-m68k.org> |
|---|---|
| First post | 2016-12-14 12:30 +0100 |
| Last post | 2016-12-15 16:30 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] USB: serial: f81534: Detect errors from f81534_logic_to_phy_port() Geert Uytterhoeven <geert@linux-m68k.org> - 2016-12-14 12:30 +0100
Re: [PATCH] USB: serial: f81534: Detect errors from f81534_logic_to_phy_port() Johan Hovold <johan@kernel.org> - 2016-12-15 16:30 +0100
| From | Geert Uytterhoeven <geert@linux-m68k.org> |
|---|---|
| Date | 2016-12-14 12:30 +0100 |
| Subject | [PATCH] USB: serial: f81534: Detect errors from f81534_logic_to_phy_port() |
| Message-ID | <sOfV0-5Pg-21@gated-at.bofh.it> |
With gcc 4.1.2:
drivers/usb/serial/f81534.c: In function ‘f81534_port_probe’:
drivers/usb/serial/f81534.c:1250: warning: comparison is always false due to limited range of data type
f81534_logic_to_phy_port() may return a negative error value, which is
ignored by assigning it to u8 f81534_port_private.phy_num.
Use an intermediate variable of type int to fix this.
While at it, forward the actual error code instead of converting it to
-ENODEV.
Fixes: 0c9bd6004d258d46 ("USB: serial: add Fintek F81532/534 driver")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
drivers/usb/serial/f81534.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c
index 8282a6a18fee83f6..2acad268f9d15f43 100644
--- a/drivers/usb/serial/f81534.c
+++ b/drivers/usb/serial/f81534.c
@@ -1237,6 +1237,7 @@ static int f81534_attach(struct usb_serial *serial)
static int f81534_port_probe(struct usb_serial_port *port)
{
struct f81534_port_private *port_priv;
+ int ret;
port_priv = devm_kzalloc(&port->dev, sizeof(*port_priv), GFP_KERNEL);
if (!port_priv)
@@ -1246,10 +1247,14 @@ static int f81534_port_probe(struct usb_serial_port *port)
mutex_init(&port_priv->mcr_mutex);
/* Assign logic-to-phy mapping */
- port_priv->phy_num = f81534_logic_to_phy_port(port->serial, port);
- if (port_priv->phy_num < 0 || port_priv->phy_num >= F81534_NUM_PORT)
+ ret = f81534_logic_to_phy_port(port->serial, port);
+ if (ret < 0)
+ return ret;
+
+ if (ret >= F81534_NUM_PORT)
return -ENODEV;
+ port_priv->phy_num = ret;
usb_set_serial_port_data(port, port_priv);
dev_dbg(&port->dev, "%s: port_number: %d, phy_num: %d\n", __func__,
port->port_number, port_priv->phy_num);
--
1.9.1
[toc] | [next] | [standalone]
| From | Johan Hovold <johan@kernel.org> |
|---|---|
| Date | 2016-12-15 16:30 +0100 |
| Subject | Re: [PATCH] USB: serial: f81534: Detect errors from f81534_logic_to_phy_port() |
| Message-ID | <sOG8O-7rb-7@gated-at.bofh.it> |
| In reply to | #1541860 |
On Wed, Dec 14, 2016 at 12:18:53PM +0100, Geert Uytterhoeven wrote:
> With gcc 4.1.2:
>
> drivers/usb/serial/f81534.c: In function ‘f81534_port_probe’:
> drivers/usb/serial/f81534.c:1250: warning: comparison is always false due to limited range of data type
>
> f81534_logic_to_phy_port() may return a negative error value, which is
> ignored by assigning it to u8 f81534_port_private.phy_num.
Thanks for fixing this.
> Use an intermediate variable of type int to fix this.
> While at it, forward the actual error code instead of converting it to
> -ENODEV.
>
> Fixes: 0c9bd6004d258d46 ("USB: serial: add Fintek F81532/534 driver")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> drivers/usb/serial/f81534.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c
> index 8282a6a18fee83f6..2acad268f9d15f43 100644
> --- a/drivers/usb/serial/f81534.c
> +++ b/drivers/usb/serial/f81534.c
> @@ -1237,6 +1237,7 @@ static int f81534_attach(struct usb_serial *serial)
> static int f81534_port_probe(struct usb_serial_port *port)
> {
> struct f81534_port_private *port_priv;
> + int ret;
>
> port_priv = devm_kzalloc(&port->dev, sizeof(*port_priv), GFP_KERNEL);
> if (!port_priv)
> @@ -1246,10 +1247,14 @@ static int f81534_port_probe(struct usb_serial_port *port)
> mutex_init(&port_priv->mcr_mutex);
>
> /* Assign logic-to-phy mapping */
> - port_priv->phy_num = f81534_logic_to_phy_port(port->serial, port);
> - if (port_priv->phy_num < 0 || port_priv->phy_num >= F81534_NUM_PORT)
> + ret = f81534_logic_to_phy_port(port->serial, port);
> + if (ret < 0)
> + return ret;
> +
> + if (ret >= F81534_NUM_PORT)
> return -ENODEV;
How about dropping the redundant >= F81534_NUM_PORT test as well as the
helper function will never return anything that large?
>
> + port_priv->phy_num = ret;
> usb_set_serial_port_data(port, port_priv);
> dev_dbg(&port->dev, "%s: port_number: %d, phy_num: %d\n", __func__,
> port->port_number, port_priv->phy_num);
Thanks,
Johan
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web