]> rtime.felk.cvut.cz Git - zynq/linux.git/commitdiff
serial: uartps: Do not allow use aliases >= MAX_UART_INSTANCES
authorMichal Simek <michal.simek@xilinx.com>
Mon, 8 Oct 2018 12:17:19 +0000 (14:17 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 11 Oct 2018 17:59:29 +0000 (19:59 +0200)
Aliases >= MAX_UART_INSTANCES is no problem to find out and use but in
error path is necessary skip clearing bits in bitmap to ensure that only
bits in allocated bitmap are handled and nothing beyond that.
Without this patch when for example serial90 alias is used then in error
patch bit 90 is clear in 32bit wide bitmap.

Fixes: ae1cca3fa347 ("serial: uartps: Change uart ID port allocation")
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/xilinx_uartps.c

index 0e3dae461f71806fd169735c034acc287ef2b173..c3f6cce300aaddb500166ab02b2c75c1750916f2 100644 (file)
@@ -1668,7 +1668,8 @@ err_out_unregister_driver:
        uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
 err_out_id:
        mutex_lock(&bitmap_lock);
-       clear_bit(cdns_uart_data->id, bitmap);
+       if (cdns_uart_data->id < MAX_UART_INSTANCES)
+               clear_bit(cdns_uart_data->id, bitmap);
        mutex_unlock(&bitmap_lock);
        return rc;
 }
@@ -1693,7 +1694,8 @@ static int cdns_uart_remove(struct platform_device *pdev)
        rc = uart_remove_one_port(cdns_uart_data->cdns_uart_driver, port);
        port->mapbase = 0;
        mutex_lock(&bitmap_lock);
-       clear_bit(cdns_uart_data->id, bitmap);
+       if (cdns_uart_data->id < MAX_UART_INSTANCES)
+               clear_bit(cdns_uart_data->id, bitmap);
        mutex_unlock(&bitmap_lock);
        clk_disable_unprepare(cdns_uart_data->uartclk);
        clk_disable_unprepare(cdns_uart_data->pclk);