Skip to contentSkip to conversation

sched/cfs-scheduler: Fix 'make check' errors and warnings in hackbench.c.

PATCH Superseded Samir Mulani 3 participants 3 messages Jul 22 – Jul 28

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 sched/cfs-scheduler: Fix 'make check' errors and warnings in hackbench.c.

Fix all 'make check' warnings in hackbench.c to comply with the LTP coding style guidelines. Add the missing SPDX-License-Identifier header and remove the unnecessary space after a cast as flagged by checkpatch.pl.

---
 .../kernel/sched/cfs-scheduler/hackbench.c    | 88 +++++++------------
 1 file changed, 33 insertions(+), 55 deletions(-)
testcases/kernel/sched/cfs-scheduler/hackbench.c +33 -55
index 6f37060aa..5ead2ffd7 100644
@@ -1,49 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /******************************************************************************/
-/* Copyright Rusty Russell,                                                   */
-/* Copyright Pierre Peiffer                                                   */
-/* Copyright Zhang, Yanmin,                                                   */
-/* Copyright Ingo Molnar,                                                     */
-/* Copyright Arjan van de Ven,                                                */
 /* Copyright (c) International Business Machines  Corp., 2008                 */
-/*                                                                            */
-/* 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 Rusty Russell <[email protected]>                            */
+/* Copyright Pierre Peiffer <[email protected]>                         */
+/* Copyright Ingo Molnar <[email protected]>                                      */
+/* Copyright Arjan van de Ven <[email protected]>                           */
+/* Copyright Zhang, Yanmin <[email protected]>                     */
+/* Copyright Nathan Lynch <[email protected]>                                     */
+/* Copyright Subrata Modak <[email protected]>                       */
 /*                                                                            */
 /******************************************************************************/
 
 /******************************************************************************/
 /*                                                                            */
-/* File:        hackbench.c                                                   */
-/*                                                                            */
 /* Description: hackbench tests the Linux scheduler. Test groups of 20        */
-/*              processes spraying to 20 receivers                            */
-/*                                                                            */
-/* Total Tests: 1                                                             */
-/*                                                                            */
-/* Test Name:   hackbench01 and hackbench02                                   */
-/*                                                                            */
-/* Test Assertion:                                                            */
-/*                                                                            */
-/* Author(s):   Rusty Russell <[email protected]>,                        */
-/*              Pierre Peiffer <[email protected]>,                     */
-/*              Ingo Molnar <[email protected]>,                                  */
-/*              Arjan van de Ven <[email protected]>,                       */
-/*              "Zhang, Yanmin" <[email protected]>,               */
-/*              Nathan Lynch <[email protected]>                                  */
-/*                                                                            */
-/* History:     Included into LTP                                             */
-/*                  - June 26 2008 - Subrata Modak<[email protected]>*/
+/*              processes spraying to 20 receivers.                           */
 /*                                                                            */
 /******************************************************************************/
 #include <pthread.h>
@@ -59,24 +30,24 @@
 #include <sys/poll.h>
 #include <limits.h>
 
-#define SAFE_FREE(p) { if (p) { free(p); (p)=NULL; } }
+#define SAFE_FREE(p) { if (p) { free(p); (p) = NULL; } }
 #define DATASIZE 100
 static struct sender_context **snd_ctx_tab;	/*Table for sender context pointers. */
 static struct receiver_context **rev_ctx_tab;	/*Table for receiver context pointers. */
-static int gr_num = 0;		/*For group calculation */
+static int gr_num;		/*For group calculation */
 static unsigned int loops = 100;
 /*
  * 0 means thread mode and others mean process (default)
  */
 static unsigned int process_mode = 1;
 
