File 0001-ppc64-diag-Move-trim_trail_space-function-to-common-.patch of Package ppc64-diag

From c507319d1b5f0286d67e08a3598949ca4144f475 Mon Sep 17 00:00:00 2001
From: Sathvika Vasireddy <sv@linux.ibm.com>
Date: Fri, 8 Sep 2023 12:35:12 +0530
Subject: [PATCH 1/3] ppc64-diag: Move trim_trail_space() function to
 common/utils.c

Upstream: merged, expected in 2.7.10
Git-commit: c507319d1b5f0286d67e08a3598949ca4144f475

Currently, trim_trail_space() function is used in diags/diag_nvme.c file
to be able to trim trailing white spaces from a given location code. Allow
code reusability by moving the trim_trail_space() function from
diags/diag_nvme.c to common/utils.c.

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.ibm.com>
---
 common/utils.c    | 25 +++++++++++++++++++++++++
 common/utils.h    |  1 +
 diags/Makefile.am |  4 +++-
 diags/diag_nvme.c | 24 +-----------------------
 4 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/common/utils.c b/common/utils.c
index 031294328fc3..2349878334b2 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -24,9 +24,34 @@
 #include <fcntl.h>
 #include <string.h>
 #include <assert.h>
+#include <ctype.h>
 
 #include "utils.h"
 
+/* trim_trail_space - Trim trailing white spaces from string
+ * @string - Null terminated string to remove white spaces from
+ *
+ * This function will alter the passed string by removing any trailing white spaces and null
+ * terminating it at that point.
+ */
+void trim_trail_space(char *string)
+{
+	char *end;
+	size_t length;
+
+	if (string == NULL)
+		return;
+
+	length = strlen(string);
+	if (length == 0)
+		return;
+
+	end = string + length - 1;
+	while (end >= string && isspace(*end))
+		end--;
+	*(end + 1) = '\0';
+}
+
 static int process_child(char *argv[], int pipefd[])
 {
 	int	nullfd;
diff --git a/common/utils.h b/common/utils.h
index ec2072db5a5b..2459b5be330b 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -18,6 +18,7 @@
 #ifndef UTILS_H
 #define UTILS_H
 
+void trim_trail_space(char *string);
 FILE	*spopen(char **, pid_t *);
 int	spclose(FILE *, pid_t);
 
diff --git a/diags/Makefile.am b/diags/Makefile.am
index 4ac81b8160be..dea0a79e0d2d 100644
--- a/diags/Makefile.am
+++ b/diags/Makefile.am
@@ -13,7 +13,8 @@ encl_led_h_files = diags/encl_led.h \
 		   $(diag_common_h_files)
 
 diag_nvme_h_files = diags/diag_nvme.h \
-		    common/platform.h
+		    common/platform.h \
+		    common/utils.h
 
 sbin_PROGRAMS += diags/diag_encl diags/encl_led diags/diag_nvme
 
@@ -41,6 +42,7 @@ diags_encl_led_SOURCES = diags/encl_led.c \
 
 diags_diag_nvme_SOURCES = diags/diag_nvme.c \
 			  common/platform.c \
+			  common/utils.c    \
 			  $(diag_nvme_h_files)
 diags_diag_nvme_LDADD = -lservicelog -lm
 diags_diag_nvme_CFLAGS = $(AM_CFLAGS) -Wno-stringop-truncation
diff --git a/diags/diag_nvme.c b/diags/diag_nvme.c
index 2a78034ecfd9..2606f2cb7784 100644
--- a/diags/diag_nvme.c
+++ b/diags/diag_nvme.c
@@ -27,6 +27,7 @@
 #include <sys/utsname.h>
 #include "diag_nvme.h"
 #include "platform.h"
+#include "utils.h"
 
 #define ITEM_DATA_LENGTH	255
 #define MIN_HOURS_ON		720
@@ -71,7 +72,6 @@ static int raw_data_smart(unsigned char **raw_data, uint32_t *raw_data_len, stru
 static int raw_data_vpd(unsigned char **raw_data, uint32_t *raw_data_len, struct nvme_ibm_vpd *vpd);
 static int regex_controller(char *controller_name, char *device_name);
 static void set_notify(struct notify *notify, struct dictionary *dict, int num_elements);
-static void trim_trail_space(char *string);
 static long double uint128_to_long_double(uint8_t *data);
 
 int main(int argc, char *argv[]) {
@@ -1426,28 +1426,6 @@ extern void set_vpd_pcie_field(const char *keyword, const char *vpd_data, struct
 		strncpy(vpd->firmware_level, vpd_data, sizeof(vpd->firmware_level));
 }
 
-/* trim_trail_space - Trim trailing white spaces from string
- * @string - Null terminated string to remove white spaces from
- *
- * This function will alter the passed string by removing any trailing white spaces and null
- * terminating it at that point.
- */
-static void trim_trail_space(char *string) {
-	char *end;
-	size_t length;
-
-	if (string == NULL)
-		return;
-
-	if ((length = strlen(string)) == 0)
-		return;
-
-	end = string + length - 1;
-	while (end >= string && isspace(*end))
-		end--;
-	*(end + 1) = '\0';
-}
-
 static long double uint128_to_long_double(uint8_t *data) {
 	int i;
 	long double value = 0;
-- 
2.42.0

openSUSE Build Service is sponsored by