From patchwork Thu Aug 16 05:57:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 958113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41rbH54Y4hz9s4Z for ; Thu, 16 Aug 2018 15:58:25 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="pIynG7ka"; 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 41rbH52MvZzDr5t for ; Thu, 16 Aug 2018 15:58:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="pIynG7ka"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41rbGh0TPXzDqgF for ; Thu, 16 Aug 2018 15:58:04 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="pIynG7ka"; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 41rbGg4SZBz9s4Z; Thu, 16 Aug 2018 15:58:03 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1534399083; bh=cK5o2XRDjGQwjPNsL8wx1jYlGrAyvrii0mvTwyBUFY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pIynG7kaJcUX/fjoTzTvdUQSdEL+snsgJ59UeDaZybAgtbIRUumDlKAPw7PYWDq2I DMZSBCszgoBnAObMWTB04ICX0KZH1djGRwEuqE9tFYInEKIDuJGEyErTmZEOz6UWcs yyvRc1nqOqbubt3S06rmi8j2gSAXawkGY9Pnj/PtY03nYgV+OwmEkwyqotUDyPQHnd wm0j2TpC1yCgS4SuXaGb3IUQxSUi2VKT2mtU0RMJU94Z7zkaP5zaWFaRDvn1PY0Ziu ViFQ1Hioif2bDXXHAF+N7u3h28bZJOZwSShndEfbcRLA71E+dUOJNWcHbrXm5Zypbz FaZlJVwJ8EqIQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 16 Aug 2018 15:57:56 +1000 Message-Id: <20180816055756.1011374-5-amitay@ozlabs.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180816055756.1011374-1-amitay@ozlabs.org> References: <20180816055756.1011374-1-amitay@ozlabs.org> Subject: [Pdbg] [PATCH 5/5] libpdbg: Return immediate parent if class is NULL X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" This avoids the segfault if class is NULL. Also, this api can be used to traverse the tree by explicitly setting class=NULL. Signed-off-by: Amitay Isaacs --- libpdbg/libpdbg.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 522bec9..810e045 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -89,6 +89,9 @@ struct pdbg_target *pdbg_target_parent(const char *class, struct pdbg_target *ta { struct pdbg_target *parent; + if (!class) + return target->parent; + for (parent = target->parent; parent && parent->parent; parent = parent->parent) { if (!strcmp(class, pdbg_target_class_name(parent))) return parent;