From patchwork Fri Sep 16 06:44:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 670706 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sb66D306bz9rxl for ; Fri, 16 Sep 2016 17:16:52 +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=07vau/cO; 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 3sb66D1xsmzDsNS for ; Fri, 16 Sep 2016 17:16:52 +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=07vau/cO; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) (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 3sb5RV6rVKzDsZR for ; Fri, 16 Sep 2016 16:46:46 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=07vau/cO; dkim-atps=neutral Received: by mail-pf0-x242.google.com with SMTP id 21so1778744pfy.1 for ; Thu, 15 Sep 2016 23:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mHs3zviLu1OJIzOL3jMVIGFhAR2K8W0Ej2F3ggEP3qU=; b=07vau/cO9UtDGR2+dZMyzK6w+C1/wbWHTzjCqwcQVJ49TJRDs8bk+k0CvmbrgbDQxN hQZhWeLKPIcQSIVp3fhGBs1LJlv0GO7aZKa8n6v67BP1xU/wRmFZUk52qRahIBSe3Vk1 sPLU2PkNDOV5umA2iqZdDyLw8ptLyNKF5Up4OBhmf/KG3okr3fkktnoRqDONa459j2+p M4EfbJdswd6vwiTCfjYgIxmC+TfwW9Z5UicZCID5MSUW+67PS0Qn6arfqrjxZuff8wf4 YRS2S1VN7B3gqALMwpFwCyGIW2JRAtOYSO7yURYmYajEyDcVeZQY2t8qu7nTyRFoaehA ZzHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mHs3zviLu1OJIzOL3jMVIGFhAR2K8W0Ej2F3ggEP3qU=; b=HLi5Xz6G1NVhoDknuY1vqfMh4jdjijyrpBMPN5nvzWks107KJXSWRY2QGc8W7l26cQ Fk0ifH0vZmCI99SV/iPQWdnDC0N7P9gXzTEHa/meZTkpO9cv1nplilxvuEOpM0BHMcDN BuSBBe34M275EWUbYVzQyjqXO3rQAzKPcCHuE/fudtSj8UbM+WFgxY6KoCjwtIoaKPcv qxEiUvMjVmwB4n6lcqN2C8ub3i6wZAiHmEueMI51kr2CcegwQW1Xcnh+crnM3G2A3RI1 Qr+mKp4y0/5m/gjpTnzayjB2dTP7DzdgAvKpcZs/NcWvz3FlWacFwu3Nc/RJglagqjp3 dFIw== X-Gm-Message-State: AE9vXwMwomgsQ6GqL0NXHnxWhHPrLV+UX1+VjEYxvH+vFaTOrfCTsSdn0Kl7BN8xwOgzaw== X-Received: by 10.98.23.140 with SMTP id 134mr20556252pfx.96.1474008404960; Thu, 15 Sep 2016 23:46:44 -0700 (PDT) Received: from canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id 22sm15920382pft.10.2016.09.15.23.46.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Sep 2016 23:46:44 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Fri, 16 Sep 2016 16:44:59 +1000 Message-Id: <1474008303-20365-2-git-send-email-oohall@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1474008303-20365-1-git-send-email-oohall@gmail.com> References: <1474008303-20365-1-git-send-email-oohall@gmail.com> Subject: [Skiboot] [RFC PATCH 1/5] dt: add dt_new_check() X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.22 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" This is similar to dt_new(), but if the node already exists it will return the existing node. This is useful because some init code depends on the presence of certain nodes, but where the node is actually created is unimportant. Signed-off-by: Oliver O'Halloran Reviewed-by: Vasant Hegde --- core/device.c | 14 ++++++++++++++ include/device.h | 1 + 2 files changed, 15 insertions(+) diff --git a/core/device.c b/core/device.c index 9e7ef0d448d9..bd0674e31fda 100644 --- a/core/device.c +++ b/core/device.c @@ -352,6 +352,20 @@ struct dt_node *dt_find_by_name(struct dt_node *root, const char *name) return NULL; } + +struct dt_node *dt_new_check(struct dt_node *parent, const char *name) +{ + struct dt_node *node = dt_find_by_name(parent, name); + + if (!node) { + node = dt_new(parent, name); + assert(node); + } + + return node; +} + + struct dt_node *dt_find_by_phandle(struct dt_node *root, u32 phandle) { struct dt_node *node; diff --git a/include/device.h b/include/device.h index ed4fc460598f..47ec95b92528 100644 --- a/include/device.h +++ b/include/device.h @@ -67,6 +67,7 @@ struct dt_node *dt_new_addr(struct dt_node *parent, const char *name, uint64_t unit_addr); struct dt_node *dt_new_2addr(struct dt_node *parent, const char *name, uint64_t unit_addr0, uint64_t unit_addr1); +struct dt_node *dt_new_check(struct dt_node *parent, const char *name); /* Copy node to new parent, including properties and subnodes */ struct dt_node *dt_copy(struct dt_node *node, struct dt_node *parent);