Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: sprd: getting port index via serial aliases only

This patch simplifies the process of getting serial port number, with
this patch, serial devices must have aliases 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 aliases is mandatory.

Reviewed-by: Baolin Wang <baolin.wang7@gmail.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
Link: https://lore.kernel.org/r/20200318105049.19623-2-zhang.lyra@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Chunyan Zhang and committed by
Greg Kroah-Hartman
4b7349cb 630db5cb

+5 -31
+5 -31
drivers/tty/serial/sprd_serial.c
··· 1102 1102 .cons = SPRD_CONSOLE, 1103 1103 }; 1104 1104 1105 - static int sprd_probe_dt_alias(int index, struct device *dev) 1106 - { 1107 - struct device_node *np; 1108 - int ret = index; 1109 - 1110 - if (!IS_ENABLED(CONFIG_OF)) 1111 - return ret; 1112 - 1113 - np = dev->of_node; 1114 - if (!np) 1115 - return ret; 1116 - 1117 - ret = of_alias_get_id(np, "serial"); 1118 - if (ret < 0) 1119 - ret = index; 1120 - else if (ret >= ARRAY_SIZE(sprd_port) || sprd_port[ret] != NULL) { 1121 - dev_warn(dev, "requested serial port %d not available.\n", ret); 1122 - ret = index; 1123 - } 1124 - 1125 - return ret; 1126 - } 1127 - 1128 1105 static int sprd_remove(struct platform_device *dev) 1129 1106 { 1130 1107 struct sprd_uart_port *sup = platform_get_drvdata(dev); ··· 1180 1203 int index; 1181 1204 int ret; 1182 1205 1183 - for (index = 0; index < ARRAY_SIZE(sprd_port); index++) 1184 - if (sprd_port[index] == NULL) 1185 - break; 1186 - 1187 - if (index == ARRAY_SIZE(sprd_port)) 1188 - return -EBUSY; 1189 - 1190 - index = sprd_probe_dt_alias(index, &pdev->dev); 1206 + index = of_alias_get_id(pdev->dev.of_node, "serial"); 1207 + if (index < 0 || index >= ARRAY_SIZE(sprd_port)) { 1208 + dev_err(&pdev->dev, "got a wrong serial alias id %d\n", index); 1209 + return -EINVAL; 1210 + } 1191 1211 1192 1212 sprd_port[index] = devm_kzalloc(&pdev->dev, sizeof(*sprd_port[index]), 1193 1213 GFP_KERNEL);