Skip to contentSkip to conversation

serial: sprd: getting port index via serial alias only

PATCH Superseded Chunyan Zhang 3 participants 10 messages Mar 18, 2020

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Chunyan Zhang

author reviewer
#0 lore raw

PATCH v2 1/2 serial: sprd: getting port index via serial alias only

From: Chunyan Zhang <[email protected]>

This patch simplifies the process of getting serial port number, with this patch, serial devices must have alias configured in devicetree.

The serial port searched out via sprd_port array maybe wrong if we don't have serial alias defined in devicetree, and specify console with command line, we would get the wrong port number if other serial ports probe failed before console's. So using alias is mandatory.

---
 drivers/tty/serial/sprd_serial.c | 36 +++++---------------------------
 1 file changed, 5 insertions(+), 31 deletions(-)
drivers/tty/serial/sprd_serial.c +5 -31
index 914862844790..9f8c14ff6454 100644
@@ -1102,29 +1102,6 @@ static struct uart_driver sprd_uart_driver = {
 	.cons = SPRD_CONSOLE,
 };
 
-static int sprd_probe_dt_alias(int index, struct device *dev)
-{
-	struct device_node *np;
-	int ret = index;
-
-	if (!IS_ENABLED(CONFIG_OF))
-		return ret;
-
-	np = dev->of_node;
-	if (!np)
-		return ret;
-
-	ret = of_alias_get_id(np, "serial");
-	if (ret < 0)
-		ret = index;
-	else if (ret >= ARRAY_SIZE(sprd_port) || sprd_port[ret] != NULL) {
-		dev_warn(dev, "requested serial port %d not available.\n", ret);
-		ret = index;
-	}
-
-	return ret;
-}
-
 static int sprd_remove(struct platform_device *dev)
 {
 	struct sprd_uart_port *sup = platform_get_drvdata(dev);
@@ -1204,14 +1181,11 @@ static int sprd_probe(struct platform_device *pdev)
 	int index;
 	int ret;
 
-	for (index = 0; index < ARRAY_SIZE(sprd_port); index++)
-		if (sprd_port[index] == NULL)
-			break;
-
-	if (index == ARRAY_SIZE(sprd_port))
-		return -EBUSY;
-
-	index = sprd_probe_dt_alias(index, &pdev->dev);
+	index = of_alias_get_id(pdev->dev.of_node, "serial");
+	if (index < 0 || index >= ARRAY_SIZE(sprd_port)) {
+		dev_err(&pdev->dev, "got a wrong serial alias id %d\n", index);
+		return index;
+	}
 
 	sprd_port[index] = devm_kzalloc(&pdev->dev, sizeof(*sprd_port[index]),
 					GFP_KERNEL);
Signature · 1 line
2.20.1
author reviewer
#1 lore raw

PATCH v2 2/2 serial: sprd: cleanup the sprd_port for error case

From: Chunyan Zhang <[email protected]>

It would be better to cleanup the sprd_port for the device before return error.

---
 drivers/tty/serial/sprd_serial.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +3 -1
index 9f8c14ff6454..54477de9822f 100644
@@ -1204,8 +1204,10 @@ static int sprd_probe(struct platform_device *pdev)
 	up->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SPRD_CONSOLE);
 
 	ret = sprd_clk_init(up);
-	if (ret)
+	if (ret) {
+		sprd_port[index] = NULL;
 		return ret;
+	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	up->membase = devm_ioremap_resource(&pdev->dev, res);
Signature · 1 line
2.20.1
maintainer
#2 lore raw

Re: [PATCH v2 2/2] serial: sprd: cleanup the sprd_port for error case

Quoted 16 lines · Chunyan Zhang

From: Chunyan Zhang <[email protected]>

It would be better to cleanup the sprd_port for the device before return error.

---
 drivers/tty/serial/sprd_serial.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +0 -0
index 9f8c14ff6454..54477de9822f 100644

drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1208

Quoted 6 lines
drivers/tty/serial/sprd_serial.c +2 -1
@@ -1204,8 +1204,10 @@ static int sprd_probe(struct platform_device *pdev)
        up->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SPRD_CONSOLE);
 
        ret = sprd_clk_init(up);
