Skip to contentSkip to conversation

tty: serial: Add 8250-core based omap driver

PATCH In review Dan Carpenter 3 participants 5 messages Nov 12, 2014 – Nov 25, 2014 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

Hello Sebastian Andrzej Siewior,

The patch 61929cf0169d: "tty: serial: Add 8250-core based omap driver" from Sep 29, 2014, leads to the following static checker warning:

	drivers/tty/serial/8250/8250_omap.c:1025 omap8250_probe()
	warn: unsigned 'up.port.line' is never less than zero.

drivers/tty/serial/8250/8250_omap.c
1015
1016 if (pdev->dev.of_node) {
1017 up.port.line = of_alias_get_id(pdev->dev.of_node, "serial");
1018 of_property_read_u32(pdev->dev.of_node, "clock-frequency",
1019 &up.port.uartclk);
1020 priv->wakeirq = irq_of_parse_and_map(pdev->dev.of_node, 1);
1021 } else {
1022 up.port.line = pdev->id;
1023 }
1024

  1025          if (up.port.line < 0) {
                    ^^^^^^^^^^^^^^^^

Impossible.

1026 dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n",
1027 up.port.line);

  1028                  return -ENODEV;
                        ^^^^^^^^^^^^^^

It's better to preserve the error code normally.

1029 }

regards,
dan carpenter

#1 lore raw

PATCH 1/2 tty: serial: 8250: omap: line is unsigned, don't check < 0

Dan Carpenter reported:

|drivers/tty/serial/8250/8250_omap.c:1025 omap8250_probe()
|warn: unsigned 'up.port.line' is never less than zero.
|1025          if (up.port.line < 0) {

I (wrongly) assumed that line is an int and compiler didn't complain nor did sparse. Since of_alias_get_id() and pdev->id can get negative I check for the error via ret variable.

---
 drivers/tty/serial/8250/8250_omap.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/tty/serial/8250/8250_omap.c +8 -7
index 1681875f2996..907100eb8030 100644
@@ -1014,19 +1014,20 @@ static int omap8250_probe(struct platform_device *pdev)
 	up.port.unthrottle = omap_8250_unthrottle;
 
 	if (pdev->dev.of_node) {
-		up.port.line = of_alias_get_id(pdev->dev.of_node, "serial");
+		ret = of_alias_get_id(pdev->dev.of_node, "serial");
+
 		of_property_read_u32(pdev->dev.of_node, "clock-frequency",
 				     &up.port.uartclk);
 		priv->wakeirq = irq_of_parse_and_map(pdev->dev.of_node, 1);
 	} else {
-		up.port.line = pdev->id;
+		ret = pdev->id;
 	}
-
-	if (up.port.line < 0) {
-		dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n",
-			up.port.line);
-		return -ENODEV;
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to get alias/pdev id\n");
+		return ret;
 	}
+	up.port.line = ret;
+
 	if (!up.port.uartclk) {
 		up.port.uartclk = DEFAULT_CLK_SPEED;
 		dev_warn(&pdev->dev,
Signature · 1 line
2.1.3
#2 lore raw

PATCH 2/2 tty: serial: omap_serial: line is unsigned, don't check < 0

Dan Carpenter reported:

|drivers/tty/serial/8250/8250_omap.c:1025 omap8250_probe()
|warn: unsigned 'up.port.line' is never less than zero.
|1025          if (up.port.line < 0) {

Since of_alias_get_id() and pdev->id can get negative I check for the error via ret variable.

---
 drivers/tty/serial/omap-serial.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/tty/serial/omap-serial.c +5 -5
index 6cda5cd8b513..9401d2f9c119 100644
@@ -1682,16 +1682,16 @@ static int serial_omap_probe(struct platform_device *pdev)
 	up->port.ops = &serial_omap_pops;
 
 	if (pdev->dev.of_node)
-		up->port.line = of_alias_get_id(pdev->dev.of_node, "serial");
+		ret = of_alias_get_id(pdev->dev.of_node, "serial");
 	else
-		up->port.line = pdev->id;
+		ret = pdev->id;
 
-	if (up->port.line < 0) {
+	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n",
-								up->port.line);
-		ret = -ENODEV;
+			ret);
 		goto err_port_line;
 	}
+	up->port.line = ret;
 
 	ret = serial_omap_probe_rs485(up, pdev->dev.of_node);
 	if (ret < 0)
Signature · 1 line
2.1.3
#3 lore raw

Re: [PATCH 1/2] tty: serial: 8250: omap: line is unsigned, don't check < 0

In reply to Sebastian Andrzej Siewior
Quoted 11 lines · Sebastian Andrzej Siewior

Dan Carpenter reported:

|drivers/tty/serial/8250/8250_omap.c:1025 omap8250_probe()
|warn: unsigned 'up.port.line' is never less than zero.
|1025          if (up.port.line < 0) {

I (wrongly) assumed that line is an int and compiler didn't complain nor did sparse. Since of_alias_get_id() and pdev->id can get negative I check for the error via ret variable.

Greg, did those two slip through or do you wait for something until you apply them?

Sebastian

#4 lore raw

Re: [PATCH 1/2] tty: serial: 8250: omap: line is unsigned, don't check < 0

Quoted 10 lines · Sebastian Andrzej Siewior
Quoted 9 lines · Sebastian Andrzej Siewior

Dan Carpenter reported:

|drivers/tty/serial/8250/8250_omap.c:1025 omap8250_probe()
|warn: unsigned 'up.port.line' is never less than zero.
|1025          if (up.port.line < 0) {

I (wrongly) assumed that line is an int and compiler didn't complain nor did sparse. Since of_alias_get_id() and pdev->id can get negative I check for the error via ret variable.

Quoted 5 lines
Quoted 2 lines

Greg, did those two slip through or do you wait for something until you apply them?

I'm still working on catching up with my tty/serial patches, this is in the queue...