Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40A0CC6377C for ; Thu, 22 Jul 2021 03:39:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14E0761285 for ; Thu, 22 Jul 2021 03:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230225AbhGVC67 (ORCPT ); Wed, 21 Jul 2021 22:58:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:52594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbhGVC67 (ORCPT ); Wed, 21 Jul 2021 22:58:59 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0114861261; Thu, 22 Jul 2021 03:39:35 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94.2) (envelope-from ) id 1m6PYb-001Xmk-L3; Wed, 21 Jul 2021 23:39:33 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: Tom Zanussi , Masami Hiramatsu , Namhyung Kim , "Steven Rostedt (VMware)" Subject: [PATCH 1/4] libtracefs: Add tracefs_list_pop() to remove the last item Date: Wed, 21 Jul 2021 23:39:14 -0400 Message-Id: <20210722033917.367982-2-rostedt@goodmis.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722033917.367982-1-rostedt@goodmis.org> References: <20210722033917.367982-1-rostedt@goodmis.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (VMware)" Add a way to remove the last item of a string list. This will be needed to revert changes made to the new tracefs_synth structure that will have more than one tracefs_list char ** that must be the same size. If one is successfully updated, but the next one fails, the first one needs to be reverted. Signed-off-by: Steven Rostedt (VMware) --- include/tracefs.h | 1 + src/tracefs-utils.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/tracefs.h b/include/tracefs.h index 2649417654b1..4dd77b9c4119 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -66,6 +66,7 @@ int tracefs_error_clear(struct tracefs_instance *instance); void tracefs_list_free(char **list); char **tracefs_list_add(char **list, const char *string); int tracefs_list_size(char **list); +int tracefs_list_pop(char **list); /** * tracefs_trace_on_get_fd - Get a file descriptor of "tracing_on" in given instance diff --git a/src/tracefs-utils.c b/src/tracefs-utils.c index 600cdf2acefc..63bb413298fe 100644 --- a/src/tracefs-utils.c +++ b/src/tracefs-utils.c @@ -448,6 +448,32 @@ char **tracefs_list_add(char **list, const char *string) return list; } +/** + * tracefs_list_pop - Removes the last string added + * @list: The list to remove the last event from + * + * Returns 0 on success, -1 on error. + * Returns 1 if the list is empty or NULL. + */ +int tracefs_list_pop(char **list) +{ + unsigned long size; + + if (!list || list[0]) + return 1; + + list--; + size = *(unsigned long *)list; + /* size must be greater than zero */ + if (!size) + return -1; + size--; + *list = (char *)size; + list++; + list[size] = '\0'; + return 0; +} + /** * tracefs_list_size - Return the number of strings in the list * @list: The list to determine the size. -- 2.30.2