-       if (ret)
+       if (ret) {
+               sprd_port[index] = NULL;

如果我们强制使用alias, 则这里应该也无需清除了,因为一进probe就会给它重新赋值。 还是我漏了什么?

Quoted 8 lines
drivers/tty/serial/sprd_serial.c +1 -1
                return ret;
+       }
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        up->membase = devm_ioremap_resource(&pdev->dev, res);
--

2.20.1

--
Baolin Wang

author reviewer
#3 lore raw

Re: [PATCH v2 2/2] serial: sprd: cleanup the sprd_port for error case

Quoted 20 lines · Baolin Wang
Quoted 18 lines · Chunyan Zhang

From: Chunyan Zhang <[email protected]>

It would be better to cleanup the sprd_port for the device before return error.

---
 drivers/tty/serial/sprd_serial.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +0 -0
index 9f8c14ff6454..54477de9822f 100644
@@ -1204,8 +1204,10 @@ static int sprd_probe(struct platform_device *pdev)
        up->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SPRD_CONSOLE);
 
Quoted 6 lines

drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1208

Quoted 4 lines
drivers/tty/serial/sprd_serial.c +2 -1
        ret = sprd_clk_init(up);
-       if (ret)
+       if (ret) {
+               sprd_port[index] = NULL;

如果我们强制使用alias, 则这里应该也无需清除了,因为一进probe就会给它重新赋值。 还是我漏了什么?

是不需要, 所以我comment message里写的是it would be better...

我觉得是下面返回的地方都清理了, 这里也清理掉

要么都去掉?

Quoted 14 lines
Quoted 10 lines
drivers/tty/serial/sprd_serial.c +1 -1
                return ret;
+       }
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        up->membase = devm_ioremap_resource(&pdev->dev, res);
--

2.20.1

--
Baolin Wang

maintainer
#4 lore raw

Re: [PATCH v2 2/2] serial: sprd: cleanup the sprd_port for error case

Quoted 29 lines · Chunyan Zhang
Quoted 20 lines · Baolin Wang
Quoted 18 lines · Chunyan Zhang

From: Chunyan Zhang <[email protected]>

It would be better to cleanup the sprd_port for the device before return error.

---
 drivers/tty/serial/sprd_serial.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +0 -0
index 9f8c14ff6454..54477de9822f 100644
@@ -1204,8 +1204,10 @@ static int sprd_probe(struct platform_device *pdev)
        up->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SPRD_CONSOLE);
 
Quoted 6 lines

drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1208

Quoted 4 lines
drivers/tty/serial/sprd_serial.c +2 -1
        ret = sprd_clk_init(up);
-       if (ret)
+       if (ret) {
+               sprd_port[index] = NULL;

如果我们强制使用alias, 则这里应该也无需清除了,因为一进probe就会给它重新赋值。 还是我漏了什么?

Quoted 5 lines

是不需要, 所以我comment message里写的是it would be better...

我觉得是下面返回的地方都清理了, 这里也清理掉

要么都去掉?

我觉得删掉吧,代码能少一行是一行 :)

Quoted 14 lines
Quoted 14 lines
Quoted 10 lines
drivers/tty/serial/sprd_serial.c +1 -1
                return ret;
+       }
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        up->membase = devm_ioremap_resource(&pdev->dev, res);
--

2.20.1

--
Baolin Wang

Signature · 1 line
Baolin Wang
maintainer
#5 lore raw

Re: [PATCH v2 2/2] serial: sprd: cleanup the sprd_port for error case

In reply to Baolin Wang
Quoted 20 lines · Baolin Wang
Quoted 18 lines · Chunyan Zhang

