From patchwork Tue May 16 09:03:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 762845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wRs271YcSz9s5L for ; Tue, 16 May 2017 19:03:59 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Keea8W98"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wRs270d56zDqdS for ; Tue, 16 May 2017 19:03:59 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Keea8W98"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wRs1s11QRzDqZp for ; Tue, 16 May 2017 19:03:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Keea8W98"; dkim-atps=neutral Received: by mail-pf0-x244.google.com with SMTP id n23so18100043pfb.3 for ; Tue, 16 May 2017 02:03:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6vn7vOP47PS3cJtFReGsyRdROT5KGLKXD33hk+9iqRg=; b=Keea8W98ROup20XLQTeSGHPzg7ahqOZNpvDw2ASLZKHksWHRT5D0AgpWVuXH/kmVyG CUAlwKVQHB58kzAcmYu6flLff8GKvnU8TFX63XsXG3splG3jJSEYXYNTmKFYi4eBVaHL afVqbeBbrb3TfqcpOYf2xIgTt4vCE+bWdFHlfwvLRv+tEFMKfHYXiTGQytlnz7wsKW6F 7T4wiuNYdgxvcmlvi6UCn8Ty5ANSBNd95yj2HTRsNC324HmAuSPqF3ClWogwqk8JEg/X uKIGJl8OByKceCTpy8rLt9X5BdTr1fzxWXyLobnUBSCCB40ClbvucN9u9ohzeIxkuxuq tRsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6vn7vOP47PS3cJtFReGsyRdROT5KGLKXD33hk+9iqRg=; b=BbcPOlDDFBobRSrjmyZEsg3rxIezbg9sp/kRi7HykTUcV9NrSt7BlkXHxbWmbda2vW C824cYgypWyGFI6i4zmDNRSDxC7mSm0OeszyTyGXW3ogJcIDqrqvpSiOpDKHb+YN+sNQ TX2wlFw2YGwB1IAHxzKPN3Zv0cqbFa9nmFIWLu2HkGx2y2K8+rSvKGChNXu99fd47Hvg kZIbPJdhcO/I70zQBAsWzOl90zDqRzRzoxgXQOEvsAbDpMOfcjn0ytR0PxxcRJohAgUP Kbx7+Z3yLk+kPcKPJ7PRddimhZAEgJ0cMSeH5yy1TpKN6yeLqL53pcKYQit08m4gGZNA MKnA== X-Gm-Message-State: AODbwcCc+IFPLmKJuPTVOe6o+vK4b6QMdnQdO8DahOfj0JiVIbLN3eyS e2rXAFk9VbLyAQ== X-Received: by 10.98.245.155 with SMTP id b27mr10851436pfm.181.1494925423189; Tue, 16 May 2017 02:03:43 -0700 (PDT) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id y20sm16407397pfb.93.2017.05.16.02.03.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 May 2017 02:03:42 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Tue, 16 May 2017 19:03:21 +1000 Message-Id: <20170516090321.22527-2-oohall@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170516090321.22527-1-oohall@gmail.com> References: <20170516090321.22527-1-oohall@gmail.com> Subject: [Skiboot] [PATCH 2/2] hdata: Fix NULL pointer dereference in LPC setup X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The HDAT parser runs before the per-cpu structures have been initialised and as a result get_chip() will always return NULL. This seems to work though since the first few bytes of memory are zeros and the LPC bus is usually attached to chip zero anyway. Fix this by using the proper function to conver the HDAT chip ID we get in the structure to a global chip ID using the low-level __phys_map_get() instead. Signed-off-by: Oliver O'Halloran --- hdata/fsp.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hdata/fsp.c b/hdata/fsp.c index 2c8254f930b2..5f8cffa540da 100644 --- a/hdata/fsp.c +++ b/hdata/fsp.c @@ -288,7 +288,8 @@ static void bmc_create_node(const struct HDIF_common_hdr *sp) const struct spss_sp_impl *sp_impl; struct dt_node *lpcm, *lpc, *n; u64 lpcm_base, lpcm_end; - int chip_id, size; + uint32_t gcid; + int size; bmc_node = dt_new(dt_root, "bmc"); assert(bmc_node); @@ -318,9 +319,13 @@ static void bmc_create_node(const struct HDIF_common_hdr *sp) return; #define GB (1024ul * 1024ul * 1024ul) - chip_id = be32_to_cpu(iopath->lpc.chip_id); + /* + * convert the hdat chip ID the HW chip id so we get the right + * phys map offset + */ + gcid = pcid_to_chip_id(be32_to_cpu(iopath->lpc.chip_id)); - phys_map_get(get_chip(chip_id), LPC_BUS, 0, &lpcm_base, NULL); + __phys_map_get(gcid, LPC_BUS, 0, &lpcm_base, NULL); lpcm = dt_new_addr(dt_root, "lpcm-opb", lpcm_base); assert(lpcm); @@ -330,7 +335,7 @@ static void bmc_create_node(const struct HDIF_common_hdr *sp) "ibm,power9-lpcm-opb", "simple-bus"); dt_add_property_u64s(lpcm, "reg", lpcm_base, 0x100000000ul); - dt_add_property_cells(lpcm, "ibm,chip-id", chip_id); + dt_add_property_cells(lpcm, "ibm,chip-id", gcid); /* Setup the ranges for the MMIO LPC */ lpcm_end = lpcm_base + 2 * GB; @@ -347,7 +352,7 @@ static void bmc_create_node(const struct HDIF_common_hdr *sp) io_bar = be32_to_cpu(iopath->lpc.io_bar); internal_bar = be32_to_cpu(iopath->lpc.internal_bar); - prlog(PR_DEBUG, "LPC: IOPATH chip id = %x\n", chip_id); + prlog(PR_DEBUG, "LPC: IOPATH chip id = %x\n", gcid); prlog(PR_DEBUG, "LPC: FW BAR = %#x\n", fw_bar); prlog(PR_DEBUG, "LPC: MEM BAR = %#x\n", mem_bar); prlog(PR_DEBUG, "LPC: IO BAR = %#x\n", io_bar);