[xlnx:master 227/525] drivers/tty/serial/xilinx_uartps.c:1520 cdns_get_id() warn: inconsistent returns '&bitmap_lock'.
Dan Carpenter
dan.carpenter at oracle.com
Thu Jun 24 02:28:28 PDT 2021
tree: https://github.com/Xilinx/linux-xlnx master
head: 163a7d26208a6794f595eeee3d54787df5e903d4
commit: e75553bc99db8983cdfc8c629a5ca741d9897053 [227/525] serial: uartps: Change uart ID port allocation
config: x86_64-randconfig-m001-20210622 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp at intel.com>
Reported-by: Dan Carpenter <dan.carpenter at oracle.com>
smatch warnings:
drivers/tty/serial/xilinx_uartps.c:1520 cdns_get_id() warn: inconsistent returns '&bitmap_lock'.
vim +1520 drivers/tty/serial/xilinx_uartps.c
e75553bc99db89 Michal Simek 2018-09-20 1456 static int cdns_get_id(struct platform_device *pdev)
e75553bc99db89 Michal Simek 2018-09-20 1457 {
e75553bc99db89 Michal Simek 2018-09-20 1458 int id, ret;
e75553bc99db89 Michal Simek 2018-09-20 1459
e75553bc99db89 Michal Simek 2018-09-20 1460 mutex_lock(&bitmap_lock);
e75553bc99db89 Michal Simek 2018-09-20 1461
e75553bc99db89 Michal Simek 2018-09-20 1462 /* Alias list is stable that's why get alias bitmap only once */
e75553bc99db89 Michal Simek 2018-09-20 1463 if (!alias_bitmap_initialized) {
e75553bc99db89 Michal Simek 2018-09-20 1464 ret = of_alias_get_alias_list(cdns_uart_of_match, "serial",
e75553bc99db89 Michal Simek 2018-09-20 1465 alias_bitmap, CDNS_UART_NR_PORTS);
e75553bc99db89 Michal Simek 2018-09-20 1466 if (ret)
e75553bc99db89 Michal Simek 2018-09-20 1467 return ret;
mutex_unlock(&bitmap_lock); before returning
e75553bc99db89 Michal Simek 2018-09-20 1468
e75553bc99db89 Michal Simek 2018-09-20 1469 alias_bitmap_initialized++;
e75553bc99db89 Michal Simek 2018-09-20 1470 }
e75553bc99db89 Michal Simek 2018-09-20 1471
e75553bc99db89 Michal Simek 2018-09-20 1472 /* Make sure that alias ID is not taken by instance without alias */
e75553bc99db89 Michal Simek 2018-09-20 1473 bitmap_or(bitmap, bitmap, alias_bitmap, CDNS_UART_NR_PORTS);
e75553bc99db89 Michal Simek 2018-09-20 1474
e75553bc99db89 Michal Simek 2018-09-20 1475 dev_dbg(&pdev->dev, "Alias bitmap: %*pb\n",
e75553bc99db89 Michal Simek 2018-09-20 1476 CDNS_UART_NR_PORTS, bitmap);
e75553bc99db89 Michal Simek 2018-09-20 1477
e75553bc99db89 Michal Simek 2018-09-20 1478 /* Look for a serialN alias */
e75553bc99db89 Michal Simek 2018-09-20 1479 id = of_alias_get_id(pdev->dev.of_node, "serial");
e75553bc99db89 Michal Simek 2018-09-20 1480 if (id < 0) {
e75553bc99db89 Michal Simek 2018-09-20 1481 dev_warn(&pdev->dev,
e75553bc99db89 Michal Simek 2018-09-20 1482 "No serial alias passed. Using the first free id\n");
e75553bc99db89 Michal Simek 2018-09-20 1483
e75553bc99db89 Michal Simek 2018-09-20 1484 /*
e75553bc99db89 Michal Simek 2018-09-20 1485 * Start with id 0 and check if there is no serial0 alias
e75553bc99db89 Michal Simek 2018-09-20 1486 * which points to device which is compatible with this driver.
e75553bc99db89 Michal Simek 2018-09-20 1487 * If alias exists then try next free position.
e75553bc99db89 Michal Simek 2018-09-20 1488 */
e75553bc99db89 Michal Simek 2018-09-20 1489 id = 0;
e75553bc99db89 Michal Simek 2018-09-20 1490
e75553bc99db89 Michal Simek 2018-09-20 1491 for (;;) {
e75553bc99db89 Michal Simek 2018-09-20 1492 dev_info(&pdev->dev, "Checking id %d\n", id);
e75553bc99db89 Michal Simek 2018-09-20 1493 id = find_next_zero_bit(bitmap, CDNS_UART_NR_PORTS, id);
e75553bc99db89 Michal Simek 2018-09-20 1494
e75553bc99db89 Michal Simek 2018-09-20 1495 /* No free empty instance */
e75553bc99db89 Michal Simek 2018-09-20 1496 if (id == CDNS_UART_NR_PORTS) {
e75553bc99db89 Michal Simek 2018-09-20 1497 dev_err(&pdev->dev, "No free ID\n");
e75553bc99db89 Michal Simek 2018-09-20 1498 mutex_unlock(&bitmap_lock);
e75553bc99db89 Michal Simek 2018-09-20 1499 return -EINVAL;
e75553bc99db89 Michal Simek 2018-09-20 1500 }
e75553bc99db89 Michal Simek 2018-09-20 1501
e75553bc99db89 Michal Simek 2018-09-20 1502 dev_dbg(&pdev->dev, "The empty id is %d\n", id);
e75553bc99db89 Michal Simek 2018-09-20 1503 /* Check if ID is empty */
e75553bc99db89 Michal Simek 2018-09-20 1504 if (!test_and_set_bit(id, bitmap)) {
e75553bc99db89 Michal Simek 2018-09-20 1505 /* Break the loop if bit is taken */
e75553bc99db89 Michal Simek 2018-09-20 1506 dev_dbg(&pdev->dev,
e75553bc99db89 Michal Simek 2018-09-20 1507 "Selected ID %d allocation passed\n",
e75553bc99db89 Michal Simek 2018-09-20 1508 id);
e75553bc99db89 Michal Simek 2018-09-20 1509 break;
e75553bc99db89 Michal Simek 2018-09-20 1510 }
e75553bc99db89 Michal Simek 2018-09-20 1511 dev_dbg(&pdev->dev,
e75553bc99db89 Michal Simek 2018-09-20 1512 "Selected ID %d allocation failed\n", id);
e75553bc99db89 Michal Simek 2018-09-20 1513 /* if taking bit fails then try next one */
e75553bc99db89 Michal Simek 2018-09-20 1514 id++;
e75553bc99db89 Michal Simek 2018-09-20 1515 }
e75553bc99db89 Michal Simek 2018-09-20 1516 }
e75553bc99db89 Michal Simek 2018-09-20 1517
e75553bc99db89 Michal Simek 2018-09-20 1518 mutex_unlock(&bitmap_lock);
e75553bc99db89 Michal Simek 2018-09-20 1519
e75553bc99db89 Michal Simek 2018-09-20 @1520 return id;
e75553bc99db89 Michal Simek 2018-09-20 1521 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
More information about the linux-arm-kernel
mailing list