From: Chunyan Zhang <[email protected]>

It would be better to cleanup the sprd_port for the device before return error.

---
 drivers/tty/serial/sprd_serial.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +0 -0
index 9f8c14ff6454..54477de9822f 100644
@@ -1204,8 +1204,10 @@ static int sprd_probe(struct platform_device *pdev)
        up->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SPRD_CONSOLE);
 
Quoted 6 lines

drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1208

Quoted 4 lines
drivers/tty/serial/sprd_serial.c +2 -1
        ret = sprd_clk_init(up);
-       if (ret)
+       if (ret) {
+               sprd_port[index] = NULL;

如果我们强制使用alias, 则这里应该也无需清除了,因为一进probe就会给它重新赋值。 还是我漏了什么?

Sorry, please ignore my previsous comment. I made a stupid mistake when talking with Chunyan.

So what I mean is we should not add this clean up, cause we will always get the correct index with aliases, and it will be overlapped when probing again.

Quoted 12 lines
Quoted 10 lines
drivers/tty/serial/sprd_serial.c +1 -1
                return ret;
+       }
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        up->membase = devm_ioremap_resource(&pdev->dev, res);
--

2.20.1

Quoted 2 lines

--
Baolin Wang

--
Baolin Wang

#6 lore raw

Re: [PATCH v2 2/2] serial: sprd: cleanup the sprd_port for error case

Quoted 28 lines · Baolin Wang
Quoted 20 lines · Baolin Wang
Quoted 18 lines · Chunyan Zhang

From: Chunyan Zhang <[email protected]>

It would be better to cleanup the sprd_port for the device before return error.

---
 drivers/tty/serial/sprd_serial.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +0 -0
index 9f8c14ff6454..54477de9822f 100644
@@ -1204,8 +1204,10 @@ static int sprd_probe(struct platform_device *pdev)
        up->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SPRD_CONSOLE);
 
Quoted 6 lines

drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1208

Quoted 4 lines
drivers/tty/serial/sprd_serial.c +2 -1
        ret = sprd_clk_init(up);
-       if (ret)
+       if (ret) {
+               sprd_port[index] = NULL;

如果我们强制使用alias, 则这里应该也无需清除了,因为一进probe就会给它重新赋值。 还是我漏了什么?

Quoted 6 lines

Sorry, please ignore my previsous comment. I made a stupid mistake when talking with Chunyan.

So what I mean is we should not add this clean up, cause we will always get the correct index with aliases, and it will be overlapped when probing again.

So ignore this patch and only take patch 1/2? If so, can I get your acked-by for it?

thanks,

greg k-h

author reviewer
#7 lore raw

Re: [PATCH v2 2/2] serial: sprd: cleanup the sprd_port for error case

Quoted 33 lines · Greg Kroah-Hartman
Quoted 31 lines · Baolin Wang
Quoted 20 lines · Baolin Wang
Quoted 18 lines · Chunyan Zhang

From: Chunyan Zhang <[email protected]>

It would be better to cleanup the sprd_port for the device before return error.

---
 drivers/tty/serial/sprd_serial.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +0 -0
index 9f8c14ff6454..54477de9822f 100644
@@ -1204,8 +1204,10 @@ static int sprd_probe(struct platform_device *pdev)
        up->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SPRD_CONSOLE);
 
Quoted 6 lines

drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1208

Quoted 4 lines
drivers/tty/serial/sprd_serial.c +2 -1
        ret = sprd_clk_init(up);