-static int use_pipes = 0;
+static int use_pipes;
 
 struct sender_context {
 	unsigned int num_fds;
 	int ready_out;
 	int wakefd;
-	int out_fds[0];
+	int out_fds[];
 };
 
 struct receiver_context {
@@ -115,7 +86,7 @@ static void fdpair(int fds[2])
 static void ready(int ready_out, int wakefd)
 {
 	char dummy;
-	struct pollfd pollfd = {.fd = wakefd,.events = POLLIN };
+	struct pollfd pollfd = {.fd = wakefd, .events = POLLIN};
 
 	/* Tell them we're ready. */
 	if (write(ready_out, &dummy, 1) != 1)
@@ -199,7 +170,7 @@ pthread_t create_worker(void *ctx, void *(*func) (void *))
 			exit(0);
 		}
 
-		return (pthread_t) 0;
+		return (pthread_t)0;
 	}
 
 	if (pthread_attr_init(&attr) != 0)
@@ -210,7 +181,9 @@ pthread_t create_worker(void *ctx, void *(*func) (void *))
 		barf("pthread_attr_setstacksize");
 #endif
 
-	if ((err = pthread_create(&childid, &attr, func, ctx)) != 0) {
+	err = pthread_create(&childid, &attr, func, ctx);
+
+	if (err != 0) {
 		fprintf(stderr, "pthread_create failed: %s (%d)\n",
 			strerror(err), err);
 		exit(-1);
@@ -235,15 +208,16 @@ void reap_worker(pthread_t id)
 }
 
 /* One group of senders and receivers */
-static unsigned int group(pthread_t * pth,
+static unsigned int group(pthread_t *pth,
 			  unsigned int num_fds, int ready_out, int wakefd)
 {
 	unsigned int i;
 	struct sender_context *snd_ctx = malloc(sizeof(struct sender_context) + num_fds * sizeof(int));
+
 	if (!snd_ctx)
 		barf("malloc()");
-	else
-		snd_ctx_tab[gr_num] = snd_ctx;
+
+	snd_ctx_tab[gr_num] = snd_ctx;
 
 	for (i = 0; i < num_fds; i++) {
 		int fds[2];
@@ -251,8 +225,8 @@ static unsigned int group(pthread_t * pth,
 
 		if (!ctx)
 			barf("malloc()");
-		else
-			rev_ctx_tab[gr_num * num_fds + i] = ctx;
+
+		rev_ctx_tab[gr_num * num_fds + i] = ctx;
 
 		/* Create the pipe between client and server */
 		fdpair(fds);
@@ -305,8 +279,12 @@ int main(int argc, char *argv[])
 		argv++;
 	}
 
-	if (argc >= 2 && (num_groups = atoi(argv[1])) == 0)
-		print_usage_exit();
+	if (argc >= 2) {
+		num_groups = atoi(argv[1]);
+
+		if (num_groups == 0)
+			print_usage_exit();
+	}
 
 	printf("Running with %d*40 (== %d) tasks.\n",
 	       num_groups, num_groups * 40);
@@ -363,9 +341,9 @@ int main(int argc, char *argv[])
 
 	/* free the memory */
 	for (i = 0; i < num_groups; i++) {
-		for (j = 0; j < num_fds; j++) {
-			SAFE_FREE(rev_ctx_tab[i * num_fds + j])
-		}
+		for (j = 0; j < num_fds; j++)
+			SAFE_FREE(rev_ctx_tab[i * num_fds + j]);
+
 		SAFE_FREE(snd_ctx_tab[i]);
 	}
 	SAFE_FREE(pth_tab);
Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Samir,

Quoted 1 line · Samir Mulani

sched/cfs-scheduler: Fix 'make check' errors and warnings in hackbench.c.

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Samir Mulani

Hi Samir,

Quoted 3 lines

This should never be part of the commit message, but stay in the --- section below.

The rest LGTM, but you have missed a couple of warnings:

CHECK testcases/kernel/sched/cfs-scheduler/hackbench.c
hackbench.c:82: WARNING: Prefer using '"%s...", __func__' to using 'fdpair', this function's name, in a string hackbench.c:93: WARNING: Prefer using '"%s...", __func__' to using 'ready', this function's name, in a string hackbench.c:310: WARNING: Prefer using '"%s...", __func__' to using 'main', this function's name, in a string

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp