From patchwork Tue Mar 31 15:12:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 6130991 X-Patchwork-Delegate: horms@verge.net.au Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 59F65BF4A6 for ; Tue, 31 Mar 2015 15:12:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 37F0C2011E for ; Tue, 31 Mar 2015 15:12:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74773200D6 for ; Tue, 31 Mar 2015 15:12:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754549AbbCaPMc (ORCPT ); Tue, 31 Mar 2015 11:12:32 -0400 Received: from sauhun.de ([89.238.76.85]:48961 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754575AbbCaPMb (ORCPT ); Tue, 31 Mar 2015 11:12:31 -0400 Received: from p4fe24281.dip0.t-ipconnect.de ([79.226.66.129]:46645 helo=localhost) by pokefinder.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Ycxq5-0007Ji-1c; Tue, 31 Mar 2015 17:12:25 +0200 From: Wolfram Sang To: devicetree@vger.kernel.org Cc: linux-sh@vger.kernel.org, Magnus Damm , Simon Horman , Laurent Pinchart , Geert Uytterhoeven , Wolfram Sang , Pantelis Antoniou , Grant Likely , Rob Herring , linux-kernel@vger.kernel.org Subject: [PATCH] TESTCASE: of: OOPS when disabling node via OF_DYNAMIC Date: Tue, 31 Mar 2015 17:12:51 +0200 Message-Id: <1427814771-30335-1-git-send-email-wsa@the-dreams.de> X-Mailer: git-send-email 2.1.4 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wolfram Sang I wanted to disable a node via OF_DYNAMIC by setting its status to disabled. This code is the minimal testcase, the same happens in a more complex scenario. There is something wrong with freeing resources. Is my module wrong? Or is it a bug? Crashlog without CONFIG_I2C_CHARDEV, slightly shortened: [ 5.127314] of/notify UPDATE_PROPERTY /i2c@e60b0000:status [ 5.132814] i2c-sh_mobile e60b0000.i2c: pm_clk_notify() 2 [ 5.138504] bus: 'platform': remove device e60b0000.i2c [ 5.143762] i2c-sh_mobile e60b0000.i2c: pm_clk_notify() 6 [ 5.149231] device: '7-0068': device_unregister [ 5.153982] bus: 'i2c': remove device 7-0068 [ 5.158679] device: 'regulator.2': device_unregister [ 5.165827] i2c 7-0068: uevent [ 5.168997] i2c i2c-7: adapter [e60b0000.i2c] unregistered [ 5.174462] device: 'i2c-7': device_unregister [ 5.179057] bus: 'i2c': remove device i2c-7 [ 5.183570] platform e60b0000.i2c: pm_clk_notify() 7 [ 5.188595] platform e60b0000.i2c: Runtime PM disabled, clock forced off. [ 5.195368] platform e60b0000.i2c: pm_clk_notify() 3 [ 5.200426] Unable to handle kernel NULL pointer dereference at virtual address 00000018 [ 5.208474] pgd = c0004000 [ 5.211164] [00000018] *pgd=00000000 [ 5.214745] Internal error: Oops: 5 [#1] ARM [ 5.218995] CPU: 0 PID: 1 Comm: swapper Tainted: G W 4.0.0-rc4-00009-gcb55587ebc4047 #90 [ 5.228148] Hardware name: Generic R8A7790 (Flattened Device Tree) [ 5.234288] task: ee84d340 ti: ee84e000 task.ti: ee84e000 [ 5.239656] PC is at release_resource+0x20/0x68 [ 5.244171] LR is at _raw_write_lock+0x3c/0x44 [ 5.248591] pc : [] lr : [] psr: a0000113 [ 5.248591] sp : ee84fcd8 ip : ee84fcb0 fp : ee84fcec [ 5.259989] r10: 00000000 r9 : c03de2c0 r8 : c03d5694 [ 5.265180] r7 : ee84fdf4 r6 : 0000001c r5 : 00000000 r4 : ee8efd00 [ 5.271664] r3 : 00000000 r2 : 00000018 r1 : 00000009 r0 : c03c7cd8 [ 5.278149] Flags: NzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel [ 5.285410] Control: 10c5347d Table: 40004059 DAC: 00000015 [ 5.291117] Process swapper (pid: 1, stack limit = 0xee84e208) [ 5.296911] Stack: (0xee84fcd8 to 0xee850000) [ 5.301243] fcc0: 00000000 ee8f3e00 [ 5.309375] fce0: ee84fd0c ee84fcf0 c01604fc c0024168 c03d39a0 ee8f3e00 00000000 00000005 [ 5.317507] fd00: ee84fd24 ee84fd10 c016054c c0160494 c03d39a0 ee8f3e10 ee84fd3c ee84fd28 [ 5.325639] fd20: c01aad54 c0160544 ee8f3e34 ee8f3e00 ee84fd64 ee84fd40 c01ab3f8 c01aad08 ... [ 5.512643] Backtrace: [ 5.515097] [] (release_resource) from [] (platform_device_del+0x74/0x84) [ 5.523561] r4:ee8f3e00 r3:00000000 [ 5.527145] [] (platform_device_del) from [] (platform_device_unregister+0x14/0x20) [ 5.536469] r6:00000005 r5:00000000 r4:ee8f3e00 r3:c03d39a0 [ 5.542152] [] (platform_device_unregister) from [] (of_platform_device_destroy+0x58/0xa8) [ 5.552080] r4:ee8f3e10 r3:c03d39a0 [ 5.555667] [] (of_platform_device_destroy) from [] (of_platform_notify+0xcc/0xe8) [ 5.564905] r4:ee8f3e00 r3:ee8f3e34 [ 5.568493] [] (of_platform_notify) from [] (notifier_call_chain+0x48/0x70) [ 5.577128] r6:00000005 r5:00000000 r4:ffffffff [ 5.581759] [] (notifier_call_chain) from [] (__blocking_notifier_call_chain+0x4c/0x64) [ 5.591429] r8:00000005 r7:ee84fdf4 r6:ffffffff r5:c03d7ba4 r4:c03d7b98 r3:ffffffff [ 5.599192] [] (__blocking_notifier_call_chain) from [] (blocking_notifier_call_chain+0x20/0x28) [ 5.609637] r8:c0340d2c r7:c0340d2c r6:ee84fe88 r5:00000005 r4:ee84fdf4 [ 5.616365] [] (blocking_notifier_call_chain) from [] (of_reconfig_notify+0x88/0xa8) [ 5.625788] [] (of_reconfig_notify) from [] (of_property_notify+0x44/0x4c) [ 5.634338] r5:ee84fe88 r4:ee940440 [ 5.637925] [] (of_property_notify) from [] (__of_changeset_entry_notify+0x84/0xc4) [ 5.647263] [] (__of_changeset_entry_notify) from [] (of_changeset_apply+0xa4/0xe4) [ 5.656588] r4:ee940440 [ 5.659126] [] (of_changeset_apply) from [] (test_init+0x84/0xa8) [ 5.666900] r6:00000000 r5:c03356c0 r4:eefd18b8 [ 5.671533] [] (test_init) from [] (do_one_initcall+0x108/0x1bc) [ 5.679220] r4:ee940440 Signed-off-by: Wolfram Sang --- drivers/of/Makefile | 2 +- drivers/of/wsa_testcase.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 drivers/of/wsa_testcase.c diff --git a/drivers/of/Makefile b/drivers/of/Makefile index 7563f36c71db34..4ec30a5bab39d5 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -1,4 +1,4 @@ -obj-y = base.o device.o platform.o +obj-y = base.o device.o platform.o wsa_testcase.o obj-$(CONFIG_OF_DYNAMIC) += dynamic.o obj-$(CONFIG_OF_FLATTREE) += fdt.o obj-$(CONFIG_OF_EARLY_FLATTREE) += fdt_address.o diff --git a/drivers/of/wsa_testcase.c b/drivers/of/wsa_testcase.c new file mode 100644 index 00000000000000..b6bffd1acf76ad --- /dev/null +++ b/drivers/of/wsa_testcase.c @@ -0,0 +1,48 @@ +/* + * Testcase for disabling nodes via OF_DYNAMIC + * + * Copyright (C) 2015 by Wolfram Sang, Sang Engineering + * Copyright (C) 2015 by Renesas Electronics Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; version 2 of the License. + */ + +#include +#include +#include +#include +#include "of_private.h" + +static __init int test_init(void) +{ + + struct i2c_adapter *adap; + struct device_node *np; + struct of_changeset chgset; + struct property status_chg = { .name = "status", .length = 9, .value = "disabled" }; + int ret; + + // Use an active adapter here + adap = i2c_get_adapter(0); + if (!adap) + return -EPROBE_DEFER; + + np = adap->dev.of_node; + + i2c_put_adapter(adap); + + of_changeset_init(&chgset); + of_changeset_update_property(&chgset, np, &status_chg); + + mutex_lock(&of_mutex); + ret = of_changeset_apply(&chgset); + mutex_unlock(&of_mutex); + + return ret; +} +late_initcall(test_init); + +MODULE_AUTHOR("Wolfram Sang "); +MODULE_LICENSE("GPL v2");