Skip to contentSkip to conversation

serial: cpm_uart: use irq variable for platform_get_irq()

PATCH In review Rosen Penev 3 participants 6 messages Sep 25 – Oct 3 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: cpm_uart: use irq variable for platform_get_irq()

struct uart_port has its irq member as an unsigned int, which does not work when platform_get_irq() returns an error.

Use a local irq variable to handle this and write to struct uart_port's irq member when platform_get_irq() succeeds. On success, it returns an IRQ >= 0, which is representable by unsigned int.

Fixes 831603b3e8aa ("serial: cpm_uart: replace irq_of_parse_and_map with platform_get_irq")
---
 drivers/tty/serial/cpm_uart.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/tty/serial/cpm_uart.c +6 -4
index 39f54bb7b485..ca0acccd3dd8 100644
@@ -1517,6 +1517,7 @@ static int cpm_uart_probe(struct platform_device *ofdev)
 {
 	int index = probe_index++;
 	struct uart_cpm_port *pinfo = &cpm_uart_ports[index];
+	int irq;
 	int ret;
 
 	pinfo->port.line = index;
@@ -1524,14 +1525,15 @@ static int cpm_uart_probe(struct platform_device *ofdev)
 	if (index >= UART_NR)
 		return -ENODEV;
 
+	irq = platform_get_irq(ofdev, 0);
+	if (irq < 0)
+		return irq;
+
 	platform_set_drvdata(ofdev, pinfo);
 
 	/* initialize the device pointer for the port */
 	pinfo->port.dev = &ofdev->dev;
-
-	pinfo->port.irq = platform_get_irq(ofdev, 0);
-	if (pinfo->port.irq < 0)
-		return pinfo->port.irq;
+	pinfo->port.irq = irq;
 
 	ret = cpm_uart_init_port(ofdev->dev.of_node, pinfo);
 	if (!ret)
Signature · 1 line
2.55.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

struct uart_port has its irq member as an unsigned int, which does not work when platform_get_irq() returns an error.

Use a local irq variable to handle this and write to struct uart_port's irq member when platform_get_irq() succeeds. On success, it returns an IRQ >= 0, which is representable by unsigned int.

Fixes 831603b3e8aa ("serial: cpm_uart: replace irq_of_parse_and_map with platform_get_irq")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Rosen Penev
Quoted 34 lines · Rosen Penev

struct uart_port has its irq member as an unsigned int, which does not work when platform_get_irq() returns an error.

Use a local irq variable to handle this and write to struct uart_port's irq member when platform_get_irq() succeeds. On success, it returns an IRQ >= 0, which is representable by unsigned int.

Fixes 831603b3e8aa ("serial: cpm_uart: replace irq_of_parse_and_map with platform_get_irq")
---
 drivers/tty/serial/cpm_uart.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/tty/serial/cpm_uart.c +4 -0
index 39f54bb7b485..ca0acccd3dd8 100644
@@ -1517,6 +1517,7 @@ static int cpm_uart_probe(struct platform_device *ofdev)
 {
 	int index = probe_index++;
 	struct uart_cpm_port *pinfo = &cpm_uart_ports[index];
+	int irq;
 	int ret;
 
 	pinfo->port.line = index;
@@ -1524,14 +1525,15 @@ static int cpm_uart_probe(struct platform_device *ofdev)
 	if (index >= UART_NR)
 		return -ENODEV;
 
+	irq = platform_get_irq(ofdev, 0);
+	if (irq < 0)
+		return irq;

drivers/tty/serial/cpm_uart.c static int cpm_uart_probe(struct platform_device *ofdev) · line 1536

Quoted 10 lines
drivers/tty/serial/cpm_uart.c +2 -4
+
 	platform_set_drvdata(ofdev, pinfo);
 
 	/* initialize the device pointer for the port */
 	pinfo->port.dev = &ofdev->dev;
-
-	pinfo->port.irq = platform_get_irq(ofdev, 0);
-	if (pinfo->port.irq < 0)
-		return pinfo->port.irq;
+	pinfo->port.irq = irq;

Why did you move where platform_get_irq() is called?

thanks,

greg k-h

#3 lore raw
Quoted 38 lines · Greg Kroah-Hartman
Quoted 37 lines · Rosen Penev

struct uart_port has its irq member as an unsigned int, which does not work when platform_get_irq() returns an error.

Use a local irq variable to handle this and write to struct uart_port's irq member when platform_get_irq() succeeds. On success, it returns an IRQ >= 0, which is representable by unsigned int.

Fixes 831603b3e8aa ("serial: cpm_uart: replace irq_of_parse_and_map with platform_get_irq")
---
 drivers/tty/serial/cpm_uart.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/tty/serial/cpm_uart.c +5 -0
index 39f54bb7b485..ca0acccd3dd8 100644
@@ -1517,6 +1517,7 @@ static int cpm_uart_probe(struct platform_device *ofdev)
 {
 	int index = probe_index++;
 	struct uart_cpm_port *pinfo = &cpm_uart_ports[index];
+	int irq;
 	int ret;
 
 	pinfo->port.line = index;
@@ -1524,14 +1525,15 @@ static int cpm_uart_probe(struct platform_device *ofdev)
 	if (index >= UART_NR)
 		return -ENODEV;
 
+	irq = platform_get_irq(ofdev, 0);
+	if (irq < 0)
+		return irq;
+
 	platform_set_drvdata(ofdev, pinfo);
 
Quoted 9 lines

drivers/tty/serial/cpm_uart.c static int cpm_uart_probe(struct platform_device *ofdev) · line 1536

Quoted 7 lines
drivers/tty/serial/cpm_uart.c +1 -4
 	/* initialize the device pointer for the port */
 	pinfo->port.dev = &ofdev->dev;
-
-	pinfo->port.irq = platform_get_irq(ofdev, 0);
-	if (pinfo->port.irq < 0)
-		return pinfo->port.irq;
+	pinfo->port.irq = irq;

Why did you move where platform_get_irq() is called?

So that platform_set_drvdata does not get called on failure.

Quoted 4 lines

thanks,

greg k-h

#4 lore raw
Quoted 49 lines · Rosen Penev
Quoted 38 lines · Greg Kroah-Hartman
Quoted 37 lines · Rosen Penev

struct uart_port has its irq member as an unsigned int, which does not work when platform_get_irq() returns an error.

Use a local irq variable to handle this and write to struct uart_port's irq member when platform_get_irq() succeeds. On success, it returns an IRQ >= 0, which is representable by unsigned int.

Fixes 831603b3e8aa ("serial: cpm_uart: replace irq_of_parse_and_map with platform_get_irq")
---
 drivers/tty/serial/cpm_uart.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/tty/serial/cpm_uart.c +5 -0
index 39f54bb7b485..ca0acccd3dd8 100644
@@ -1517,6 +1517,7 @@ static int cpm_uart_probe(struct platform_device *ofdev)
 {
 	int index = probe_index++;
 	struct uart_cpm_port *pinfo = &cpm_uart_ports[index];
+	int irq;
 	int ret;
 
 	pinfo->port.line = index;
@@ -1524,14 +1525,15 @@ static int cpm_uart_probe(struct platform_device *ofdev)
 	if (index >= UART_NR)
 		return -ENODEV;
 
+	irq = platform_get_irq(ofdev, 0);
+	if (irq < 0)
+		return irq;
+
 	platform_set_drvdata(ofdev, pinfo);
 
Quoted 9 lines

drivers/tty/serial/cpm_uart.c static int cpm_uart_probe(struct platform_device *ofdev) · line 1536

Quoted 7 lines
drivers/tty/serial/cpm_uart.c +1 -4
 	/* initialize the device pointer for the port */
 	pinfo->port.dev = &ofdev->dev;
-
-	pinfo->port.irq = platform_get_irq(ofdev, 0);
-	if (pinfo->port.irq < 0)
-		return pinfo->port.irq;
+	pinfo->port.irq = irq;

Why did you move where platform_get_irq() is called?

Quoted 1 line

So that platform_set_drvdata does not get called on failure.

Why does that matter?

#5 lore raw
Quoted 51 lines · Greg Kroah-Hartman
Quoted 49 lines · Rosen Penev
Quoted 47 lines · Greg Kroah-Hartman
Quoted 34 lines · Rosen Penev

struct uart_port has its irq member as an unsigned int, which does not work when platform_get_irq() returns an error.

Use a local irq variable to handle this and write to struct uart_port's irq member when platform_get_irq() succeeds. On success, it returns an IRQ >= 0, which is representable by unsigned int.

Fixes 831603b3e8aa ("serial: cpm_uart: replace irq_of_parse_and_map with platform_get_irq")
---
 drivers/tty/serial/cpm_uart.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/tty/serial/cpm_uart.c +4 -0
index 39f54bb7b485..ca0acccd3dd8 100644
@@ -1517,6 +1517,7 @@ static int cpm_uart_probe(struct platform_device *ofdev)
 {
   int index = probe_index++;
   struct uart_cpm_port *pinfo = &cpm_uart_ports[index];
+  int irq;
   int ret;
 
   pinfo->port.line = index;
@@ -1524,14 +1525,15 @@ static int cpm_uart_probe(struct platform_device *ofdev)
   if (index >= UART_NR)
           return -ENODEV;
 
+  irq = platform_get_irq(ofdev, 0);
+  if (irq < 0)
+          return irq;

drivers/tty/serial/cpm_uart.c static int cpm_uart_probe(struct platform_device *ofdev) · line 1536

Quoted 10 lines
drivers/tty/serial/cpm_uart.c +2 -4
+
   platform_set_drvdata(ofdev, pinfo);
 
   /* initialize the device pointer for the port */
   pinfo->port.dev = &ofdev->dev;
-
-  pinfo->port.irq = platform_get_irq(ofdev, 0);
-  if (pinfo->port.irq < 0)
-          return pinfo->port.irq;
+  pinfo->port.irq = irq;

Why did you move where platform_get_irq() is called?

Quoted 3 lines
Quoted 1 line

So that platform_set_drvdata does not get called on failure.

Why does that matter?

To avoid doing unnecessary work.