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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'tty-5.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty

Pull tty/serial fixes from Greg KH:
"Here are some tty and serial driver fixes for 5.7-rc3.

The "largest" in here are a number of reverts for previous changes to
the uartps serial driver that turned out to not be a good idea at all.

The others are just small fixes found by people and tools. Included in
here is a much-reported symbol export needed by previous changes that
happened in 5.7-rc1. All of these have been in linux-next for a while
with no reported issues"

* tag 'tty-5.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty:
tty: hvc: fix buffer overflow during hvc_alloc().
tty: rocket, avoid OOB access
tty: serial: bcm63xx: fix missing clk_put() in bcm63xx_uart
vt: don't hardcode the mem allocation upper bound
tty: serial: owl: add "much needed" clk_prepare_enable()
vt: don't use kmalloc() for the unicode screen buffer
tty/sysrq: Export sysrq_mask(), sysrq_toggle_support()
serial: sh-sci: Make sure status register SCxSR is read in correct sequence
serial: sunhv: Initialize lock for non-registered console
Revert "serial: uartps: Register own uart console and driver structures"
Revert "serial: uartps: Move Port ID to device data structure"
Revert "serial: uartps: Change uart ID port allocation"
Revert "serial: uartps: Do not allow use aliases >= MAX_UART_INSTANCES"
Revert "serial: uartps: Fix error path when alloc failed"
Revert "serial: uartps: Use the same dynamic major number for all ports"
Revert "serial: uartps: Fix uartps_major handling"

