From patchwork Tue Feb 21 12:53:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 60083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1852645wrn; Tue, 21 Feb 2023 05:09:44 -0800 (PST) X-Google-Smtp-Source: AK7set+FqVpzMbMWFi299qMriu21ETr4uaCYbTsI6ghs6GiuPQb+1V7oH4u3RaDZ6t+iPjRRXKuK X-Received: by 2002:a05:6a21:789c:b0:c0:aacf:69d6 with SMTP id bf28-20020a056a21789c00b000c0aacf69d6mr15833918pzc.43.1676984984275; Tue, 21 Feb 2023 05:09:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984984; cv=none; d=google.com; s=arc-20160816; b=lUpaJyj5Cr+CMJsRKMhjMjKE0BdwMxSwKJj59c+fjmDk5SDAUZ7SEbEJ+uCd/6Os74 0TYeLEhwrwOtBZBDSNXD/G40tS6lsL3xE1FWWpD8wMSlAmhWw9QK2K7m3hV30jstZsno YQ4mL3nWvfjuVWHsndL5Uz0pErErPDYPn+VXmqloihiHuCT5fJQNF1YB5qn3y02epmXt xrMIbTp2UutMuLhhtc5ZjYipEB8Oo8rb289Ijo+SbcSLVV2v+/p4952yTVz9mRAt0KCH bURYWruoYHXmmkTqNOHuq7yE1Fg76Ijr8F0Omw1O0Ey1ik55e6zTXH1cC6OxHfP+Nkwe tA5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=wPbfUMIuA8aFMhZKtkZlw1tBq+C/4e/WB5E1O3dO1Y8=; b=eKapskIzmXmnBr/3WTjR0afM26NRGrd+0kMMP/PoQsNdREXEwBjI5/pVst5oMZy1Th 6UHDRlZGlRki5Vgy3mgfU3iNLpdYP28uVr3QVd8vWqk0DnyfBzVpmgv0CXk19azi6NPk FRuajx8vtv3wZVPNH2/I2MdLvthc4OeCo6hlbFtvDkjPzye6WK3jNOiTfMn4lJCtxSh4 olWdgHBdGJ+Vk4JYwOhONkxLzu9ttJeJ8qvZv8zuNvuGQU+1RQGEJZCpBblPfzxxPcZ3 hG+f/DdxAmpW7GizUKUuy5GRbM1R3BiN52i0UcAdQ7D63kYS3EVKHY94X0eZyWEMKXPK dalA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l185-20020a6388c2000000b00502d650cfa2si2967795pgd.811.2023.02.21.05.09.28; Tue, 21 Feb 2023 05:09:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233312AbjBUMyT (ORCPT + 99 others); Tue, 21 Feb 2023 07:54:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232986AbjBUMyR (ORCPT ); Tue, 21 Feb 2023 07:54:17 -0500 Received: from andre.telenet-ops.be (andre.telenet-ops.be [IPv6:2a02:1800:120:4::f00:15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D9D026CE5 for ; Tue, 21 Feb 2023 04:54:02 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed50:22fe:52b9:4e8:3dfc]) by andre.telenet-ops.be with bizsmtp id Potz290011v1X7l01otzqD; Tue, 21 Feb 2023 13:53:59 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1pUS9G-009ce4-DU; Tue, 21 Feb 2023 13:53:58 +0100 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1pUS9e-00149K-Rt; Tue, 21 Feb 2023 13:53:58 +0100 From: Geert Uytterhoeven To: Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: Arnd Bergmann , Lee Jones , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] driver core: bus: Handle early calls to bus_to_subsys() Date: Tue, 21 Feb 2023 13:53:51 +0100 Message-Id: <0a92979f6e790737544638e8a4c19b0564e660a2.1676983596.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758446206723100242?= X-GMAIL-MSGID: =?utf-8?q?1758446206723100242?= When calling soc_device_match() from early_initcall(), bus_kset is still NULL, causing a crash: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000028 ... Call trace: __lock_acquire+0x530/0x20f0 lock_acquire.part.0+0xc8/0x210 lock_acquire+0x64/0x80 _raw_spin_lock+0x4c/0x60 bus_to_subsys+0x24/0xac bus_for_each_dev+0x30/0xcc soc_device_match+0x4c/0xe0 r8a7795_sysc_init+0x18/0x60 rcar_sysc_pd_init+0xb0/0x33c do_one_initcall+0x128/0x2bc Before, bus_for_each_dev() handled this gracefully by checking that the back-pointer to the private structure was valid. Fix this by adding a NULL check for bus_kset to bus_to_subsys(). Fixes: 83b9148df2c95e23 ("driver core: bus: bus iterator cleanups") Signed-off-by: Geert Uytterhoeven Tested-by: Wolfram Sang --- drivers/base/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index cfe8615d5106f030..dd4b82d7510f68fb 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -62,7 +62,7 @@ static struct subsys_private *bus_to_subsys(const struct bus_type *bus) struct subsys_private *sp = NULL; struct kobject *kobj; - if (!bus) + if (!bus || !bus_kset) return NULL; spin_lock(&bus_kset->list_lock);