Skip to content

Commit

Permalink
of: base: Change logic in of_alias_get_alias_list()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michal Simek authored and Greg Kroah-Hartman committed Oct 15, 2018
1 parent 7acf79b commit 59eaeba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions drivers/of/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion drivers/tty/serial/xilinx_uartps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 59eaeba

Please sign in to comment.