linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] USB: serial: f81534: Detect errors from f81534_logic_to_phy_port()
@ 2016-12-18  9:19 Geert Uytterhoeven
  2016-12-19 11:11 ` Johan Hovold
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2016-12-18  9:19 UTC (permalink / raw)
  To: Johan Hovold, Ji-Ze Hong (Peter Hong), Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Geert Uytterhoeven

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, and drop the useless check for F81534_NUM_PORT, as the callee
always returns a valid port number in case of success.

Fixes: 0c9bd6004d258d46 ("USB: serial: add Fintek F81532/534 driver")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
v2:
  - Drop useless check for F81534_NUM_PORT.
---
 drivers/usb/serial/f81534.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c
index 8282a6a18fee83f6..22f23a429a95cb6a 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,11 @@ 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)
-		return -ENODEV;
+	ret = f81534_logic_to_phy_port(port->serial, port);
+	if (ret < 0)
+		return ret;
 
+	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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] USB: serial: f81534: Detect errors from f81534_logic_to_phy_port()
  2016-12-18  9:19 [PATCH v2] USB: serial: f81534: Detect errors from f81534_logic_to_phy_port() Geert Uytterhoeven
@ 2016-12-19 11:11 ` Johan Hovold
  2017-01-02  9:32   ` Johan Hovold
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2016-12-19 11:11 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Johan Hovold, Ji-Ze Hong (Peter Hong),
	Greg Kroah-Hartman, linux-usb, linux-kernel

On Sun, Dec 18, 2016 at 10:19:28AM +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.
> 
> Use an intermediate variable of type int to fix this.
> While at it, forward the actual error code instead of converting it to
> -ENODEV, and drop the useless check for F81534_NUM_PORT, as the callee
> always returns a valid port number in case of success.
> 
> Fixes: 0c9bd6004d258d46 ("USB: serial: add Fintek F81532/534 driver")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> v2:
>   - Drop useless check for F81534_NUM_PORT.

Thanks for the update. I'll queue this one up for -rc2.

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] USB: serial: f81534: Detect errors from f81534_logic_to_phy_port()
  2016-12-19 11:11 ` Johan Hovold
@ 2017-01-02  9:32   ` Johan Hovold
  0 siblings, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2017-01-02  9:32 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Johan Hovold, Ji-Ze Hong (Peter Hong),
	Greg Kroah-Hartman, linux-usb, linux-kernel

On Mon, Dec 19, 2016 at 12:11:15PM +0100, Johan Hovold wrote:
> On Sun, Dec 18, 2016 at 10:19:28AM +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.
> > 
> > Use an intermediate variable of type int to fix this.
> > While at it, forward the actual error code instead of converting it to
> > -ENODEV, and drop the useless check for F81534_NUM_PORT, as the callee
> > always returns a valid port number in case of success.
> > 
> > Fixes: 0c9bd6004d258d46 ("USB: serial: add Fintek F81532/534 driver")
> > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > ---
> > v2:
> >   - Drop useless check for F81534_NUM_PORT.
> 
> Thanks for the update. I'll queue this one up for -rc2.

Now applied, thanks.

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-02  9:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-18  9:19 [PATCH v2] USB: serial: f81534: Detect errors from f81534_logic_to_phy_port() Geert Uytterhoeven
2016-12-19 11:11 ` Johan Hovold
2017-01-02  9:32   ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).