From patchwork Tue Sep 11 14:56:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 146467 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3732486ljw; Tue, 11 Sep 2018 07:56:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbO+dL/ZYmE39he5riVlqr4y+ACuFoj4dKRuqRE6lk+GsTLw6TmbdFU6EumG7YykpZ1TfCE X-Received: by 2002:a63:6054:: with SMTP id u81-v6mr28952981pgb.433.1536677771989; Tue, 11 Sep 2018 07:56:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536677771; cv=none; d=google.com; s=arc-20160816; b=kbYOxQ+zV9VGXZPLjgfARtDzmY+ogfsn/hCula/RXuV4o/sgjBXMDxwuC4rMEBbTfQ naJae3o4rwrPJopjOJMpgWUk8MFKzNbMcJsYp0b+dPMJIQig3zMp2K6Do/3Aq/FzOtYl ia75zRgrZwjQSDdCZc0L52oXEOBhfgTFfuNdaQy17XH4M7viKQNVaxWVlgv5eNSVHdCu K2QHcCjGMgrUPMmJ+aDNFctJo3AJNv5KqchHBTS3fiz0drY2mFq793+el6ziqQ1RHdI6 WCq6LGWizcJe3I5ERJV15BT1JD50GRsvMGHRyYicoAX2hvXTygT7jaqbDxB+OiJdcv9x mtMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=k7AVLB9lcI+ZZD5i6K8Uly97g4wcFneJFRswawwZ9dg=; b=Iu5k4/LdoUxHlRRP3T9xfLA3i1yMwTqPMlf7vDnP4w13CC6YYNIU+IxGiQR+XEZ0QO 5LfCdNL26SxNxlKzs4NuqK3DoFjtP7UhfdwdxibSvntKWyI/bddLnXRxNJWOn10vKQZI gR8oez+GdKsXau+iLlv9RmQ1qMgdPadJkQ8ZM9N/2RKsAY7sS17SvAqmybs3Z1dM0v8X uaPgWxbpXRIgdqxZd5FIm2B2TL1hhzcF3fRZclLNPGeGlEWjMWo6phcUWdn56ZbEGGIv BL4tIHZwP12diPKA7rWhWWq0VPfitLWPSiHf5+dtkK0dK0Ptd1Lv0yRHecDQuSErDxbu 5K9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay12-v6si19535368plb.336.2018.09.11.07.56.11; Tue, 11 Sep 2018 07:56:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726761AbeIKTzt (ORCPT + 13 others); Tue, 11 Sep 2018 15:55:49 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:45745 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726622AbeIKTzt (ORCPT ); Tue, 11 Sep 2018 15:55:49 -0400 Received: by mail-oi0-f68.google.com with SMTP id t68-v6so47658556oie.12; Tue, 11 Sep 2018 07:56:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=k7AVLB9lcI+ZZD5i6K8Uly97g4wcFneJFRswawwZ9dg=; b=e7BVDETcA/5CViShXQmHJ/E7O1ugYFfEDm1GDMvCS3sAiIAfftMF+LKKCBozKiaDQG ap/h+moFPR6aa7caTxJpzNBCogyjQ9dQjsEHLrIhMow7HYleG/nQEfcQQ0wBRd4xwNJ3 6cMwX8sd07NN+uqGlymlAJgNZK+SmkJI81BKQq0SU1UGA+PEXi5nUrm8RokGdqk+QuD6 tOwfMLOLCiF8psR3AQULp49aluGKfBFfkmwRwtPDWTeKdkut4g3z2ltxYPsEFgNbMd7f fUiXXehKDu0QP5zsCzDnhsvz5z8xIckEuEbpc6R0BwC1zuvurNktA8JEwU8J92mlm7MW +mhw== X-Gm-Message-State: APzg51Bvdfarce51lj666IxmCeSbliXkhWsDywogqfkKYI94pKgJmf5K t6+PwmkY49pOYlDv/v2NYA== X-Received: by 2002:a54:448b:: with SMTP id v11-v6mr29223241oiv.208.1536677769415; Tue, 11 Sep 2018 07:56:09 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id y85-v6sm16403991oie.25.2018.09.11.07.56.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 07:56:08 -0700 (PDT) From: Rob Herring To: Finn Thain , Stan Johnson , Frank Rowand , Benjamin Herrenschmidt Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, stable@vger.kernel.org Subject: [PATCH] of: fix phandle cache creation for DTs with no phandles Date: Tue, 11 Sep 2018 09:56:07 -0500 Message-Id: <20180911145607.6009-1-robh@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org With commit 0b3ce78e90fc ("of: cache phandle nodes to reduce cost of of_find_node_by_phandle()"), a G3 PowerMac fails to boot. The root cause is the DT for this system has no phandle properties when booted with BootX. of_populate_phandle_cache() does not handle the case of no phandles correctly. The problem is roundup_pow_of_two() for 0 is undefined. The implementation subtracts 1 underflowing and then things are in the weeds. Fixes: 0b3ce78e90fc ("of: cache phandle nodes to reduce cost of of_find_node_by_phandle()") Cc: stable@vger.kernel.org # 4.17+ Reported-by: Finn Thain Tested-by: Stan Johnson Cc: Frank Rowand Cc: Benjamin Herrenschmidt Signed-off-by: Rob Herring --- Here's a formal patch of what Stan tested. Will send to Linus this week. Rob drivers/of/base.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.1 diff --git a/drivers/of/base.c b/drivers/of/base.c index a055cd1ef96d..17ae594b7014 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -140,6 +140,9 @@ void of_populate_phandle_cache(void) if (np->phandle && np->phandle != OF_PHANDLE_ILLEGAL) phandles++; + if (!phandles) + goto out; + cache_entries = roundup_pow_of_two(phandles); phandle_cache_mask = cache_entries - 1;