Skip to content

Commit 59eaeba

Browse files
Michal Simekgregkh
authored andcommitted
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: b1078c3 ("of: base: Introduce of_alias_get_alias_list() to check alias IDs") Fixes: ae1cca3 ("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>
1 parent 7acf79b commit 59eaeba

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

drivers/of/base.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,13 +1953,15 @@ EXPORT_SYMBOL_GPL(of_alias_get_id);
19531953
* The function travels the lookup table to record alias ids for the given
19541954
* device match structures and alias stem.
19551955
*
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
19571958
*/
19581959
int of_alias_get_alias_list(const struct of_device_id *matches,
19591960
const char *stem, unsigned long *bitmap,
19601961
unsigned int nbits)
19611962
{
19621963
struct alias_prop *app;
1964+
int ret = 0;
19631965

19641966
/* Zero bitmap field to make sure that all the time it is clean */
19651967
bitmap_zero(bitmap, nbits);
@@ -1976,21 +1978,21 @@ int of_alias_get_alias_list(const struct of_device_id *matches,
19761978
continue;
19771979
}
19781980

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-
19851981
if (of_match_node(matches, app->np)) {
19861982
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+
}
19881991
}
1989-
/* Alias exists but is not compatible with matches */
19901992
}
19911993
mutex_unlock(&of_mutex);
19921994

1993-
return 0;
1995+
return ret;
19941996
}
19951997
EXPORT_SYMBOL_GPL(of_alias_get_alias_list);
19961998

drivers/tty/serial/xilinx_uartps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ static int cdns_get_id(struct platform_device *pdev)
13941394
if (!alias_bitmap_initialized) {
13951395
ret = of_alias_get_alias_list(cdns_uart_of_match, "serial",
13961396
alias_bitmap, MAX_UART_INSTANCES);
1397-
if (ret) {
1397+
if (ret && ret != -EOVERFLOW) {
13981398
mutex_unlock(&bitmap_lock);
13991399
return ret;
14001400
}

0 commit comments

Comments
 (0)