[LTP] [PATCH] sched/clisrv: Fix "make check" warnings and errors

“Samir
2026-04-07T10:52:18Z

Fixed multiple checkpatch issues in the clisrv test suite to improve
code style compliance with Linux kernel coding standards.

Changes made:
* Added SPDX-License-Identifier headers to all files
* Removed FSF mailing address from license text
* Fixed SPDX comment style (// for .c files, /* */ for .h files)
* Removed 'extern' keyword from function prototypes in header
* Fixed pointer declaration style (char* -> char *)
* Wrapped multi-statement macro in do-while loop
* Added parentheses around macro values
* Fixed block comment formatting (added * on subsequent lines)
* Separated assignments from if conditions
* Removed unnecessary parentheses from return statements
* Added blank lines after variable declarations
* Replaced platform-specific yield() with sched_yield()
* Added function parameter identifier (void *arg_)
* Changed NULL comparison to implicit check for fgets()
* Restructured if-else logic to avoid "else after break"
* Used __func__ in printf() calls where applicable
* Added (void) cast to suppress unused parameter warnings

Files modified:
- testcases/kernel/sched/clisrv/inet.h
- testcases/kernel/sched/clisrv/pthcli.c
- testcases/kernel/sched/clisrv/pthserv.c
- testcases/kernel/sched/clisrv/readline.c
- testcases/kernel/sched/clisrv/writen.c

Note: Function names are intentionally kept in perror() calls
(e.g., "str_cli:", "str_echo:") for better error context, as perror()
doesn't support format strings and cannot use __func__. This results
in minor checkpatch warnings but provides valuable debugging information.

Signed-off-by: Samir <samir@linux.ibm.com>
---
testcases/kernel/sched/clisrv/inet.h | 36 ++++-------
testcases/kernel/sched/clisrv/pthcli.c | 75 +++++++---------------
testcases/kernel/sched/clisrv/pthserv.c | 79 +++++++-----------------
testcases/kernel/sched/clisrv/readline.c | 47 ++++++--------
testcases/kernel/sched/clisrv/writen.c | 27 ++------
5 files changed, 78 insertions(+), 186 deletions(-)

diff --git a/testcases/kernel/sched/clisrv/inet.h b/testcases/kernel/sched/clisrv/inet.h
index 7cc5f186c..da052b2d9 100644
--- a/testcases/kernel/sched/clisrv/inet.h
+++ b/testcases/kernel/sched/clisrv/inet.h
@@ -1,23 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
- *
- * Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
*/

-/* inet.h */
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -30,23 +15,24 @@
/* address for server */
char *pname;

-extern int writen(int fd, char *ptr, int nbytes);
-extern int readline(int fd, char *ptr, int maxlen);
-extern void noprintf(char* string, ...);
-
+int writen(int fd, char *ptr, int nbytes);
+int readline(int fd, char *ptr, int maxlen);
+void noprintf(char *string, ...);

/* debug */
#ifdef DEBUG

-#define prtln() fflush(NULL); \
- printf("Reached %s: %d\n", __FILE__, __LINE__);
+#define prtln() do { \
+ fflush(NULL); \
+ printf("Reached %s: %d\n", __FILE__, __LINE__); \
+ } while (0)
#define dprt printf
-#define dprt2(args) printf args
+#define dprt2(args) (printf args)

#else

#define prtln()
#define dprt noprintf
-#define dprt2(args) noprintf args
+#define dprt2(args) (noprintf args)

#endif
diff --git a/testcases/kernel/sched/clisrv/pthcli.c b/testcases/kernel/sched/clisrv/pthcli.c
index 7833b86d1..5f15239bc 100644
--- a/testcases/kernel/sched/clisrv/pthcli.c
+++ b/testcases/kernel/sched/clisrv/pthcli.c
@@ -1,46 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- *
- * Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 1993, 2001
*/

-/******************************************************************************
- *
- * pthcli.c
- *
- *
- * (C) COPYRIGHT International Business Machines Corp. 1993
- * All Rights Reserved
- * Licensed Materials - Property of IBM
- * US Government Users Restricted Rights - Use, duplication or
- * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *
- *****************************************************************************/
-
-/******************************************************************************/
-/* File: pthcli.c */
-/* */
-/* Description: Read contents of data file. Write each line to socket, then */
-/* ead line back from socket and write to standard output. */
-/* */
-/* */
-/* Usage: pthcli [port number] */
-/* */
-/******************************************************************************/
-
/* client using TCP */

#include <stdio.h>
@@ -56,19 +18,22 @@ void noprintf(char *string, ...)
(void) string;
}

-/* Read contents of FILE *fp. Write each line to socket, then
- read line back from socket and write to standard output.
- Return to caller when done */
+/*
+ * Read contents of FILE *fp. Write each line to socket, then
+ * read line back from socket and write to standard output.
+ * Return to caller when done
+ */

