diff mbox series

[iproute2-next,5/7] ss: Fix coding style issues in user_ent_hash_build()

Message ID d32e90ccce3003fa0cdf05b95e0427de8a28684e.1653446538.git.peilin.ye@bytedance.com (mailing list archive)
State Accepted
Commit 210018bfe99b21effd3f6f2f67dec7dcba49decc
Delegated to: David Ahern
Headers show
Series ss: Introduce -T, --threads option | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Peilin Ye May 25, 2022, 2:53 a.m. UTC
From: Peilin Ye <peilin.ye@bytedance.com>

Make checkpatch.pl --strict happy about user_ent_hash_build().

Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
---
 misc/ss.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/misc/ss.c b/misc/ss.c
index ec14d746c669..42d04bf432eb 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -599,7 +599,7 @@  static void user_ent_hash_build(void)
 
 	strlcpy(name, root, sizeof(name));
 
-	if (strlen(name) == 0 || name[strlen(name)-1] != '/')
+	if (strlen(name) == 0 || name[strlen(name) - 1] != '/')
 		strcat(name, "/");
 
 	nameoff = strlen(name);
@@ -622,7 +622,8 @@  static void user_ent_hash_build(void)
 
 		snprintf(name + nameoff, sizeof(name) - nameoff, "%d/fd/", pid);
 		pos = strlen(name);
-		if ((dir1 = opendir(name)) == NULL) {
+		dir1 = opendir(name);
+		if (!dir1) {
 			freecon(pid_context);
 			continue;
 		}
@@ -640,9 +641,9 @@  static void user_ent_hash_build(void)
 			if (sscanf(d1->d_name, "%d%*c", &fd) != 1)
 				continue;
 
-			snprintf(name+pos, sizeof(name) - pos, "%d", fd);
+			snprintf(name + pos, sizeof(name) - pos, "%d", fd);
 
-			link_len = readlink(name, lnk, sizeof(lnk)-1);
+			link_len = readlink(name, lnk, sizeof(lnk) - 1);
 			if (link_len == -1)
 				continue;
 			lnk[link_len] = '\0';
@@ -650,7 +651,8 @@  static void user_ent_hash_build(void)
 			if (strncmp(lnk, pattern, strlen(pattern)))
 				continue;
 
-			sscanf(lnk, "socket:[%u]", &ino);
+			if (sscanf(lnk, "socket:[%u]", &ino) != 1)
+				continue;
 
 			if (getfilecon(name, &sock_context) <= 0)
 				sock_context = strdup(no_ctx);
@@ -658,16 +660,16 @@  static void user_ent_hash_build(void)
 			if (process[0] == '\0') {
 				FILE *fp;
 
-				snprintf(tmp, sizeof(tmp), "%s/%d/stat",
-					root, pid);
-				if ((fp = fopen(tmp, "r")) != NULL) {
+				snprintf(tmp, sizeof(tmp), "%s/%d/stat", root, pid);
+
+				fp = fopen(tmp, "r");
+				if (fp) {
 					if (fscanf(fp, "%*d (%[^)])", process) < 1)
 						; /* ignore */
 					fclose(fp);
 				}
 			}
-			user_ent_add(ino, process, pid, fd,
-					pid_context, sock_context);
+			user_ent_add(ino, process, pid, fd, pid_context, sock_context);
 			freecon(sock_context);
 		}
 		freecon(pid_context);