summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMichal Simek <michal.simek@xilinx.com>2018-10-12 07:43:11 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-10-15 16:16:06 +0200
commit59eaeba63a171127a90bb76187536ba66076af40 (patch)
tree9078a11d1a47315916fcb5a4ae835a97728b7572 /drivers
parent7acf79b6b2160540af87f47a55d7e3e5637ddeb5 (diff)
downloadlinux-59eaeba63a171127a90bb76187536ba66076af40.tar.bz2
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);
* The function travels the lookup table to record alias ids for the given
* device match structures and alias stem.
*
- * Return: 0 or -ENOSYS when !CONFIG_OF
+ * Return: 0 or -ENOSYS when !CONFIG_OF or
+ * -EOVERFLOW if alias ID is greater then allocated nbits
*/
int of_alias_get_alias_list(const struct of_device_id *matches,
const char *stem, unsigned long *bitmap,
unsigned int nbits)
{
struct alias_prop *app;
+ int ret = 0;
/* Zero bitmap field to make sure that all the time it is clean */
bitmap_zero(bitmap, nbits);
@@ -1976,21 +1978,21 @@ int of_alias_get_alias_list(const struct of_device_id *matches,
continue;
}
- if (app->id >= nbits) {
- pr_debug("%s: ID %d greater then bitmap field %d\n",
- __func__, app->id, nbits);
- continue;
- }
-
if (of_match_node(matches, app->np)) {
pr_debug("%s: Allocated ID %d\n", __func__, app->id);
- set_bit(app->id, bitmap);
+
+ if (app->id >= nbits) {
+ pr_warn("%s: ID %d >= than bitmap field %d\n",
+ __func__, app->id, nbits);
+ ret = -EOVERFLOW;
+ } else {
+ set_bit(app->id, bitmap);
+ }
}
- /* Alias exists but is not compatible with matches */
}
mutex_unlock(&of_mutex);
- return 0;
+ return ret;
}
EXPORT_SYMBOL_GPL(of_alias_get_alias_list);
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)
if (!alias_bitmap_initialized) {
ret = of_alias_get_alias_list(cdns_uart_of_match, "serial",
alias_bitmap, MAX_UART_INSTANCES);
- if (ret) {
+ if (ret && ret != -EOVERFLOW) {
mutex_unlock(&bitmap_lock);
return ret;
}