From patchwork Fri Oct 12 15:26:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 983139 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=st.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42WsBq1nvzz9s3Z for ; Sat, 13 Oct 2018 02:26:59 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id D1F2CC21D8A; Fri, 12 Oct 2018 15:26:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id AB739C21C4A; Fri, 12 Oct 2018 15:26:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C0D5AC21C4A; Fri, 12 Oct 2018 15:26:50 +0000 (UTC) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [62.209.51.94]) by lists.denx.de (Postfix) with ESMTPS id 77CAAC21C2C for ; Fri, 12 Oct 2018 15:26:50 +0000 (UTC) Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w9CFOKJW022506; Fri, 12 Oct 2018 17:26:47 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2n0se754bf-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 12 Oct 2018 17:26:47 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9505934; Fri, 12 Oct 2018 15:26:45 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 77DBF50D9; Fri, 12 Oct 2018 15:26:45 +0000 (GMT) Received: from SAFEX1HUBCAS22.st.com (10.75.90.93) by SAFEX1HUBCAS21.st.com (10.75.90.44) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 12 Oct 2018 17:26:45 +0200 Received: from localhost (10.201.23.85) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 12 Oct 2018 17:26:45 +0200 From: Patrick Delaunay To: Date: Fri, 12 Oct 2018 17:26:25 +0200 Message-ID: <1539357985-8753-1-git-send-email-patrick.delaunay@st.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.201.23.85] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-10-12_12:, , signatures=0 Cc: U-Boot STM32 Subject: [U-Boot] [PATCH] syscon: reset node list syscon_list after relocation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Reset the list head after the reallocation because the list syscon_list use allocated pointer and they are no more valid. This patch avoid issue (crash) when syscon_node_to_regmap() is called before and after reallocation. Signed-off-by: Patrick Delaunay --- Hi This patch correct a crash see on v2018.11-rc1 with my board stm32mp1 for the command "reset". The crash is a side effect of 2 patches 1f6ca3f42f6edf143473159297f4c515b1cf36f6 sysreset: syscon: update regmap access to syscon 23471aed5c33e104d6fa64575932577618543bec board_f: Add reset status printing With the first patch the syscon_node_to_regmap() is called each time that the class sysreset_syscon is probed. => in v2018.09 probe is done only when reset is requested NB: for stm32mp1, the node rcc_reboot in tagged pre-relocated to support reset in pre-reloc phases (allow panic). With the second patch, U-Boot probes all the sysreset uclass in preloc phase to allow to print the reset status, and the list is initialized in board_f / pre-reloc: -> print_resetinfo --> uclass_first_device_err(UCLASS_SYSRESET, &dev); ---> syscon_reboot_probe() ----> syscon_node_to_regmap(node) -----> of_syscon_register() -------> list_add_tail(&syscon->list, &syscon_list); During relocation, the content of syscon_list (static) is updated but the list use pointers allocated by malloc in pre-reloc phasis And when I execute the reset command -> do_reset() --> reset_cpu() ---> sysreset_walk_halt(SYSRESET_COLD); ----> loop on device UCLASS_SYSRESET -----> syscon_reboot_probe() ------> syscon_node_to_regmap(node) -------> list_for_each_entry(entry, &syscon_list, list) I have a crash here because the pointer syscon_list.next is invalid. I solve the issue by resetting the list after reloc and it is working but I don't know if a more elegant solution exist (keep the list in .bss section to be set to 0). Regards Patrick drivers/core/syscon-uclass.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c index 303e166..aacb43a 100644 --- a/drivers/core/syscon-uclass.c +++ b/drivers/core/syscon-uclass.c @@ -156,8 +156,15 @@ static struct syscon *of_syscon_register(ofnode node) struct regmap *syscon_node_to_regmap(ofnode node) { + static int reloc_done; struct syscon *entry, *syscon = NULL; + /* content of list is not relocated (malloc): reinit when needed */ + if (!reloc_done && (gd->flags & GD_FLG_RELOC)) { + INIT_LIST_HEAD(&syscon_list); + reloc_done++; + } + list_for_each_entry(entry, &syscon_list, list) if (ofnode_equal(entry->node, node)) { syscon = entry;