lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210810204818.880714-4-rostedt@goodmis.org>
Date:   Tue, 10 Aug 2021 16:48:12 -0400
From:   Steven Rostedt <rostedt@...dmis.org>
To:     linux-trace-devel@...r.kernel.org
Cc:     linux-kernel@...r.kernel.org, Tom Zanussi <zanussi@...nel.org>,
        Daniel Bristot de Oliveira <bristot@...hat.com>,
        Masami Hiramatsu <mhiramat@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        linux-rt-users <linux-rt-users@...r.kernel.org>,
        Clark Williams <williams@...hat.com>,
        "Steven Rostedt (VMware)" <rostedt@...dmis.org>
Subject: [PATCH 3/9] libtracefs: Change hist_data_key type to flags

From: "Steven Rostedt (VMware)" <rostedt@...dmis.org>

As the tracefs_hist_bucket_key will be exposed to users of the library,
have the type be flags, where it can be modified in the future, and not
break backward compatibility.

Signed-off-by: Steven Rostedt (VMware) <rostedt@...dmis.org>
---
 src/tracefs-hist-data.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/src/tracefs-hist-data.c b/src/tracefs-hist-data.c
index 6ec262e8b180..c7e110559ee8 100644
--- a/src/tracefs-hist-data.c
+++ b/src/tracefs-hist-data.c
@@ -113,10 +113,10 @@ static char *name_token(enum yytokentype type)
 	return NULL;
 }
 
-enum tracefs_bucket_key_type {
-	TRACEFS_BUCKET_KEY_UNDEF,
-	TRACEFS_BUCKET_KEY_SINGLE,
-	TRACEFS_BUCKET_KEY_RANGE,
+enum tracefs_bucket_key_flags {
+	TRACEFS_BUCKET_KEY_FL_UNDEF	= (1 << 29),
+	TRACEFS_BUCKET_KEY_FL_SINGLE	= (1 << 30),
+	TRACEFS_BUCKET_KEY_FL_RANGE	= (1 << 31),
 };
 
 struct tracefs_hist_bucket_key_single {
@@ -131,7 +131,7 @@ struct tracefs_hist_bucket_key_range {
 
 struct tracefs_hist_bucket_key {
 	struct tracefs_hist_bucket_key	*next;
-	enum tracefs_bucket_key_type	type;
+	unsigned int			flags;
 	union {
 		struct tracefs_hist_bucket_key_single	single;
 		struct tracefs_hist_bucket_key_range	range;
@@ -210,6 +210,8 @@ static int start_new_row(struct tracefs_hist_data *hdata)
 		return -1;
 	}
 
+	key->flags = TRACEFS_BUCKET_KEY_FL_UNDEF;
+
 	bucket->keys = key;
 	bucket->next_key = &key->next;
 
@@ -233,6 +235,8 @@ static int start_new_key(struct tracefs_hist_data *hdata)
 		return -1;
 	}
 
+	key->flags = TRACEFS_BUCKET_KEY_FL_UNDEF;
+
 	*bucket->next_key = key;
 	bucket->next_key = &key->next;
 
@@ -385,12 +389,13 @@ static int __do_key_val(struct tracefs_hist_data *hdata,
 	bucket = container_of(hdata->next_bucket, struct tracefs_hist_bucket, next);
 
 	key = container_of(bucket->next_key, struct tracefs_hist_bucket_key, next);
-	if (!key->type)
-		key->type = TRACEFS_BUCKET_KEY_SINGLE;
-
-	if (key->type != TRACEFS_BUCKET_KEY_SINGLE)
+	if (!(key->flags &
+	      (TRACEFS_BUCKET_KEY_FL_UNDEF | TRACEFS_BUCKET_KEY_FL_SINGLE)))
 		return -1;
 
+	key->flags &= ~TRACEFS_BUCKET_KEY_FL_UNDEF;
+	key->flags |= TRACEFS_BUCKET_KEY_FL_SINGLE;
+
 	k = &key->single;
 
 	len = strlen(text);
@@ -455,7 +460,7 @@ static int do_key_raw(struct tracefs_hist_data *hdata, char *text)
 	bucket = container_of(hdata->next_bucket, struct tracefs_hist_bucket, next);
 
 	key = container_of(bucket->next_key, struct tracefs_hist_bucket_key, next);
-	if (key->type != TRACEFS_BUCKET_KEY_SINGLE)
+	if (!(key->flags & TRACEFS_BUCKET_KEY_FL_SINGLE))
 		return -1;
 
 	k = &key->single;
@@ -487,12 +492,13 @@ static int do_key_range(struct tracefs_hist_data *hdata, long long start,
 
 	key = container_of(bucket->next_key, struct tracefs_hist_bucket_key, next);
 
-	if (!key->type)
-		key->type = TRACEFS_BUCKET_KEY_RANGE;
-
-	if (key->type != TRACEFS_BUCKET_KEY_RANGE)
+	if (!(key->flags &
+	      (TRACEFS_BUCKET_KEY_FL_UNDEF | TRACEFS_BUCKET_KEY_FL_RANGE)))
 		return -1;
 
+	key->flags &= ~TRACEFS_BUCKET_KEY_FL_UNDEF;
+	key->flags |= TRACEFS_BUCKET_KEY_FL_RANGE;
+
 	k = &key->range;
 
 	k->start = start;
@@ -698,13 +704,8 @@ void tracefs_hist_data_free(struct tracefs_hist_data *hdata)
 		hdata->buckets = bucket->next;
 		while ((key = bucket->keys)) {
 			bucket->keys = key->next;
-			switch (key->type) {
-			case TRACEFS_BUCKET_KEY_SINGLE:
+			if (key->flags & TRACEFS_BUCKET_KEY_FL_SINGLE)
 				free(key->single.sym);
-				break;
-			default:
-				break;
-			}
 			free(key);
 		}
 		while ((val = bucket->vals)) {
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