+105 -188
+14 -9
drivers/tty/hvc/hvc_console.c
··· 302 302 vtermnos[index] = vtermno; 303 303 cons_ops[index] = ops; 304 304 305 - /* reserve all indices up to and including this index */ 306 - if (last_hvc < index) 307 - last_hvc = index; 308 - 309 305 /* check if we need to re-register the kernel console */ 310 306 hvc_check_console(index); 311 307 ··· 956 960 cons_ops[i] == hp->ops) 957 961 break; 958 962 959 - /* no matching slot, just use a counter */ 960 - if (i >= MAX_NR_HVC_CONSOLES) 961 - i = ++last_hvc; 963 + if (i >= MAX_NR_HVC_CONSOLES) { 964 + 965 + /* find 'empty' slot for console */ 966 + for (i = 0; i < MAX_NR_HVC_CONSOLES && vtermnos[i] != -1; i++) { 967 + } 968 + 969 + /* no matching slot, just use a counter */ 970 + if (i == MAX_NR_HVC_CONSOLES) 971 + i = ++last_hvc + MAX_NR_HVC_CONSOLES; 972 + } 962 973 963 974 hp->index = i; 964 - cons_ops[i] = ops; 965 - vtermnos[i] = vtermno; 975 + if (i < MAX_NR_HVC_CONSOLES) { 976 + cons_ops[i] = ops; 977 + vtermnos[i] = vtermno; 978 + } 966 979 967 980 list_add_tail(&(hp->next), &hvc_structs); 968 981 mutex_unlock(&hvc_structs_mutex);
+14 -11
drivers/tty/rocket.c
··· 632 632 tty_port_init(&info->port); 633 633 info->port.ops = &rocket_port_ops; 634 634 info->flags &= ~ROCKET_MODE_MASK; 635 - switch (pc104[board][line]) { 636 - case 422: 637 - info->flags |= ROCKET_MODE_RS422; 638 - break; 639 - case 485: 640 - info->flags |= ROCKET_MODE_RS485; 641 - break; 642 - case 232: 643 - default: 635 + if (board < ARRAY_SIZE(pc104) && line < ARRAY_SIZE(pc104_1)) 636 + switch (pc104[board][line]) { 637 + case 422: 638 + info->flags |= ROCKET_MODE_RS422; 639 + break; 640 + case 485: 641 + info->flags |= ROCKET_MODE_RS485; 642 + break; 643 + case 232: 644 + default: 645 + info->flags |= ROCKET_MODE_RS232; 646 + break; 647 + } 648 + else 644 649 info->flags |= ROCKET_MODE_RS232; 645 - break; 646 - } 647 650 648 651 info->intmask = RXF_TRIG | TXFIFO_MT | SRC_INT | DELTA_CD | DELTA_CTS | DELTA_DSR; 649 652 if (sInitChan(ctlp, &info->channel, aiop, chan) == 0) {
+3 -1
drivers/tty/serial/bcm63xx_uart.c
··· 843 843 if (IS_ERR(clk) && pdev->dev.of_node) 844 844 clk = of_clk_get(pdev->dev.of_node, 0); 845 845 846 - if (IS_ERR(clk)) 846 + if (IS_ERR(clk)) { 847 + clk_put(clk); 847 848 return -ENODEV; 849 + } 848 850 849 851 port->iotype = UPIO_MEM; 850 852 port->irq = res_irq->start;
+7
drivers/tty/serial/owl-uart.c
··· 680 680 return PTR_ERR(owl_port->clk); 681 681 } 682 682 683 + ret = clk_prepare_enable(owl_port->clk); 684 + if (ret) { 685 + dev_err(&pdev->dev, "could not enable clk\n"); 686 + return ret; 687 + } 688 + 683 689 owl_port->port.dev = &pdev->dev; 684 690 owl_port->port.line = pdev->id; 685 691 owl_port->port.type = PORT_OWL; ··· 718 712 719 713 uart_remove_one_port(&owl_uart_driver, &owl_port->port); 720 714 owl_uart_ports[pdev->id] = NULL; 715 + clk_disable_unprepare(owl_port->clk); 721 716 722 717 return 0; 723 718 }
+9 -2
drivers/tty/serial/sh-sci.c
··· 870 870 tty_insert_flip_char(tport, c, TTY_NORMAL); 871 871 } else { 872 872 for (i = 0; i < count; i++) { 873 - char c = serial_port_in(port, SCxRDR); 873 + char c; 874 874 875 - status = serial_port_in(port, SCxSR); 875 + if (port->type == PORT_SCIF || 876 + port->type == PORT_HSCIF) { 877 + status = serial_port_in(port, SCxSR); 878 + c = serial_port_in(port, SCxRDR); 879 + } else { 880 + c = serial_port_in(port, SCxRDR); 881 + status = serial_port_in(port, SCxSR); 882 + } 876 883 if (uart_handle_sysrq_char(port, c)) { 877 884 count--; i--; 878 885 continue;
+3
drivers/tty/serial/sunhv.c
··· 567 567 sunserial_console_match(&sunhv_console, op->dev.of_node, 568 568 &sunhv_reg, port->line, false); 569 569 570 + /* We need to initialize lock even for non-registered console */ 571 + spin_lock_init(&port->lock); 572 + 570 573 err = uart_add_one_port(&sunhv_reg, port); 571 574 if (err) 572 575 goto out_unregister_driver;
+49 -162
drivers/tty/serial/xilinx_uartps.c
··· 26 26 27 27 #define CDNS_UART_TTY_NAME "ttyPS" 28 28 #define CDNS_UART_NAME "xuartps" 29 + #define CDNS_UART_MAJOR 0 /* use dynamic node allocation */ 30 + #define CDNS_UART_MINOR 0 /* works best with devtmpfs */ 31 + #define CDNS_UART_NR_PORTS 16 29 32 #define CDNS_UART_FIFO_SIZE 64 /* FIFO size */ 30 33 #define CDNS_UART_REGISTER_SPACE 0x1000 31 34 #define TX_TIMEOUT 500000 32 35 33 36 /* Rx Trigger level */ 34 37 static int rx_trigger_level = 56; 35 - static int uartps_major; 36 38 module_param(rx_trigger_level, uint, 0444); 37 39 MODULE_PARM_DESC(rx_trigger_level, "Rx trigger level, 1-63 bytes"); 38 40 ··· 190 188 * @pclk: APB clock 191 189 * @cdns_uart_driver: Pointer to UART driver 192 190 * @baud: Current baud rate 193 - * @id: Port ID 194 191 * @clk_rate_change_nb: Notifier block for clock changes 195 192 * @quirks: Flags for RXBS support. 196 193 */ ··· 199 198 struct clk *pclk; 200 199 struct uart_driver *cdns_uart_driver; 201 200 unsigned int baud; 202 - int id; 203 201 struct notifier_block clk_rate_change_nb; 204 202 u32 quirks; 205 203 bool cts_override; ··· 1133 1133 #endif 1134 1134 }; 1135 1135 1136 + static struct uart_driver cdns_uart_uart_driver; 1137 + 1136 1138 #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE 1137 1139 /** 1138 1140 * cdns_uart_console_putchar - write the character to the FIFO buffer ··· 1274 1272 1275 1273 return uart_set_options(port, co, baud, parity, bits, flow); 1276 1274 } 1275 + 1276 + static struct console cdns_uart_console = { 1277 + .name = CDNS_UART_TTY_NAME, 1278 + .write = cdns_uart_console_write, 1279 + .device = uart_console_device, 1280 + .setup = cdns_uart_console_setup, 1281 + .flags = CON_PRINTBUFFER, 1282 + .index = -1, /* Specified on the cmdline (e.g. console=ttyPS ) */ 1283 + .data = &cdns_uart_uart_driver, 1284 + }; 1277 1285 #endif /* CONFIG_SERIAL_XILINX_PS_UART_CONSOLE */ 1278 1286 1279 1287 #ifdef CONFIG_PM_SLEEP ··· 1415 1403 }; 1416 1404 MODULE_DEVICE_TABLE(of, cdns_uart_of_match); 1417 1405 1418 - /* 1419 - * Maximum number of instances without alias IDs but if there is alias 1420 - * which target "< MAX_UART_INSTANCES" range this ID can't be used. 1421 - */ 1422 - #define MAX_UART_INSTANCES 32 1423 - 1424 - /* Stores static aliases list */ 1425 - static DECLARE_BITMAP(alias_bitmap, MAX_UART_INSTANCES); 1426 - static int alias_bitmap_initialized; 1427 - 1428 - /* Stores actual bitmap of allocated IDs with alias IDs together */ 1429 - static DECLARE_BITMAP(bitmap, MAX_UART_INSTANCES); 1430 - /* Protect bitmap operations to have unique IDs */ 1431 - static DEFINE_MUTEX(bitmap_lock); 1432 - 1433 - static int cdns_get_id(struct platform_device *pdev) 1434 - { 1435 - int id, ret; 1436 - 1437 - mutex_lock(&bitmap_lock); 1438 - 1439 - /* Alias list is stable that's why get alias bitmap only once */ 1440 - if (!alias_bitmap_initialized) { 1441 - ret = of_alias_get_alias_list(cdns_uart_of_match, "serial", 1442 - alias_bitmap, MAX_UART_INSTANCES); 1443 - if (ret && ret != -EOVERFLOW) { 1444 - mutex_unlock(&bitmap_lock); 1445 - return ret; 1446 - } 1447 - 1448 - alias_bitmap_initialized++; 1449 - } 1450 - 1451 - /* Make sure that alias ID is not taken by instance without alias */ 1452 - bitmap_or(bitmap, bitmap, alias_bitmap, MAX_UART_INSTANCES); 1453 - 1454 - dev_dbg(&pdev->dev, "Alias bitmap: %*pb\n", 1455 - MAX_UART_INSTANCES, bitmap); 1456 - 1457 - /* Look for a serialN alias */ 1458 - id = of_alias_get_id(pdev->dev.of_node, "serial"); 1459 - if (id < 0) { 1460 - dev_warn(&pdev->dev, 1461 - "No serial alias passed. Using the first free id\n"); 1462 - 1463 - /* 1464 - * Start with id 0 and check if there is no serial0 alias 1465 - * which points to device which is compatible with this driver. 1466 - * If alias exists then try next free position. 1467 - */ 1468 - id = 0; 1469 - 1470 - for (;;) { 1471 - dev_info(&pdev->dev, "Checking id %d\n", id); 1472 - id = find_next_zero_bit(bitmap, MAX_UART_INSTANCES, id); 1473 - 1474 - /* No free empty instance */ 1475 - if (id == MAX_UART_INSTANCES) { 1476 - dev_err(&pdev->dev, "No free ID\n"); 1477 - mutex_unlock(&bitmap_lock); 1478 - return -EINVAL; 1479 - } 1480 - 1481 - dev_dbg(&pdev->dev, "The empty id is %d\n", id); 1482 - /* Check if ID is empty */ 1483 - if (!test_and_set_bit(id, bitmap)) { 1484 - /* Break the loop if bit is taken */ 1485 - dev_dbg(&pdev->dev, 1486 - "Selected ID %d allocation passed\n", 1487 - id); 1488 - break; 1489 - } 1490 - dev_dbg(&pdev->dev, 1491 - "Selected ID %d allocation failed\n", id); 1492 - /* if taking bit fails then try next one */ 1493 - id++; 1494 - } 1495 - } 1496 - 1497 - mutex_unlock(&bitmap_lock); 1498 - 1499 - return id; 1500 - } 1406 + /* Temporary variable for storing number of instances */ 1407 + static int instances; 1501 1408 1502 1409 /** 1503 1410 * cdns_uart_probe - Platform driver probe ··· 1426 1495 */ 1427 1496 static int cdns_uart_probe(struct platform_device *pdev) 1428 1497 { 1429 - int rc, irq; 1498 + int rc, id, irq; 1430 1499 struct uart_port *port; 1431 1500 struct resource *res; 1432 1501 struct cdns_uart *cdns_uart_data; 1433 1502 const struct of_device_id *match; 1434 - struct uart_driver *cdns_uart_uart_driver; 1435 - char *driver_name; 1436 - #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE 1437 - struct console *cdns_uart_console; 1438 - #endif 1439 1503 1440 1504 cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data), 1441 1505 GFP_KERNEL); ··· 1440 1514 if (!port) 1441 1515 return -ENOMEM; 1442 1516 1443 - cdns_uart_uart_driver = devm_kzalloc(&pdev->dev, 1444 - sizeof(*cdns_uart_uart_driver), 1445 - GFP_KERNEL); 1446 - if (!cdns_uart_uart_driver) 1447 - return -ENOMEM; 1517 + /* Look for a serialN alias */ 1518 + id = of_alias_get_id(pdev->dev.of_node, "serial"); 1519 + if (id < 0) 1520 + id = 0; 1448 1521 1449 - cdns_uart_data->id = cdns_get_id(pdev); 1450 - if (cdns_uart_data->id < 0) 1451 - return cdns_uart_data->id; 1452 - 1453 - /* There is a need to use unique driver name */ 1454 - driver_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s%d", 1455 - CDNS_UART_NAME, cdns_uart_data->id); 1456 - if (!driver_name) { 1457 - rc = -ENOMEM; 1458 - goto err_out_id; 1522 + if (id >= CDNS_UART_NR_PORTS) { 1523 + dev_err(&pdev->dev, "Cannot get uart_port structure\n"); 1524 + return -ENODEV; 1459 1525 } 1460 1526 1461 - cdns_uart_uart_driver->owner = THIS_MODULE; 1462 - cdns_uart_uart_driver->driver_name = driver_name; 1463 - cdns_uart_uart_driver->dev_name = CDNS_UART_TTY_NAME; 1464 - cdns_uart_uart_driver->major = uartps_major; 1465 - cdns_uart_uart_driver->minor = cdns_uart_data->id; 1466 - cdns_uart_uart_driver->nr = 1; 1467 - 1527 + if (!cdns_uart_uart_driver.state) { 1528 + cdns_uart_uart_driver.owner = THIS_MODULE; 1529 + cdns_uart_uart_driver.driver_name = CDNS_UART_NAME; 1530 + cdns_uart_uart_driver.dev_name = CDNS_UART_TTY_NAME; 1531 + cdns_uart_uart_driver.major = CDNS_UART_MAJOR; 1532 + cdns_uart_uart_driver.minor = CDNS_UART_MINOR; 1533 + cdns_uart_uart_driver.nr = CDNS_UART_NR_PORTS; 1468 1534 #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE 1469 - cdns_uart_console = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_console), 1470 - GFP_KERNEL); 1471 - if (!cdns_uart_console) { 1472 - rc = -ENOMEM; 1473 - goto err_out_id; 1474 - } 1475 - 1476 - strncpy(cdns_uart_console->name, CDNS_UART_TTY_NAME, 1477 - sizeof(cdns_uart_console->name)); 1478 - cdns_uart_console->index = cdns_uart_data->id; 1479 - cdns_uart_console->write = cdns_uart_console_write; 1480 - cdns_uart_console->device = uart_console_device; 1481 - cdns_uart_console->setup = cdns_uart_console_setup; 1482 - cdns_uart_console->flags = CON_PRINTBUFFER; 1483 - cdns_uart_console->data = cdns_uart_uart_driver; 1484 - cdns_uart_uart_driver->cons = cdns_uart_console; 1535 + cdns_uart_uart_driver.cons = &cdns_uart_console; 1485 1536 #endif 1486 1537 1487 - rc = uart_register_driver(cdns_uart_uart_driver); 1488 - if (rc < 0) { 1489 - dev_err(&pdev->dev, "Failed to register driver\n"); 1490 - goto err_out_id; 1538 + rc = uart_register_driver(&cdns_uart_uart_driver); 1539 + if (rc < 0) { 1540 + dev_err(&pdev->dev, "Failed to register driver\n"); 1541 + return rc; 1542 + } 1491 1543 } 1492 1544 1493 - cdns_uart_data->cdns_uart_driver = cdns_uart_uart_driver; 1494 - 1495 - /* 1496 - * Setting up proper name_base needs to be done after uart 1497 - * registration because tty_driver structure is not filled. 1498 - * name_base is 0 by default. 1499 - */ 1500 - cdns_uart_uart_driver->tty_driver->name_base = cdns_uart_data->id; 1545 + cdns_uart_data->cdns_uart_driver = &cdns_uart_uart_driver; 1501 1546 1502 1547 match = of_match_node(cdns_uart_of_match, pdev->dev.of_node); 1503 1548 if (match && match->data) { ··· 1546 1649 port->ops = &cdns_uart_ops; 1547 1650 port->fifosize = CDNS_UART_FIFO_SIZE; 1548 1651 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_XILINX_PS_UART_CONSOLE); 1652 + port->line = id; 1549 1653 1550 1654 /* 1551 1655 * Register the port. ··· 1578 1680 console_port = port; 1579 1681 #endif 1580 1682 1581 - rc = uart_add_one_port(cdns_uart_uart_driver, port); 1683 + rc = uart_add_one_port(&cdns_uart_uart_driver, port); 1582 1684 if (rc) { 1583 1685 dev_err(&pdev->dev, 1584 1686 "uart_add_one_port() failed; err=%i\n", rc); ··· 1588 1690 #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE 1589 1691 /* This is not port which is used for console that's why clean it up */ 1590 1692 if (console_port == port && 1591 - !(cdns_uart_uart_driver->cons->flags & CON_ENABLED)) 1693 + !(cdns_uart_uart_driver.cons->flags & CON_ENABLED)) 1592 1694 console_port = NULL; 1593 1695 #endif 1594 1696 1595 - uartps_major = cdns_uart_uart_driver->tty_driver->major; 1596 1697 cdns_uart_data->cts_override = of_property_read_bool(pdev->dev.of_node, 1597 1698 "cts-override"); 1699 + 1700 + instances++; 1701 + 1598 1702 return 0; 1599 1703 1600 1704 err_out_pm_disable: ··· 1612 1712 err_out_clk_dis_pclk: 1613 1713 clk_disable_unprepare(cdns_uart_data->pclk); 1614 1714 err_out_unregister_driver: 1615 - uart_unregister_driver(cdns_uart_data->cdns_uart_driver); 1616 - err_out_id: 1617 - mutex_lock(&bitmap_lock); 1618 - if (cdns_uart_data->id < MAX_UART_INSTANCES) 1619 - clear_bit(cdns_uart_data->id, bitmap); 1620 - mutex_unlock(&bitmap_lock); 1715 + if (!instances) 1716 + uart_unregister_driver(cdns_uart_data->cdns_uart_driver); 1621 1717 return rc; 1622 1718 } 1623 1719 ··· 1636 1740 #endif 1637 1741 rc = uart_remove_one_port(cdns_uart_data->cdns_uart_driver, port); 1638 1742 port->mapbase = 0; 1639 - mutex_lock(&bitmap_lock); 1640 - if (cdns_uart_data->id < MAX_UART_INSTANCES) 1641 - clear_bit(cdns_uart_data->id, bitmap); 1642 - mutex_unlock(&bitmap_lock); 1643 1743 clk_disable_unprepare(cdns_uart_data->uartclk); 1644 1744 clk_disable_unprepare(cdns_uart_data->pclk); 1645 1745 pm_runtime_disable(&pdev->dev); ··· 1648 1756 console_port = NULL; 1649 1757 #endif 1650 1758 1651 - /* If this is last instance major number should be initialized */ 1652 - mutex_lock(&bitmap_lock); 1653 - if (bitmap_empty(bitmap, MAX_UART_INSTANCES)) 1654 - uartps_major = 0; 1655 - mutex_unlock(&bitmap_lock); 1656 - 1657 - uart_unregister_driver(cdns_uart_data->cdns_uart_driver); 1759 + if (!--instances) 1760 + uart_unregister_driver(cdns_uart_data->cdns_uart_driver); 1658 1761 return rc; 1659 1762 } 1660 1763
+2
drivers/tty/sysrq.c
··· 74 74 return 1; 75 75 return sysrq_enabled; 76 76 } 77 + EXPORT_SYMBOL_GPL(sysrq_mask); 77 78 78 79 /* 79 80 * A value of 1 means 'all', other nonzero values are an op mask: ··· 1059 1058 1060 1059 return 0; 1061 1060 } 1061 + EXPORT_SYMBOL_GPL(sysrq_toggle_support); 1062 1062 1063 1063 static int __sysrq_swap_key_ops(int key, struct sysrq_key_op *insert_op_p, 1064 1064 struct sysrq_key_op *remove_op_p)
+4 -3
drivers/tty/vt/vt.c
··· 81 81 #include <linux/errno.h> 82 82 #include <linux/kd.h> 83 83 #include <linux/slab.h> 84 + #include <linux/vmalloc.h> 84 85 #include <linux/major.h> 85 86 #include <linux/mm.h> 86 87 #include <linux/console.h> ··· 351 350 /* allocate everything in one go */ 352 351 memsize = cols * rows * sizeof(char32_t); 353 352 memsize += rows * sizeof(char32_t *); 354 - p = kmalloc(memsize, GFP_KERNEL); 353 + p = vmalloc(memsize); 355 354 if (!p) 356 355 return NULL; 357 356 ··· 367 366 368 367 static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr) 369 368 { 370 - kfree(vc->vc_uni_screen); 369 + vfree(vc->vc_uni_screen); 371 370 vc->vc_uni_screen = new_uniscr; 372 371 } 373 372 ··· 1207 1206 if (new_cols == vc->vc_cols && new_rows == vc->vc_rows) 1208 1207 return 0; 1209 1208 1210 - if (new_screen_size > (4 << 20)) 1209 + if (new_screen_size > KMALLOC_MAX_SIZE) 1211 1210 return -EINVAL; 1212 1211 newscreen = kzalloc(new_screen_size, GFP_USER); 1213 1212 if (!newscreen)