Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4167447imm; Tue, 11 Sep 2018 07:57:50 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdau5RlEeGunMIj/UXzl39gQFGVJ9OFwxw11bdY5e9Tg+ucIQLU/D3xWgS0/XVt8D3Imvd/H X-Received: by 2002:a62:8559:: with SMTP id u86-v6mr30179257pfd.32.1536677870810; Tue, 11 Sep 2018 07:57:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536677870; cv=none; d=google.com; s=arc-20160816; b=F/NtYqUuCqfYB7LRTriTo8s2guztkIkRePQlhdv1Zdi2vUduqLdoNPUMDxnx6S+B/r 6xSpSRK7XVUWl2dahTav9243k7ls5W58Ueelmk6Kk/+pTQJgP5vrQctwT3XgNbEk/Gji cwugTiqWHQwyQTbnBz4hoyA20Xvt9jkeZbKQ+FdvKo3nVdPoH/Mi9ayo7r+9wtR/XxWF GOuJ94eABFy4U5b19KUE4nv6/OexcmhHmeyNob2eZmuVwU5mexWIiqrGcAh0Re2ZJEOF mSb7qrqEzSYKOxoUf4MmC7Y/HniI8ypra1crVaZe7bLqtShswUo+Dxdyvyrxof7uInn9 GHMA== 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=lFZ6LW3JbfhcotJTmx4bgdSFSug5mmkjhpvjmrJS+ZEeDI+R/2rC/SY8WnET+8ejTB /az1hyW70D+6nvZn8vOcpb5DlEtmiOZOKF47/3TfULOjFTjM4mCDtUft2S+zYzVC97I9 1kzuqEBCDpsymzXVGcTxXy12MaFPXwy9mRc9G/trWoWkV7ViBxFQ9LQANzINUiGIA0fB zmTq6QdTRnsRV80IkXk6TDSleblolat6WhJ4ZuOWEKtJQYtRZDJW58D2FraAatR8IDpL otWTDlszVAAT5/CLsBO0+SEGWt3+2kqkVDdVk+e2GZJWlWxM8qXq/Pzw1fQ28Txize/G yQaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 c1-v6si21430123pfe.29.2018.09.11.07.57.34; Tue, 11 Sep 2018 07:57:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1727231AbeIKTzt (ORCPT + 99 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(+) 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; -- 2.17.1