-       if (ret)
+       if (ret) {
+               sprd_port[index] = NULL;

如果我们强制使用alias, 则这里应该也无需清除了,因为一进probe就会给它重新赋值。 还是我漏了什么?

Sorry, please ignore my previsous comment. I made a stupid mistake when talking with Chunyan.

Quoted 6 lines
Quoted 3 lines

So what I mean is we should not add this clean up, cause we will always get the correct index with aliases, and it will be overlapped when probing again.

So ignore this patch and only take patch 1/2? If so, can I get your acked-by for it?

Hi Greg,

There's something I need to modify on 1/2 as well, I will send the whole patch-set later, please ignore these two patches.

Sorry for the noise!

Thanks,
Chunyan

Quoted 4 lines

thanks,

greg k-h

#8 lore raw

Re: [PATCH v2 2/2] serial: sprd: cleanup the sprd_port for error case

Quoted 42 lines · Chunyan Zhang
Quoted 33 lines · Greg Kroah-Hartman
Quoted 31 lines · Baolin Wang
Quoted 20 lines · Baolin Wang
Quoted 18 lines · Chunyan Zhang

From: Chunyan Zhang <[email protected]>

It would be better to cleanup the sprd_port for the device before return error.

---
 drivers/tty/serial/sprd_serial.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +0 -0
index 9f8c14ff6454..54477de9822f 100644
@@ -1204,8 +1204,10 @@ static int sprd_probe(struct platform_device *pdev)
        up->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SPRD_CONSOLE);
 
Quoted 6 lines

drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1208

Quoted 4 lines
drivers/tty/serial/sprd_serial.c +2 -1
        ret = sprd_clk_init(up);
-       if (ret)
+       if (ret) {
+               sprd_port[index] = NULL;

如果我们强制使用alias, 则这里应该也无需清除了,因为一进probe就会给它重新赋值。 还是我漏了什么?

Sorry, please ignore my previsous comment. I made a stupid mistake when talking with Chunyan.

Quoted 6 lines
Quoted 3 lines

So what I mean is we should not add this clean up, cause we will always get the correct index with aliases, and it will be overlapped when probing again.

So ignore this patch and only take patch 1/2? If so, can I get your acked-by for it?

Quoted 6 lines

Hi Greg,

There's something I need to modify on 1/2 as well, I will send the whole patch-set later, please ignore these two patches.

Sorry for the noise!

Discussion about patches is _never_ noise, that's what this list/group is for :)

author reviewer
#9 lore raw

Re: [PATCH v2 2/2] serial: sprd: cleanup the sprd_port for error case

Quoted 46 lines · Greg Kroah-Hartman
Quoted 44 lines · Chunyan Zhang
Quoted 33 lines · Greg Kroah-Hartman
Quoted 31 lines · Baolin Wang
Quoted 20 lines · Baolin Wang
Quoted 18 lines · Chunyan Zhang

From: Chunyan Zhang <[email protected]>

It would be better to cleanup the sprd_port for the device before return error.

---
 drivers/tty/serial/sprd_serial.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +0 -0
index 9f8c14ff6454..54477de9822f 100644
@@ -1204,8 +1204,10 @@ static int sprd_probe(struct platform_device *pdev)
        up->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SPRD_CONSOLE);
 
Quoted 6 lines

drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1208

Quoted 4 lines
drivers/tty/serial/sprd_serial.c +2 -1
        ret = sprd_clk_init(up);
-       if (ret)
+       if (ret) {
+               sprd_port[index] = NULL;

如果我们强制使用alias, 则这里应该也无需清除了,因为一进probe就会给它重新赋值。 还是我漏了什么?

Sorry, please ignore my previsous comment. I made a stupid mistake when talking with Chunyan.

Quoted 6 lines
Quoted 3 lines

So what I mean is we should not add this clean up, cause we will always get the correct index with aliases, and it will be overlapped when probing again.

So ignore this patch and only take patch 1/2? If so, can I get your acked-by for it?

Hi Greg,

Quoted 7 lines
Quoted 4 lines

There's something I need to modify on 1/2 as well, I will send the whole patch-set later, please ignore these two patches.

Sorry for the noise!

Discussion about patches is _never_ noise, that's what this list/group is for :)

Ok, thanks for your nice words, at least brought you some trouble, that's what I mean :)

I've sent out a new version of patches just now.

Thanks again,
Chunyan