aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMichal Simek <michal.simek@xilinx.com>2018-10-12 01:43:11 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-10-15 10:16:06 -0400
commit59eaeba63a171127a90bb76187536ba66076af40 (patch)
tree9078a11d1a47315916fcb5a4ae835a97728b7572 /drivers
parent7acf79b6b2160540af87f47a55d7e3e5637ddeb5 (diff)
of: base: Change logic in of_alias_get_alias_list()
Check compatible string first before setting up bit in bitmap to also cover cases that allocated bitfield is not big enough. Show warning about it but let driver to continue to work with allocated bitfield to keep at least some devices (included console which is commonly close to serial0) to work. Fixes: b1078c355d76 ("of: base: Introduce of_alias_get_alias_list() to check alias IDs") Fixes: ae1cca3fa347 ("serial: uartps: Change uart ID port allocation") Signed-off-by: Michal Simek <michal.simek@xilinx.com> Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/of/base.c22
-rw-r--r--drivers/tty/serial/xilinx_uartps.c2
2 files changed, 13 insertions, 11 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 908de45f966b..6418205a05f5 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1953,13 +1953,15 @@ EXPORT_SYMBOL_GPL(of_alias_get_id);
1953 * The function travels the lookup table to record alias ids for the given 1953 * The function travels the lookup table to record alias ids for the given
1954 * device match structures and alias stem. 1954 * device match structures and alias stem.
1955 * 1955 *
1956 * Return: 0 or -ENOSYS when !CONFIG_OF 1956 * Return: 0 or -ENOSYS when !CONFIG_OF or
1957 * -EOVERFLOW if alias ID is greater then allocated nbits
1957 */ 1958 */
1958int of_alias_get_alias_list(const struct of_device_id *matches, 1959int of_alias_get_alias_list(const struct of_device_id *matches,
1959 const char *stem, unsigned long *bitmap, 1960 const char *stem, unsigned long *bitmap,
1960 unsigned int nbits) 1961 unsigned int nbits)
1961{ 1962{
1962 struct alias_prop *app; 1963 struct alias_prop *app;
1964 int ret = 0;
1963 1965
1964 /* Zero bitmap field to make sure that all the time it is clean */ 1966 /* Zero bitmap field to make sure that all the time it is clean */
1965 bitmap_zero(bitmap, nbits); 1967 bitmap_zero(bitmap, nbits);
@@ -1976,21 +1978,21 @@ int of_alias_get_alias_list(const struct of_device_id *matches,
1976 continue; 1978 continue;
1977 } 1979 }
1978 1980
1979 if (app->id >= nbits) {
1980 pr_debug("%s: ID %d greater then bitmap field %d\n",
1981 __func__, app->id, nbits);
1982 continue;
1983 }
1984
1985 if (of_match_node(matches, app->np)) { 1981 if (of_match_node(matches, app->np)) {
1986 pr_debug("%s: Allocated ID %d\n", __func__, app->id); 1982 pr_debug("%s: Allocated ID %d\n", __func__, app->id);
1987 set_bit(app->id, bitmap); 1983
1984 if (app->id >= nbits) {
1985 pr_warn("%s: ID %d >= than bitmap field %d\n",
1986 __func__, app->id, nbits);
1987 ret = -EOVERFLOW;
1988 } else {
1989 set_bit(app->id, bitmap);
1990 }
1988 } 1991 }
1989 /* Alias exists but is not compatible with matches */
1990 } 1992 }
1991 mutex_unlock(&of_mutex); 1993 mutex_unlock(&of_mutex);
1992 1994
1993 return 0; 1995 return ret;
1994} 1996}
1995EXPORT_SYMBOL_GPL(of_alias_get_alias_list); 1997EXPORT_SYMBOL_GPL(of_alias_get_alias_list);
1996 1998
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index c3f6cce300aa..57c66d2c3471 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -1394,7 +1394,7 @@ static int cdns_get_id(struct platform_device *pdev)
1394 if (!alias_bitmap_initialized) { 1394 if (!alias_bitmap_initialized) {
1395 ret = of_alias_get_alias_list(cdns_uart_of_match, "serial", 1395 ret = of_alias_get_alias_list(cdns_uart_of_match, "serial",
1396 alias_bitmap, MAX_UART_INSTANCES); 1396 alias_bitmap, MAX_UART_INSTANCES);
1397 if (ret) { 1397 if (ret && ret != -EOVERFLOW) {
1398 mutex_unlock(&bitmap_lock); 1398 mutex_unlock(&bitmap_lock);
1399 return ret; 1399 return ret;
1400 } 1400 }