From patchwork Tue Oct 4 09:09:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 9361393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 34D28608A6 for ; Tue, 4 Oct 2016 09:10:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23DA5287A9 for ; Tue, 4 Oct 2016 09:10:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1858F2896C; Tue, 4 Oct 2016 09:10:50 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF4A528960 for ; Tue, 4 Oct 2016 09:10:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753982AbcJDJKg (ORCPT ); Tue, 4 Oct 2016 05:10:36 -0400 Received: from baptiste.telenet-ops.be ([195.130.132.51]:35426 "EHLO baptiste.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752150AbcJDJJk (ORCPT ); Tue, 4 Oct 2016 05:09:40 -0400 Received: from ayla.of.borg ([84.193.137.253]) by baptiste.telenet-ops.be with bizsmtp id rM9a1t0165UCtCs01M9a4s; Tue, 04 Oct 2016 11:09:38 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1brLjC-0003wr-Vj; Tue, 04 Oct 2016 11:09:34 +0200 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1brLjD-0007hr-Nr; Tue, 04 Oct 2016 11:09:35 +0200 From: Geert Uytterhoeven To: Simon Horman , Magnus Damm , Greg Kroah-Hartman , Arnd Bergmann , Yangbo Lu Cc: Lee Jones , Dirk Behme , linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 1/4] base: soc: Early register bus when needed Date: Tue, 4 Oct 2016 11:09:24 +0200 Message-Id: <1475572167-29581-2-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1475572167-29581-1-git-send-email-geert+renesas@glider.be> References: <1475572167-29581-1-git-send-email-geert+renesas@glider.be> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If soc_device_register() is called before soc_bus_register(), it crashes with a NULL pointer dereference. soc_bus_register() is already a core_initcall(), but drivers/base/ is entered later than e.g. drivers/pinctrl/ and drivers/soc/. Hence there are several subsystems that may need to know SoC revision information, while it's not so easy to initialize the SoC bus even earlier using an initcall. To fix this, let soc_device_register() register the bus early if that hasn't happened yet. Signed-off-by: Geert Uytterhoeven Acked-by: Arnd Bergmann --- drivers/base/soc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/base/soc.c b/drivers/base/soc.c index 75b98aad6fafd171..f612715d24754d27 100644 --- a/drivers/base/soc.c +++ b/drivers/base/soc.c @@ -114,6 +114,12 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr struct soc_device *soc_dev; int ret; + if (!soc_bus_type.p) { + ret = bus_register(&soc_bus_type); + if (ret) + goto out1; + } + soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL); if (!soc_dev) { ret = -ENOMEM; @@ -157,6 +163,9 @@ void soc_device_unregister(struct soc_device *soc_dev) static int __init soc_bus_register(void) { + if (soc_bus_type.p) + return 0; + return bus_register(&soc_bus_type); } core_initcall(soc_bus_register);