From patchwork Fri Oct 12 05:43:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 10637881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32BB4112B for ; Fri, 12 Oct 2018 05:43:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13FF52BF67 for ; Fri, 12 Oct 2018 05:43:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 054D52BF6E; Fri, 12 Oct 2018 05:43:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 678132BF67 for ; Fri, 12 Oct 2018 05:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=MLJTczAc9mlXD4APX7ANbqILyEaHEq8Jy25zbcJTezE=; b=A23 0p6BVcn82nhO+DtW5rt31NUYbytaUqnn9g66CYeebCB+K5bnf7Z3zC/Qllm8nLoI1WNm6R0SKsZ3E /r/jEEijk/gct4nmNWxtx4Roqzo7f/EuXNau5YVkS/1SLflSg4hTcn+6roAIYnYOjWUKUtrB4WSpX fgEJrqvtUb/qX04k/oG8BmpTYoNvyLkTWGfP/wi00ufBEXxzHtVCHBpTmFmLJum4ln0A7//ItNqaZ lb9wMqG8+DPoXV70M4yWfv10+qIj7XEp0af3l5dh4vXdD2ssQvS1CHJ7DzabVY9SC0tyI2hCUg15M AGcdEJYYcnw2NEThMxiKNul6GijCGWw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gAqEX-0007eK-OQ; Fri, 12 Oct 2018 05:43:33 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gAqET-0007cd-Pi for linux-arm-kernel@lists.infradead.org; Fri, 12 Oct 2018 05:43:31 +0000 Received: by mail-wm1-x342.google.com with SMTP id 193-v6so11616176wme.3 for ; Thu, 11 Oct 2018 22:43:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id; bh=Zsa0cn6PGxfFyqi8Z9uVse59foJB0FibfI32UvedOAo=; b=vqOrtOTNrFee1rr02zOGYDVqor+mAGw7DghaFHaDs9oReY4Dt4+IphwapvPCknS0jz gvMFfhSFd3dRv3cxWB5dnaab7pJ0ysRXIxO0mH09LjJMmSqjxX4fAPB8uMfYvAoBe40F 3395JBc0dH+mw0C/f76blbV+qpAohhWGFrT8EOAg4iROVsIxl48YRBgKxdIJMzvv6ByC pkjMMjj8HHUfJIC+rZYP6k8kRfkF2qCbpZL96mVFRQzYqZUJgB6t80tjvrdnVf151PU+ FeeiwRxmH3yuuyZWbjyen7c/f7SJRPl8W3Mmd0jgufD+iJ5u6WfB4ygD3XLu7020GF/F hkGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=Zsa0cn6PGxfFyqi8Z9uVse59foJB0FibfI32UvedOAo=; b=JmhSI+Wz/fLzT4+k89E26QdBiW2Q8XGFbQQVYjrEvOKBooXhqlWeIDNk9s+MfkgWNL Yx8pX22qpTy8Z9QUbeOn+w/PSVe94oVa1+QeEj5HTYu4Rou62NKsojldXmTx+aIEsxcu 3LmymMlbcgx3bWc2TvgYB7iQ59xa0nepOwf47D6ZVtnno57aBw2CxIO5HfUtLcCcj/Dn upDQvmp8hfoi5eUALm00a/YaOgVROGtfc88lcn/rOdDEiC7qTtLG6rkyZgp7BaQDetaq WZld0uPuYHr9BMImJ4gyKq22bOuKidGApoyhbSLILj5qMDzA/icYOGvDBrWqvGh0xFOc +pIA== X-Gm-Message-State: ABuFfojiPYGXaIrlCcC6naLIgaHrTR9ibF+upJrfkkkKLWjPMHxVLNA5 go21EOu9dco9l4aHn8uz/aXryg== X-Google-Smtp-Source: ACcGV60ZGyrjuCdV2qwAeihL8gvMZmXxJwP368foZDPvek5hnbuK3DQt2KNnzceiMPfKymyi4F7Wsg== X-Received: by 2002:a1c:6655:: with SMTP id a82-v6mr4187560wmc.10.1539322996790; Thu, 11 Oct 2018 22:43:16 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id q77-v6sm415316wmd.33.2018.10.11.22.43.15 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 11 Oct 2018 22:43:16 -0700 (PDT) From: Michal Simek To: linux-kernel@vger.kernel.org, monstr@monstr.eu, geert@linux-m68k.org, gregkh@linuxfoundation.org Subject: [PATCH v2] of: base: Change logic in of_alias_get_alias_list() Date: Fri, 12 Oct 2018 07:43:11 +0200 Message-Id: <1bc1488a4cbf21fafc64269958ba3ed04e0a3c1c.1539322989.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181011_224329_837417_0B84E4CE X-CRM114-Status: GOOD ( 19.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Rob Herring , linux-serial@vger.kernel.org, Jiri Slaby , Frank Rowand , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Rob Herring --- Changes in v2: - Use EOVERFLOW instead of EINVAL - Rob I have looked at it and I don't think there should be necessary to report error immediately back with partially initialized bitfield. The reason is that still there could be a console device which is most likely below that max limit and it is worth to return at least that nbits properly filled. It will also enable cases that you can still continue to use aliases higher then fields prepared for devices without alias. To be fixed patches are present in tty-next branch. And this patch depends on "of: base: Fix english spelling in of_alias_get_alias_list()" --- drivers/of/base.c | 22 ++++++++++++---------- drivers/tty/serial/xilinx_uartps.c | 2 +- 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 @@ int of_alias_get_id(struct device_node *np, const char *stem) * 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 d452dceb0cb3..b8f8abc96631 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -1393,7 +1393,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; }