Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp254981pxv; Wed, 14 Jul 2021 03:17:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSa1g46kUfYXXqlOVJ8IqPDWInuKcQWn/ASl/7+CHDtf/Ys6Mw9kke+AEods6JchGOse4r X-Received: by 2002:a17:906:eb99:: with SMTP id mh25mr10458595ejb.330.1626257837374; Wed, 14 Jul 2021 03:17:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626257837; cv=none; d=google.com; s=arc-20160816; b=nTlhTtaT6P1FeGDlarjS9JexMdUoDw/XGfqSRozli70S7CLguapQAwmueLzDETWhe6 aI1+5/WPMCKWsW5OcsR99PeeinSR32SjoPIdWJYn3s4hE7PV71Hzfre+QE2rQbleEDzH TpmW05N7sYp1JBV/IoV7BknBbb8ElMk2y8jm2FEghYkBd9nls4ZCEDevPZGa0kvqKT6b u76QRzLBpdd8La6QVs6FNSKxH2pGP0hg/66TaYH7LgN9J11qM68QUwhZMWPD3BRCC0iP RZVrG4NO7DxSNSbV7teZL1fZj+x5cbM+xGIayoLsMPdi1xLIN3/G1HUJ9ZD8ClyMPOak v6Tg== 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=rBt4x04CTkEWE4DTLc0YGIux2zX3e46oP5gzhvwkYwk=; b=bnsvyCs2VlM6dpDN2x/IuAGJpOWHPGAgtYi1taDZsNac/WZzDQwSiAnOL0nXEVSQj6 6OWY89QvpwvteQe5a80AF8tpIcIgyvkAOKgf5ZwJaVs+BvzZYh2e9DBJZTcbX0V3fsYQ ZBoNvKPKpdvBqaJ3DS6Yo84glV45X/VcZPuO2Xs9/d+XlhHdd9mNuwPNGX3INdRfLVEh aWIQETqhsvbhtExh/DpV7FLkdmvpt0rDiErgZXbPc/mY9dPkuIGxD9lznctcOEKFwAWB F/R0/FpKfSjGGPytzBFTB7NRhzHTt0hLP0gH6N/rxnbVCP/DkJkeCl76jwm/BhZnTp41 05Sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si2533069ejj.278.2021.07.14.03.16.53; Wed, 14 Jul 2021 03:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238638AbhGNKQr (ORCPT + 99 others); Wed, 14 Jul 2021 06:16:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239008AbhGNKQr (ORCPT ); Wed, 14 Jul 2021 06:16:47 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1624C061762 for ; Wed, 14 Jul 2021 03:13:55 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed10:39cc:190a:2775:cfe7]) by laurent.telenet-ops.be with bizsmtp id UyDr2500c1ccfby01yDrca; Wed, 14 Jul 2021 12:13:54 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m3btn-0016Zx-IJ; Wed, 14 Jul 2021 12:13:51 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1m3btm-00A6LB-O2; Wed, 14 Jul 2021 12:13:50 +0200 From: Geert Uytterhoeven To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Kevin Hilman , Ulf Hansson Cc: Saravana Kannan , Bartosz Golaszewski , Magnus Damm , linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2] staging: board: Fix uninitialized spinlock when attaching genpd Date: Wed, 14 Jul 2021 12:13:46 +0200 Message-Id: <57783ece7ddae55f2bda2f59f452180bff744ea0.1626257398.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Armadillo-800-EVA with CONFIG_DEBUG_SPINLOCK=y: BUG: spinlock bad magic on CPU#0, swapper/1 lock: lcdc0_device+0x10c/0x308, .magic: 00000000, .owner: /-1, .owner_cpu: 0 CPU: 0 PID: 1 Comm: swapper Not tainted 5.11.0-rc5-armadillo-00036-gbbca04be7a80-dirty #287 Hardware name: Generic R8A7740 (Flattened Device Tree) [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (do_raw_spin_lock+0x20/0x94) [] (do_raw_spin_lock) from [] (dev_pm_get_subsys_data+0x8c/0x11c) [] (dev_pm_get_subsys_data) from [] (genpd_add_device+0x78/0x2b8) [] (genpd_add_device) from [] (of_genpd_add_device+0x34/0x4c) [] (of_genpd_add_device) from [] (board_staging_register_device+0x11c/0x148) [] (board_staging_register_device) from [] (board_staging_register_devices+0x24/0x28) of_genpd_add_device() is called before platform_device_register(), as it needs to attach the genpd before the device is probed. But the spinlock is only initialized when the device is registered. Fix this by open-coding the spinlock initialization, cfr. device_pm_init_common() in the internal drivers/base code, and in the SuperH early platform code. Signed-off-by: Geert Uytterhoeven --- Exposed by fw_devlinks changing probe order. Masked before due to an unrelated wait context check failure, which disabled any further spinlock checks. https://lore.kernel.org/linux-acpi/CAMuHMdVL-1RKJ5u-HDVA4F4w_+8yGvQQuJQBcZMsdV4yXzzfcw@mail.gmail.com v2: - Improve code comment. --- drivers/staging/board/board.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/staging/board/board.c b/drivers/staging/board/board.c index cb6feb34dd401ae3..f980af0373452cab 100644 --- a/drivers/staging/board/board.c +++ b/drivers/staging/board/board.c @@ -136,6 +136,7 @@ int __init board_staging_register_clock(const struct board_staging_clk *bsc) static int board_staging_add_dev_domain(struct platform_device *pdev, const char *domain) { + struct device *dev = &pdev->dev; struct of_phandle_args pd_args; struct device_node *np; @@ -148,7 +149,11 @@ static int board_staging_add_dev_domain(struct platform_device *pdev, pd_args.np = np; pd_args.args_count = 0; - return of_genpd_add_device(&pd_args, &pdev->dev); + /* Initialization similar to device_pm_init_common() */ + spin_lock_init(&dev->power.lock); + dev->power.early_init = true; + + return of_genpd_add_device(&pd_args, dev); } #else static inline int board_staging_add_dev_domain(struct platform_device *pdev, -- 2.25.1