From patchwork Mon Oct 8 12:19:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 10630661 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 C391F16B1 for ; Mon, 8 Oct 2018 12:51:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B440B28E7B for ; Mon, 8 Oct 2018 12:51:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A80AE28F71; Mon, 8 Oct 2018 12:51:26 +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 1B32028F82 for ; Mon, 8 Oct 2018 12:51:26 +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=yw3Z/t8IFGiQ1Yb5SlGEMrp3AUJpxWcmIXiLTHwth5U=; b=eIW y/fT0dEEJSbTdWbqLCMLdfHHSfNX/K/dkvcom4roMAF7RFoXaKVIyEc0/30fgwImON2l6nwEciOir n5ok2ghIj7nyXfLZ9NIcDGcG8xjuy5jpgGC7o8NPkbLcxziFgkHVKOhe1cdVc5N8UxIzjxqb8NSJl +6+Z8VZSNRtkn7nopfDThIJWDPSuaBrhtSMb17LXbEbB/virWawenz9Vm8Gow27JLWtiFeaUy1Rr5 /rlFi7je0/KTdd1vrkvDAPTUj557d3JZNadJ5PJVYNvdaDsGfL7Qswwf6bImMKyiOM+PxHsJUhlLK C/W++uxf8004VU55yUrg2rniDwNcnAg==; 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 1g9V0B-00045j-PF; Mon, 08 Oct 2018 12:51:11 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9Uw5-0000uW-Ud for linux-arm-kernel@bombadil.infradead.org; Mon, 08 Oct 2018 12:46:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=NaiVNtYCDKE0Z4Xwjd4fDLoCLSWdI5pEGC87+tacw3U=; b=SMtIru1hBrKoOovg6Ukf9qkiL Wj61NGCCcdYKa8p8/y3biZMq+z6lU2JhUtqXCR9KYPnDLS6IjOISQouepv+v/ajo2qERuqwH9dj54 CVDWi0Lz2h+ayv+I6nDsTVE6ZqwDzdAxa0TArRpV3+pbZm3UppM54YmDPp8A1CwICmCcySZAHgZ8I EET7cN9GSQfQmzYldYyXnGWVQZpzjye+LPb43727irbTgmF02X7HV6Cb8CZiPAmCNwASFBOQij/++ v2uaQfrD5NbuIqD7jzk97Xpg2c7jlGh/CqHs1r3B5Vya7/8vRhhZebCJw8S+LcAkfB8itRjdHFRRS z5L9kTHRw==; Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9UVb-0004VV-4E for linux-arm-kernel@lists.infradead.org; Mon, 08 Oct 2018 12:19:36 +0000 Received: by mail-wr1-x442.google.com with SMTP id y11-v6so9847722wrd.4 for ; Mon, 08 Oct 2018 05:19:21 -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=NaiVNtYCDKE0Z4Xwjd4fDLoCLSWdI5pEGC87+tacw3U=; b=WQeC82njnSR42hpup7wZXwBNSubTb3gf8gaJFg7bXHyu8ZR7HAkKY8a8aICfTmvvu8 N5lSQVmNv0t8akMB8KP6EUtsW6pvMeDVbTAY8cgaRoMck1/FE3tSMzKVtY2HClK9uiFz bFTAuODAP3sFvJENnfGlrjM/QqQIncgpOUm/VvGAnKwYJkiMYPnmkqFaKC3uzmni0ILm akaN3v5yhXZMXo8sJ38Z7PRc9DmdBKx2Y86PqKexySVJImVpGvrxF1QcCxgO7R78X4BM 7r5TMdooiBNjsQ+IOkSHvFJ14HLznWncYsxEdKOgaPQEd0t5Va5nhy1WrxB43guPUG03 tXDA== 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=NaiVNtYCDKE0Z4Xwjd4fDLoCLSWdI5pEGC87+tacw3U=; b=oavzMOCBsz2+FC7CEQnztLIwpoGhBDpUyE+ktz0GqephMFTPZ9giFaradOZtzYGcxD o8gcwsyq8a7gVitBGNVU6m1j78psyxXt6jqhzgNnAcXeIG+dJ19RLZyprfPGlu84s6qm Np5Wnm84t2WK7hglX9Wr3adoXnchLtKH44PhY1ZbblJNeyxHn5Er/IEcTA+hwxBW+AXs i6mgRffLJaGKkBXuz3lZ6E5N20AH5E9mPqUd1x2v3Js9gyL7mQ0UiWoZw+Jb3ZRDyNZI X7V4+AOutRdWOV7OTu1V5J21gEBZUUfS5F3YAT8V4H/5FGPwmTEuMFcxEoZ2oigCr3g4 LyOg== X-Gm-Message-State: ABuFfojtr3yeF99jF1XY+o9qTUqExCSV36q6OAr2b4wGaZN8MR1uuHKV D+Hf3RLeJz17+VyIfjewFIhgxw== X-Google-Smtp-Source: ACcGV600COeaVu+CzzeFlBm8kweUyJWeRQdsiR930Wed7QACMfRbtGc6jBZWx5rfwHa+qMsR6mqMxA== X-Received: by 2002:adf:da43:: with SMTP id r3-v6mr16595987wrl.221.1539001159564; Mon, 08 Oct 2018 05:19:19 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id r16-v6sm22635162wrv.21.2018.10.08.05.19.18 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 08 Oct 2018 05:19:19 -0700 (PDT) From: Michal Simek To: linux-kernel@vger.kernel.org, monstr@monstr.eu, geert@linux-m68k.org, gregkh@linuxfoundation.org Subject: [PATCH] of: base: Change logic in of_alias_get_alias_list() Date: Mon, 8 Oct 2018 14:19:18 +0200 Message-Id: X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181008_081935_185544_88227767 X-CRM114-Status: GOOD ( 20.10 ) 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 --- 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. --- 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..0b9611e196d1 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 + * -EINVAL 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 = -EINVAL; + } 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..29a18103182d 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 != -EINVAL) { mutex_unlock(&bitmap_lock); return ret; }