hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/tty/serial/sprd_serial.c
....@@ -367,7 +367,7 @@
367367 if (sp->rx_dma.virt)
368368 dma_free_coherent(sp->port.dev, SPRD_UART_RX_SIZE,
369369 sp->rx_dma.virt, sp->rx_dma.phys_addr);
370
-
370
+ sp->rx_dma.virt = NULL;
371371 }
372372
373373 static int sprd_rx_dma_config(struct uart_port *port, u32 burst)
....@@ -1133,7 +1133,7 @@
11331133 static int sprd_clk_init(struct uart_port *uport)
11341134 {
11351135 struct clk *clk_uart, *clk_parent;
1136
- struct sprd_uart_port *u = sprd_port[uport->line];
1136
+ struct sprd_uart_port *u = container_of(uport, struct sprd_uart_port, port);
11371137
11381138 clk_uart = devm_clk_get(uport->dev, "uart");
11391139 if (IS_ERR(clk_uart)) {
....@@ -1176,22 +1176,22 @@
11761176 {
11771177 struct resource *res;
11781178 struct uart_port *up;
1179
+ struct sprd_uart_port *sport;
11791180 int irq;
11801181 int index;
11811182 int ret;
11821183
11831184 index = of_alias_get_id(pdev->dev.of_node, "serial");
1184
- if (index < 0 || index >= ARRAY_SIZE(sprd_port)) {
1185
+ if (index < 0 || index >= UART_NR_MAX) {
11851186 dev_err(&pdev->dev, "got a wrong serial alias id %d\n", index);
11861187 return -EINVAL;
11871188 }
11881189
1189
- sprd_port[index] = devm_kzalloc(&pdev->dev, sizeof(*sprd_port[index]),
1190
- GFP_KERNEL);
1191
- if (!sprd_port[index])
1190
+ sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL);
1191
+ if (!sport)
11921192 return -ENOMEM;
11931193
1194
- up = &sprd_port[index]->port;
1194
+ up = &sport->port;
11951195 up->dev = &pdev->dev;
11961196 up->line = index;
11971197 up->type = PORT_SPRD;
....@@ -1222,7 +1222,7 @@
12221222 * Allocate one dma buffer to prepare for receive transfer, in case
12231223 * memory allocation failure at runtime.
12241224 */
1225
- ret = sprd_rx_alloc_buf(sprd_port[index]);
1225
+ ret = sprd_rx_alloc_buf(sport);
12261226 if (ret)
12271227 return ret;
12281228
....@@ -1230,17 +1230,27 @@
12301230 ret = uart_register_driver(&sprd_uart_driver);
12311231 if (ret < 0) {
12321232 pr_err("Failed to register SPRD-UART driver\n");
1233
- return ret;
1233
+ goto free_rx_buf;
12341234 }
12351235 }
1236
+
12361237 sprd_ports_num++;
1238
+ sprd_port[index] = sport;
12371239
12381240 ret = uart_add_one_port(&sprd_uart_driver, up);
12391241 if (ret)
1240
- sprd_remove(pdev);
1242
+ goto clean_port;
12411243
12421244 platform_set_drvdata(pdev, up);
12431245
1246
+ return 0;
1247
+
1248
+clean_port:
1249
+ sprd_port[index] = NULL;
1250
+ if (--sprd_ports_num == 0)
1251
+ uart_unregister_driver(&sprd_uart_driver);
1252
+free_rx_buf:
1253
+ sprd_rx_free_buf(sport);
12441254 return ret;
12451255 }
12461256