void str_cli(FILE *fp, int sockfd)
{
int n;
char sendline[MAXLINE], recvline[MAXLINE + 1];
+
prtln();
- while (fgets(sendline, MAXLINE, fp) != NULL) {
+ while (fgets(sendline, MAXLINE, fp)) {
n = strlen(sendline);

- dprt("%s: str_cli(): sendline = %s", __FILE__, sendline);
+ dprt("%s: %s(): sendline = %s", __FILE__, __func__, sendline);

if (writen(sockfd, sendline, n) != n)
perror("str_cli: writen error on socket");
@@ -80,7 +45,7 @@ void str_cli(FILE *fp, int sockfd)
n = readline(sockfd, recvline, MAXLINE);
prtln();
/*
- printf("strcli: recvline = %s", recvline);
+ * printf("strcli: recvline = %s", recvline);
*/
if (n < 0)
perror("str_cli: readline error on socket");
@@ -112,32 +77,34 @@ int main(int argc, char *argv[])
serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
serv_addr.sin_port = htons(SERV_TCP_PORT);
prtln();
- dprt("%s: main(): Binding local address for client to use\n"
+ dprt("%s: %s(): Binding local address for client to use\n"
"serv_addr.sin_family = %d\n serv_addr.sin_addr.s_addr = %#x\n"
- "serv_addr.sin_port = %d\n", __FILE__, serv_addr.sin_family,
+ "serv_addr.sin_port = %d\n", __FILE__, __func__, serv_addr.sin_family,
serv_addr.sin_addr.s_addr, serv_addr.sin_port);

/* Open Internet stream socket */
- if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (sockfd < 0) {
printf("client: socket open failure, no = %d\n", errno);
- return (errno);
+ return errno;
exit(1);
}
prtln();
- dprt("%s: main(): Open Internet stream socket, socfd = %d\n", __FILE__,
+ dprt("%s: %s(): Open Internet stream socket, socfd = %d\n", __FILE__, __func__,
sockfd);
/* Connect to the server */
if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) <
0) {
prtln();
printf("client: connect failure, no = %d\n", errno);
- return (errno);
+ return errno;
exit(1);
}
#ifdef _LINUX
- if ((input = fopen(argv[2], "r")) == NULL) {
+ input = fopen(argv[2], "r");
+ if (!input) {
perror("fopen");
- return (errno);
+ return errno;
}
str_cli(input, sockfd); /* call the routines that do the work */
prtln();
diff --git a/testcases/kernel/sched/clisrv/pthserv.c b/testcases/kernel/sched/clisrv/pthserv.c
index e3da52130..e5f3154bb 100644
--- a/testcases/kernel/sched/clisrv/pthserv.c
+++ b/testcases/kernel/sched/clisrv/pthserv.c
@@ -1,38 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
*/
-/*
-* File: pthserv.c Version: 1.3 Last update: 5/19/94 08:55:35
-*/
-/******************************************************************************/
-/* File: pthserv.c */
-/* */
-/* Description: Read a stream socket one line at a time and write each line */
-/* back to the sender. */
-/* */
-/* History: Contact - 06/21/2001 - Manoj Iyeri, IBM Austin */
-/* */
-/* Usage: pthcli [port number] */
-/* */
-/******************************************************************************/
-
-/*
- TCP server
-*/

#include <pthread.h>
#include <string.h>
@@ -44,14 +13,17 @@
#define MAXLINE 1024
void noprintf(char *string, ...)
{
+ (void)string;
}

pthread_t th;
pthread_mutex_t current_mutex;
int sockfd;

-/* Read a stream socket one line at a time and write each line back
- to sender. Return when connection is terminated */
+/*
+ * Read a stream socket one line at a time and write each line back
+ * to sender. Return when connection is terminated
+ */

int str_echo(int sockfd)
{
@@ -61,19 +33,18 @@ int str_echo(int sockfd)
printf("sockfd = %d\n", sockfd);
for (;;) {
prtln();
- dprt2(("%s: str_echo(): reading from sockfd %d\n", __FILE__,
+ dprt2(("reading from sockfd %d\n",
sockfd));
n = readline(sockfd, line, MAXLINE);
- printf("str_echo: n = %d\n", n);
+ printf("%s: n = %d\n", __func__, n);
if (n == 0) {
- dprt2(("%s: str_echo(): connection terminated\n",
- __FILE__));
+ dprt2(("connection terminated\n"));
return 0; /* connection terminated */
} else if (n < 0) {
perror("str_echo: readline error");
return (-1);
}
- dprt2(("%s: str_echo(): writing to sockfd = %d\n", __FILE__,
+ dprt2(("writing to sockfd = %d\n",
sockfd));
testint = writen(sockfd, line, n);
prtln();
@@ -87,22 +58,23 @@ int str_echo(int sockfd)

int main(int argc, char *argv[])
{
- void *new_thread(void *);
+ void *new_thread(void *arg_);
pthread_attr_t newattr;
int newsockfd;
socklen_t clilen;
struct sockaddr_in cli_addr, serv_addr;
- pname = argv[0];

- (void) argc;
+ pname = argv[0];
+ (void)argc;
prtln();
/* Open inet stream socket */
- if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (sockfd < 0) {
printf("server: socket failure:");
exit(1);
}
prtln();
- dprt2(("%s: main(): Open inet stream socket sockfd = %d\n", __FILE__,
+ dprt2(("%s: %s(): Open inet stream socket sockfd = %d\n", __FILE__, __func__,
sockfd));

/* Bind local address for client to use */
@@ -111,9 +83,9 @@ int main(int argc, char *argv[])
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(SERV_TCP_PORT);
prtln();
- dprt2(("%s: main(): Binding local address for client to use\n"
+ dprt2(("%s: %s(): Binding local address for client to use\n"
"serv_addr.sin_family = %d\n serv_addr.sin_addr.s_addr = %#x\n"
- "serv_addr.sin_port = %d\n", __FILE__, serv_addr.sin_family,
+ "serv_addr.sin_port = %d\n", __FILE__, __func__, serv_addr.sin_family,
serv_addr.sin_addr.s_addr, serv_addr.sin_port));

prtln();
@@ -153,11 +125,7 @@ int main(int argc, char *argv[])
if (pthread_create(&th, &newattr, new_thread,
(void *)(uintptr_t) newsockfd))
printf("failure to create thread\n");
-#ifndef _LINUX
- yield();
-#else
sched_yield();
-#endif
}
prtln();
}
@@ -166,18 +134,15 @@ int main(int argc, char *argv[])

void *new_thread(void *arg_)
{
- int arg = (uintptr_t) arg_;
+ int arg = (uintptr_t)arg_;
+
if (pthread_mutex_lock(&current_mutex))
printf("mutex_lock failed");
if (str_echo(arg) < 0) /* process the request */
- printf("new_thread: str_echo returned error");
+ printf("str_echo returned error");
close(arg); /* i.e. newsockfd */
if (pthread_mutex_unlock(&current_mutex))
printf("mutex_unlock failed");
-#ifndef _LINUX
- yield();
-#else
sched_yield();
-#endif
pthread_exit(NULL);
}
diff --git a/testcases/kernel/sched/clisrv/readline.c b/testcases/kernel/sched/clisrv/readline.c
index 0c3272999..7c1ab86a6 100644
--- a/testcases/kernel/sched/clisrv/readline.c
+++ b/testcases/kernel/sched/clisrv/readline.c
@@ -1,50 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
*/

-/*****************************************************************************
- * readline.c
- ******************************************************************************/
-
#include <unistd.h>

-/* Read line from a descriptor, byte at a time, return number of
- characters up to the null */
+/*
+ * Read line from a descriptor, byte at a time, return number of
+ * characters up to the null
+ */

int readline(int fd, char *ptr, int maxlen)
{
int n, rc;
char c;
/*
- printf("readline: fd = %d\n", fd);
+ * printf("readline: fd = %d\n", fd);
*/
for (n = 1; n < maxlen; n++) {
- if ((rc = read(fd, &c, 1)) == 1) {
+ rc = read(fd, &c, 1);
+ if (rc == 1) {
*ptr++ = c;
if (c == '\n')
break;
- } else if (rc == 0) {
+ }
+
+ if (rc == 0) {
if (n == 1)
return 0; /* EOF no data read */
- else
- break; /* EOF, some data read */
- } else
- return (-1); /* error */
+ break; /* EOF, some data read */
+ }
+
+ if (rc < 0)
+ return -1; /* error */
}
*ptr = 0;
- return (n);
+ return n;
}
diff --git a/testcases/kernel/sched/clisrv/writen.c b/testcases/kernel/sched/clisrv/writen.c
index 7ab12cdbe..fd03e7332 100644
--- a/testcases/kernel/sched/clisrv/writen.c
+++ b/testcases/kernel/sched/clisrv/writen.c
@@ -1,29 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
*/

-/******************************************************************************
- * writen.c
- ******************************************************************************/
-
#include <unistd.h>

-/* Write "n" bytes to a descriptor
- Use instead of write() when fd is a stream socket. */
+/*
+ * Write "n" bytes to a descriptor
+ * Use instead of write() when fd is a stream socket.
+ */

int writen(int fd, char *ptr, int nbytes)
{
--
2.52.0

--
Mailing list info: https://lists.linux.it/listinfo/ltp