Skip to contentSkip to conversation

fstests: enable sparse checking & fix fallout

PATCH Superseded Eric Sandeen 4 participants 25 messages Feb 6, 2025 – Feb 7, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover fstests: enable sparse checking & fix fallout

After the endian bug last week, hch asked whether we should enable sparse checking in xfstests.

This does so, in the same manner as the kernel and xfsprogs,i.e. make C=1 or make C=2.

The rest of the patches fix most of the warnings that showed up for me after that.

Thanks,
-Eric

#1 lore raw

PATCH 1/7 fstests: enable sparse checking with make C=[12]

Enable "make C=1" sparse checking when files get rebuilt. To check all files, run "make clean" first.

Enable "make C=2" sparse checking of all files without rebuilding them.

---
 Makefile           | 14 ++++++++++++++
 include/buildrules | 19 +++++++++++++++++++
 2 files changed, 33 insertions(+)
Makefile +14 -0
index f6f91a4d..79779d5e 100644
@@ -14,6 +14,20 @@ else
   Q = @
 endif
 
+CHECK=sparse
+CHECK_OPTS=-Wsparse-all -Wbitwise -Wno-transparent-union -Wno-return-void -Wno-undef \
+	-Wno-non-pointer-null -D__CHECK_ENDIAN__ -D__linux__
+
+ifeq ("$(origin C)", "command line")
+  CHECK_CMD=$(CHECK) $(CHECK_OPTS)
+  CHECKSRC=$(C)
+else
+  CHECK_CMD=@true
+  CHECKSRC=0
+endif
+
+export CHECK_CMD CHECKSRC
+
 MAKEOPTS = --no-print-directory Q=$(Q)
 
 TOPDIR = .
include/buildrules +19 -0
index bf187662..6c2b7e18 100644
@@ -35,6 +35,21 @@ endif
 # Standard targets
 #
 
+ifeq ($(CHECKSRC),2)
+
+# Check every .c file with sparse CHECK_CMD, do not call compiler
+$(LTCOMMAND) $(LTLIBRARY) : $(SUBDIRS) $(OBJECTS)
+.PHONY: $(LTCOMMAND) $(LTLIBRARY)
+
+%.lo %.o : %.c FORCE
+	@echo "    [CHECK]  $<"
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
+
+FORCE:
+
+else
+# Regular build, possibly calling sparse CHECK_CMD as well
+
 ifdef LTCOMMAND
 $(LTCOMMAND) : $(SUBDIRS) $(OBJECTS) $(LTDEPENDENCIES)
 	@echo "    [LD] $*"
@@ -49,12 +64,16 @@ $(LTLIBRARY) : $(SUBDIRS) $(LTOBJECTS)
 %.lo: %.c
 	@echo "    [CC] $@"
 	$(Q)$(LTCOMPILE) -c $<
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
 else
+
 %.o: %.c
 	@echo "    [CC] $@"
 	$(Q)$(CC) $(CFLAGS) -c $<
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
 
 endif
+endif
 
 ifdef POTHEAD
 %.pot: $(XGETTEXTFILES)
Signature · 1 line
2.48.0
Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] fstests: enable sparse checking with make C=[12]

Quoted 6 lines · Eric Sandeen

Enable "make C=1" sparse checking when files get rebuilt. To check all files, run "make clean" first.

Enable "make C=2" sparse checking of all files without rebuilding them.

Looks just like the one in xfsprogs and the kernel!

--D

Quoted 77 lines
---
 Makefile           | 14 ++++++++++++++
 include/buildrules | 19 +++++++++++++++++++
 2 files changed, 33 insertions(+)
Makefile +14 -0
index f6f91a4d..79779d5e 100644
@@ -14,6 +14,20 @@ else
   Q = @
 endif
 
+CHECK=sparse
+CHECK_OPTS=-Wsparse-all -Wbitwise -Wno-transparent-union -Wno-return-void -Wno-undef \
+	-Wno-non-pointer-null -D__CHECK_ENDIAN__ -D__linux__
+
+ifeq ("$(origin C)", "command line")
+  CHECK_CMD=$(CHECK) $(CHECK_OPTS)
+  CHECKSRC=$(C)
+else
+  CHECK_CMD=@true
+  CHECKSRC=0
+endif
+
+export CHECK_CMD CHECKSRC
+
 MAKEOPTS = --no-print-directory Q=$(Q)
 
 TOPDIR = .
include/buildrules +19 -0
index bf187662..6c2b7e18 100644
@@ -35,6 +35,21 @@ endif
 # Standard targets
 #
 
+ifeq ($(CHECKSRC),2)
+
+# Check every .c file with sparse CHECK_CMD, do not call compiler
+$(LTCOMMAND) $(LTLIBRARY) : $(SUBDIRS) $(OBJECTS)
+.PHONY: $(LTCOMMAND) $(LTLIBRARY)
+
+%.lo %.o : %.c FORCE
+	@echo "    [CHECK]  $<"
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
+
+FORCE:
+
+else
+# Regular build, possibly calling sparse CHECK_CMD as well
+
 ifdef LTCOMMAND
 $(LTCOMMAND) : $(SUBDIRS) $(OBJECTS) $(LTDEPENDENCIES)
 	@echo "    [LD] $*"
@@ -49,12 +64,16 @@ $(LTLIBRARY) : $(SUBDIRS) $(LTOBJECTS)
 %.lo: %.c
 	@echo "    [CC] $@"
 	$(Q)$(LTCOMPILE) -c $<
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
 else
+
 %.o: %.c
 	@echo "    [CC] $@"
 	$(Q)$(CC) $(CFLAGS) -c $<
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
 
 endif
+endif
 
 ifdef POTHEAD
 %.pot: $(XGETTEXTFILES)
Signature · 1 line
2.48.0
#4 lore raw

PATCH 2/7 builddefs: define linux

In reply to Eric Sandeen

There are several #ifdef linux guards in the code, but nothing defined it. This caused several sparse warnings, so define it when building on linux.

---
 include/builddefs.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/builddefs.in +1 -1
index 7274cde8..00dec0ea 100644
@@ -78,7 +78,7 @@ HAVE_FICLONE = @have_ficlone@
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall
 
 ifeq ($(PKG_PLATFORM),linux)
-PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $(GCCFLAGS)
+PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -Dlinux $(GCCFLAGS)
 endif
 ifeq ($(PKG_PLATFORM),darwin)
 PCFLAGS = -traditional-cpp $(GCCFLAGS)
Signature · 1 line
2.48.0
#5 lore raw

Re: [PATCH 2/7] builddefs: define linux

Quoted 3 lines · Eric Sandeen

There are several #ifdef linux guards in the code, but nothing defined it. This caused several sparse warnings, so define it when building on linux.

cpp in gcc 12.2 defines this:

$ touch /tmp/moo.h ; cpp -dM /tmp/moo.h | grep define.linux
#define linux 1

--D

Quoted 22 lines
---
 include/builddefs.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/builddefs.in +1 -1
index 7274cde8..00dec0ea 100644
@@ -78,7 +78,7 @@ HAVE_FICLONE = @have_ficlone@
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall
 
 ifeq ($(PKG_PLATFORM),linux)
-PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $(GCCFLAGS)
+PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -Dlinux $(GCCFLAGS)
 endif
 ifeq ($(PKG_PLATFORM),darwin)
 PCFLAGS = -traditional-cpp $(GCCFLAGS)
Signature · 1 line
2.48.0
#6 lore raw

Re: [PATCH 2/7] builddefs: define linux

Quoted 9 lines · Darrick J. Wong
Quoted 3 lines · Eric Sandeen

There are several #ifdef linux guards in the code, but nothing defined it. This caused several sparse warnings, so define it when building on linux.

cpp in gcc 12.2 defines this:

$ touch /tmp/moo.h ; cpp -dM /tmp/moo.h | grep define.linux
#define linux 1

Huh, on my test box too.
And yet without this sparse coughs up lots of things for me:

tlibio.c:90:20: error: undefined identifier 'LIO_IO_TYPES' tlibio.c:90:33: error: undefined identifier 'LIO_WAIT_TYPES' tlibio.c:92:20: error: undefined identifier 'LIO_IO_TYPES' tlibio.c:92:33: error: undefined identifier 'LIO_WAIT_TYPES' tlibio.c:118:20: error: undefined identifier 'LIO_IO_TYPES' tlibio.c:118:33: error: undefined identifier 'LIO_WAIT_TYPES'

because i.e.:

#ifdef linux
#define LIO_IO_TYPES 00021 /* all io types */
#endif /* linux */

make V=1 shows:

/bin/sh ../libtool --quiet --tag=CC --mode=compile gcc -g -O2 -g -O2 -DDEBUG -I../include -DVERSION=\"1.1.1\" -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -funsigned-char -fno-strict-aliasing -Wall -c tlibio.c

so not sure what's going on here ?

Quoted 25 lines

--D

Quoted 22 lines
---
 include/builddefs.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/builddefs.in +1 -1
index 7274cde8..00dec0ea 100644
@@ -78,7 +78,7 @@ HAVE_FICLONE = @have_ficlone@
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall
 
 ifeq ($(PKG_PLATFORM),linux)
-PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $(GCCFLAGS)
+PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -Dlinux $(GCCFLAGS)
 endif
 ifeq ($(PKG_PLATFORM),darwin)
 PCFLAGS = -traditional-cpp $(GCCFLAGS)
Signature · 1 line
2.48.0
#7 lore raw

Re: [PATCH 2/7] builddefs: define linux

Quoted 27 lines · Eric Sandeen
Quoted 9 lines · Darrick J. Wong
Quoted 3 lines · Eric Sandeen

There are several #ifdef linux guards in the code, but nothing defined it. This caused several sparse warnings, so define it when building on linux.

cpp in gcc 12.2 defines this:

$ touch /tmp/moo.h ; cpp -dM /tmp/moo.h | grep define.linux
#define linux 1

Huh, on my test box too.
And yet without this sparse coughs up lots of things for me:

tlibio.c:90:20: error: undefined identifier 'LIO_IO_TYPES' tlibio.c:90:33: error: undefined identifier 'LIO_WAIT_TYPES' tlibio.c:92:20: error: undefined identifier 'LIO_IO_TYPES' tlibio.c:92:33: error: undefined identifier 'LIO_WAIT_TYPES' tlibio.c:118:20: error: undefined identifier 'LIO_IO_TYPES' tlibio.c:118:33: error: undefined identifier 'LIO_WAIT_TYPES'

because i.e.:

#ifdef linux
#define LIO_IO_TYPES 00021 /* all io types */
#endif /* linux */

Quoted 5 lines

make V=1 shows:

/bin/sh ../libtool --quiet --tag=CC --mode=compile gcc -g -O2 -g -O2 -DDEBUG -I../include -DVERSION=\"1.1.1\" -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -funsigned-char -fno-strict-aliasing -Wall -c tlibio.c

so not sure what's going on here ?

sparse doesn't define linux by default:

$ cat > /tmp/a.c << ENDL
#ifdef linux
# warning not
#else
# warning me
#endif
ENDL
$ gcc -o /tmp/a.o /tmp/a.c
/tmp/a.c:2:3: warning: #warning not [-Wcpp]
    2 | # warning not
      |   ^~~~~~~
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
$ sparse /tmp/a.c
/tmp/a.c:4:3: warning: me
$ sparse /tmp/a.c -Dlinux
/tmp/a.c:2:3: warning: not

--D

Quoted 27 lines
Quoted 26 lines

--D

Quoted 22 lines
---
 include/builddefs.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/builddefs.in +1 -1
index 7274cde8..00dec0ea 100644
@@ -78,7 +78,7 @@ HAVE_FICLONE = @have_ficlone@
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall
 
 ifeq ($(PKG_PLATFORM),linux)
-PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $(GCCFLAGS)
+PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -Dlinux $(GCCFLAGS)
 endif
 ifeq ($(PKG_PLATFORM),darwin)
 PCFLAGS = -traditional-cpp $(GCCFLAGS)
Signature · 1 line
2.48.0
#8 lore raw

Re: [PATCH 2/7] builddefs: define linux

Quoted 1 line · Darrick J. Wong

sparse doesn't define linux by default:

Does it define __linux__? That's really the preferred version these days and we should probably switch over to that.

#9 lore raw

Re: [PATCH 2/7] builddefs: define linux

Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Darrick J. Wong

sparse doesn't define linux by default:

Does it define __linux__? That's really the preferred version these days and we should probably switch over to that.

It seems to do so, yes.

--D

#10 lore raw

PATCH 3/7 lib: Fix non-ANSI function declarations

In reply to Eric Sandeen

lib/ was full of non-ANSI function declarations, fix them to make sparse happier.

---
 lib/dataascii.c    | 59 +++++++++++++++++++++-----------------------
 lib/databin.c      | 28 ++++++++++-----------
 lib/datapid.c      | 32 +++++++++---------------
 lib/file_lock.c    | 12 ++-------
 lib/forker.c       | 19 ++++++---------
 lib/pattern.c      | 14 ++---------
 lib/random_range.c | 61 ++++++++++++++--------------------------------
 lib/str_to_bytes.c |  9 +++----
 lib/tlibio.c       | 50 ++++++++++++++++++-------------------
 lib/write_log.c    | 32 ++++++++----------------
 10 files changed, 119 insertions(+), 197 deletions(-)
lib/dataascii.c +28 -31
index e2509f8d..d11609ee 100644
@@ -17,18 +17,18 @@
 static char Errmsg[80];
 
 int
-dataasciigen(listofchars, buffer, bsize, offset)
-char *listofchars;	/* a null terminated list of characters */
-char *buffer;
-int bsize;
-int offset;
+dataasciigen(
+	char *listofchars,	/* a null terminated list of characters */
+	char *buffer,
+	int bsize,
+	int offset)
 {
-   int cnt;
-   int total;
-   int ind;	/* index into CHARS array */
-   char *chr;
-   int chars_size;
-   char *charlist;
+	int cnt;
+	int total;
+	int ind;	/* index into CHARS array */
+	char *chr;
+	int chars_size;
+	char *charlist;
 
 	chr=buffer;
 	total=offset+bsize;
@@ -52,19 +52,19 @@ int offset;
 }	/* end of dataasciigen */
 
 int
-dataasciichk(listofchars, buffer, bsize, offset, errmsg)
-char *listofchars;	/* a null terminated list of characters */
-char *buffer;
-int bsize;
-int offset;
-char **errmsg;
+dataasciichk(
+	char *listofchars,	/* a null terminated list of characters */
+	char *buffer,
+	int bsize,
+	int offset,
+	char **errmsg)
 {
-   int cnt;
-   int total;
-   int ind;	/* index into CHARS array */
-   char *chr;
-   int chars_size;
-   char *charlist;
+	int cnt;
+	int total;
+	int ind;	/* index into CHARS array */
+	char *chr;
+	int chars_size;
+	char *charlist;
 
 	chr=buffer;
 	total=offset+bsize;
@@ -104,15 +104,12 @@ char **errmsg;
  * main for doing unit testing
  ***********************************************************************/
 int
-main(ac, ag)
-int ac;
-char **ag;
+main(int ac, char **ag)
 {
-
-int size=1023;
-char *buffer;
-int ret;
-char *errmsg;
+    int size=1023;
+    char *buffer;
+    int ret;
+    char *errmsg;
 
     if ((buffer=(char *)malloc(size)) == NULL ) {
         perror("malloc");
lib/databin.c +13 -15
index 8a36dff3..000d0d1a 100644
@@ -16,13 +16,13 @@
 static char Errmsg[80];
 
 void
-databingen (mode, buffer, bsize, offset)
-int mode;	/* either a, c, r, o, z or C */
-unsigned char *buffer;	/* buffer pointer */
-int bsize;	/* size of buffer */
-int offset;	/* offset into the file where buffer starts */
+databingen(
+	int mode,	/* either a, c, r, o, z or C */
+	unsigned char *buffer,	/* buffer pointer */
+	int bsize,	/* size of buffer */
+	int offset)	/* offset into the file where buffer starts */
 {
-int ind;
+	int ind;
 
         switch (mode)
         {
@@ -63,12 +63,12 @@ int ind;
  *      < 0  : no error
  ***********************************************************************/
 int
-databinchk(mode, buffer, bsize, offset, errmsg)
-int mode;	/* either a, c, r, z, o, or C */
-unsigned char *buffer;	/* buffer pointer */
-int bsize;	/* size of buffer */
-int offset;	/* offset into the file where buffer starts */
-char **errmsg;
+databinchk(
+	int mode,	/* either a, c, r, z, o, or C */
+	unsigned char *buffer,	/* buffer pointer */
+	int bsize,	/* size of buffer */
+	int offset,	/* offset into the file where buffer starts */
+	char **errmsg)
 {
 	int cnt;
 	unsigned char *chr;
@@ -138,9 +138,7 @@ char **errmsg;
  * main for doing unit testing
  ***********************************************************************/
 int
-main(ac, ag)
-int ac;
-char **ag;
+main(int ac, char **ag)
 {
 
     int size=1023;
lib/datapid.c +11 -21
index 15af8871..6786323d 100644
@@ -57,15 +57,13 @@ static char Errmsg[80];
  * Thus, offset 8 is in middle of word 1
  ***********************************************************************/
 int
-datapidgen(pid, buffer, bsize, offset)
-int pid;
-char *buffer;
-int bsize;
-int offset;
+datapidgen(
+	int pid,
+	char *buffer,
+	int bsize,
+	int offset)
 {
 	return -1;	/* not support on non-64 bits word machines  */
-
-
 } 
 
 /***********************************************************************
@@ -73,12 +71,7 @@ int offset;
  *
  ***********************************************************************/
 int
-datapidchk(pid, buffer, bsize, offset, errmsg)
-int pid;
-char *buffer;
-int bsize;
-int offset;
-char **errmsg;
+datapidchk(int pid, char *buffer, int bsize, int offset, char **errmsg)
 {
     if ( errmsg != NULL ) {
         *errmsg = Errmsg;
@@ -94,15 +87,12 @@ char **errmsg;
  * main for doing unit testing
  ***********************************************************************/
 int
-main(ac, ag)
-int ac;
-char **ag;
+main( int ac, char **ag)
 {
-
-int size=1234;
-char *buffer;
-int ret;
-char *errmsg;
+    int size=1234;
+    char *buffer;
+    int ret;
+    char *errmsg;
 
     if ((buffer=(char *)malloc(size)) == NULL ) {
         perror("malloc");
lib/file_lock.c +2 -10
index f0791489..6d87e281 100644
@@ -34,10 +34,7 @@ static char errmsg[256];
  * It will loop if the LOCK_NB flags is NOT set.
  ***********************************************************************/
 int
-file_lock(fd, flags, errormsg)
-int fd;
-int flags;
-char **errormsg;
+file_lock(int fd, int flags, char **errormsg)
 {
         register int cmd, ret;
         struct flock flocks;
@@ -109,12 +106,7 @@ char **errormsg;
  * It will loop if the LOCK_NB flags is NOT set.
  ***********************************************************************/
 int
-record_lock(fd, flags, start, len, errormsg)
-int fd;
-int flags;
-int start;
-int len;
-char **errormsg;
+record_lock(int fd, int flags, int start, int len, char **errormsg)
 {
         register int cmd, ret;
         struct flock flocks;
lib/forker.c +8 -11
index 63d8fcdb..10920ddb 100644
@@ -105,8 +105,7 @@ int Forker_npids=0;             /* number of entries in Forker_pids */
  *  !0 : if fork failed, the return value will be the errno.
  ***********************************************************************/
 int
-background(prefix)
-char *prefix;
+background(char *prefix)
 {
   switch (fork()) {
   case -1:
@@ -131,12 +130,12 @@ char *prefix;
  * 
  ***********************************************************************/
 int
-forker(ncopies, mode, prefix)
-int ncopies;
-int mode;	/* 0 - all childern of parent, 1 - only 1 direct child */
-char *prefix;   /* if ! NULL, an message will be printed to stderr */
-		/* if fork fails.  The prefix (program name) will */
-	        /* preceed the message */
+forker(
+    int ncopies,
+    int mode,		/* 0: all childern of parent, 1: only 1 direct child */
+    char *prefix)   	/* if ! NULL, an message will be printed to stderr */
+			/* if fork fails.  The prefix (program name) will */
+			/* preceed the message */
 {
     int cnt;
     int pid;
@@ -210,9 +209,7 @@ char *prefix;   /* if ! NULL, an message will be printed to stderr */
  */
 
 int
-main(argc, argv)
-int argc;
-char **argv;
+main(int argc, char **argv)
 {
     int ncopies=1;
     int mode=0;
lib/pattern.c +2 -12
index d622b935..20bbdc97 100644
@@ -12,12 +12,7 @@
  */
 
 int
-pattern_check(buf, buflen, pat, patlen, patshift)
-char	*buf;
-int	buflen;
-char	*pat;
-int	patlen;
-int	patshift;
+pattern_check(char *buf, int buflen, char *pat, int patlen, int patshift)
 {
     int		nb, ncmp, nleft;
     char	*cp;
@@ -79,12 +74,7 @@ int	patshift;
 }
 
 int
-pattern_fill(buf, buflen, pat, patlen, patshift)
-char	*buf;
-int	buflen;
-char	*pat;
-int	patlen;
-int	patshift;
+pattern_fill(char *buf, int buflen, char *pat, int patlen, int patshift)
 {
     int		trans, ncopied, nleft;
     char	*cp;
lib/random_range.c +18 -43

125 lines not on this page · raw message

lib/str_to_bytes.c +3 -6
index 2f6b2b92..20cd2a0f 100644
@@ -42,8 +42,7 @@
 #define T_MULT	1099511627776	/* tera or 2^40 */
 
 int
-str_to_bytes(s)
-char    *s;
+str_to_bytes(char *s)
 {
     char    mult, junk;
     int	    nconv;
@@ -77,8 +76,7 @@ char    *s;
 }
 
 long
-str_to_lbytes(s)
-char    *s;
+str_to_lbytes(char *s)
 {
     char    mult, junk;
     long    nconv;
@@ -117,8 +115,7 @@ char    *s;
  */
 
 long long
-str_to_llbytes(s)
-char    *s;
+str_to_llbytes(char *s)
 {
     char    mult, junk;
     long    nconv;
lib/tlibio.c +24 -26

74 lines not on this page · raw message

lib/write_log.c +10 -22
index cdc72593..c82cc1f4 100644
@@ -87,10 +87,7 @@ static int	wlog_rec_unpack();
  */
 
 int
-wlog_open(wfile, trunc, mode)
-struct wlog_file	*wfile;
-int			trunc;
-int			mode;
+wlog_open(struct wlog_file *wfile, int trunc, int mode)
 {
 	int	omask, oflags;
 
@@ -138,8 +135,7 @@ int			mode;
  */
 
 int
-wlog_close(wfile)
-struct wlog_file	*wfile;
+wlog_close(struct wlog_file *wfile)
 {
 	close(wfile->w_afd);
 	close(wfile->w_rfd);
@@ -173,10 +169,7 @@ struct wlog_file	*wfile;
  */
 
 int
-wlog_record_write(wfile, wrec, offset)
-struct wlog_file	*wfile;
-struct wlog_rec		*wrec;
-long			offset;
+wlog_record_write(struct wlog_file *wfile, struct wlog_rec *wrec, long offset)
 {
     int		reclen;
     char	wbuf[WLOG_REC_MAX_SIZE + 2];
@@ -221,11 +214,11 @@ long			offset;
  */
 
 int
-wlog_scan_backward(wfile, nrecs, func, data)
-struct wlog_file	*wfile;
-int 			nrecs;
-int 			(*func)();
-long			data;
+wlog_scan_backward(
+	struct wlog_file	*wfile,
+	int 			nrecs,
+	int 			(*func)(),
+	long			data)
 {
 	int			fd, leftover, nbytes, offset, recnum, reclen;
 	char    		buf[BSIZE*32], *bufend, *cp, *bufstart;
@@ -351,10 +344,7 @@ long			data;
  */
 
 static int
-wlog_rec_pack(wrec, buf, flag)
-struct wlog_rec	*wrec;
-char		*buf;
-int             flag;
+wlog_rec_pack(struct wlog_rec *wrec, char *buf, int flag)
 {
 	char			*file, *host, *pattern;
 	struct wlog_rec_disk	*wrecd;
@@ -400,9 +390,7 @@ int             flag;
 }
 
 static int
-wlog_rec_unpack(wrec, buf)
-struct wlog_rec	*wrec;
-char		*buf;
+wlog_rec_unpack(struct wlog_rec *wrec, char *buf)
 {
 	char			*file, *host, *pattern;
 	struct wlog_rec_disk	*wrecd;
Signature · 1 line
2.48.0
Reviewed-by on v1 3/7
#11 lore raw

Re: [PATCH 3/7] lib: Fix non-ANSI function declarations

Quoted 4 lines · Eric Sandeen

lib/ was full of non-ANSI function declarations, fix them to make sparse happier.

K&R, you mean?

"databingen", hah.

--D

Quoted 656 lines
---
 lib/dataascii.c    | 59 +++++++++++++++++++++-----------------------
 lib/databin.c      | 28 ++++++++++-----------
 lib/datapid.c      | 32 +++++++++---------------
 lib/file_lock.c    | 12 ++-------
 lib/forker.c       | 19 ++++++---------
 lib/pattern.c      | 14 ++---------
 lib/random_range.c | 61 ++++++++++++++--------------------------------
 lib/str_to_bytes.c |  9 +++----
 lib/tlibio.c       | 50 ++++++++++++++++++-------------------
 lib/write_log.c    | 32 ++++++++----------------
 10 files changed, 119 insertions(+), 197 deletions(-)
lib/dataascii.c +28 -31
index e2509f8d..d11609ee 100644
@@ -17,18 +17,18 @@
 static char Errmsg[80];
 
 int
-dataasciigen(listofchars, buffer, bsize, offset)
-char *listofchars;	/* a null terminated list of characters */
-char *buffer;
-int bsize;
-int offset;
+dataasciigen(
+	char *listofchars,	/* a null terminated list of characters */
+	char *buffer,
+	int bsize,
+	int offset)
 {
-   int cnt;
-   int total;
-   int ind;	/* index into CHARS array */
-   char *chr;
-   int chars_size;
-   char *charlist;
+	int cnt;
+	int total;
+	int ind;	/* index into CHARS array */
+	char *chr;
+	int chars_size;
+	char *charlist;
 
 	chr=buffer;
 	total=offset+bsize;
@@ -52,19 +52,19 @@ int offset;
 }	/* end of dataasciigen */
 
 int
-dataasciichk(listofchars, buffer, bsize, offset, errmsg)
-char *listofchars;	/* a null terminated list of characters */
-char *buffer;
-int bsize;
-int offset;
-char **errmsg;
+dataasciichk(
+	char *listofchars,	/* a null terminated list of characters */
+	char *buffer,
+	int bsize,
+	int offset,
+	char **errmsg)
 {
-   int cnt;
-   int total;
-   int ind;	/* index into CHARS array */
-   char *chr;
-   int chars_size;
-   char *charlist;
+	int cnt;
+	int total;
+	int ind;	/* index into CHARS array */
+	char *chr;
+	int chars_size;
+	char *charlist;
 
 	chr=buffer;
 	total=offset+bsize;
@@ -104,15 +104,12 @@ char **errmsg;
  * main for doing unit testing
  ***********************************************************************/
 int
-main(ac, ag)
-int ac;
-char **ag;
+main(int ac, char **ag)
 {
-
-int size=1023;
-char *buffer;
-int ret;
-char *errmsg;
+    int size=1023;
+    char *buffer;
+    int ret;
+    char *errmsg;
 
     if ((buffer=(char *)malloc(size)) == NULL ) {
         perror("malloc");
lib/databin.c +13 -15
index 8a36dff3..000d0d1a 100644
@@ -16,13 +16,13 @@
 static char Errmsg[80];
 
 void
-databingen (mode, buffer, bsize, offset)
-int mode;	/* either a, c, r, o, z or C */
-unsigned char *buffer;	/* buffer pointer */
-int bsize;	/* size of buffer */
-int offset;	/* offset into the file where buffer starts */
+databingen(
+	int mode,	/* either a, c, r, o, z or C */
+	unsigned char *buffer,	/* buffer pointer */
+	int bsize,	/* size of buffer */
+	int offset)	/* offset into the file where buffer starts */
 {
-int ind;
+	int ind;
 
         switch (mode)
         {
@@ -63,12 +63,12 @@ int ind;
  *      < 0  : no error
  ***********************************************************************/
 int
-databinchk(mode, buffer, bsize, offset, errmsg)
-int mode;	/* either a, c, r, z, o, or C */
-unsigned char *buffer;	/* buffer pointer */
-int bsize;	/* size of buffer */
-int offset;	/* offset into the file where buffer starts */
-char **errmsg;
+databinchk(
+	int mode,	/* either a, c, r, z, o, or C */
+	unsigned char *buffer,	/* buffer pointer */
+	int bsize,	/* size of buffer */
+	int offset,	/* offset into the file where buffer starts */
+	char **errmsg)
 {
 	int cnt;
 	unsigned char *chr;
@@ -138,9 +138,7 @@ char **errmsg;
  * main for doing unit testing
  ***********************************************************************/
 int
-main(ac, ag)
-int ac;
-char **ag;
+main(int ac, char **ag)
 {
 
     int size=1023;
lib/datapid.c +11 -21
index 15af8871..6786323d 100644
@@ -57,15 +57,13 @@ static char Errmsg[80];
  * Thus, offset 8 is in middle of word 1
  ***********************************************************************/
 int
-datapidgen(pid, buffer, bsize, offset)
-int pid;
-char *buffer;
-int bsize;
-int offset;
+datapidgen(
+	int pid,
+	char *buffer,
+	int bsize,
+	int offset)
 {
 	return -1;	/* not support on non-64 bits word machines  */
-
-
 } 
 
 /***********************************************************************
@@ -73,12 +71,7 @@ int offset;
  *
  ***********************************************************************/
 int
-datapidchk(pid, buffer, bsize, offset, errmsg)
-int pid;
-char *buffer;
-int bsize;
-int offset;
-char **errmsg;
+datapidchk(int pid, char *buffer, int bsize, int offset, char **errmsg)
 {
     if ( errmsg != NULL ) {
         *errmsg = Errmsg;
@@ -94,15 +87,12 @@ char **errmsg;
  * main for doing unit testing
  ***********************************************************************/
 int
-main(ac, ag)
-int ac;
-char **ag;
+main( int ac, char **ag)
 {
-
-int size=1234;
-char *buffer;
-int ret;
-char *errmsg;
+    int size=1234;
+    char *buffer;
+    int ret;
+    char *errmsg;
 
     if ((buffer=(char *)malloc(size)) == NULL ) {
         perror("malloc");
lib/file_lock.c +2 -10
index f0791489..6d87e281 100644
@@ -34,10 +34,7 @@ static char errmsg[256];
  * It will loop if the LOCK_NB flags is NOT set.
  ***********************************************************************/
 int
-file_lock(fd, flags, errormsg)
-int fd;
-int flags;
-char **errormsg;
+file_lock(int fd, int flags, char **errormsg)
 {
         register int cmd, ret;
         struct flock flocks;
@@ -109,12 +106,7 @@ char **errormsg;
  * It will loop if the LOCK_NB flags is NOT set.
  ***********************************************************************/
 int
-record_lock(fd, flags, start, len, errormsg)
-int fd;
-int flags;
-int start;
-int len;
-char **errormsg;
+record_lock(int fd, int flags, int start, int len, char **errormsg)
 {
         register int cmd, ret;
         struct flock flocks;
lib/forker.c +8 -11
index 63d8fcdb..10920ddb 100644
@@ -105,8 +105,7 @@ int Forker_npids=0;             /* number of entries in Forker_pids */
  *  !0 : if fork failed, the return value will be the errno.
  ***********************************************************************/
 int
-background(prefix)
-char *prefix;
+background(char *prefix)
 {
   switch (fork()) {
   case -1:
@@ -131,12 +130,12 @@ char *prefix;
  * 
  ***********************************************************************/
 int
-forker(ncopies, mode, prefix)
-int ncopies;
-int mode;	/* 0 - all childern of parent, 1 - only 1 direct child */
-char *prefix;   /* if ! NULL, an message will be printed to stderr */
-		/* if fork fails.  The prefix (program name) will */
-	        /* preceed the message */
+forker(
+    int ncopies,
+    int mode,		/* 0: all childern of parent, 1: only 1 direct child */
+    char *prefix)   	/* if ! NULL, an message will be printed to stderr */
+			/* if fork fails.  The prefix (program name) will */
+			/* preceed the message */
 {
     int cnt;
     int pid;
@@ -210,9 +209,7 @@ char *prefix;   /* if ! NULL, an message will be printed to stderr */
  */
 
 int
-main(argc, argv)
-int argc;
-char **argv;
+main(int argc, char **argv)
 {
     int ncopies=1;
     int mode=0;
lib/pattern.c +2 -12
index d622b935..20bbdc97 100644
@@ -12,12 +12,7 @@
  */
 
 int
-pattern_check(buf, buflen, pat, patlen, patshift)
-char	*buf;
-int	buflen;
-char	*pat;
-int	patlen;
-int	patshift;
+pattern_check(char *buf, int buflen, char *pat, int patlen, int patshift)
 {
     int		nb, ncmp, nleft;
     char	*cp;
@@ -79,12 +74,7 @@ int	patshift;
 }
 
 int
-pattern_fill(buf, buflen, pat, patlen, patshift)
-char	*buf;
-int	buflen;
-char	*pat;
-int	patlen;
-int	patshift;
+pattern_fill(char *buf, int buflen, char *pat, int patlen, int patshift)
 {
     int		trans, ncopied, nleft;
     char	*cp;
lib/random_range.c +18 -43
index 3fa01f0d..680bf71c 100644
@@ -73,14 +73,14 @@ static int       str_to_int();
 static long long divider(long long, long long, long long, long long);
 
 int
-parse_ranges(str, defmin, defmax, defmult, parse_func, rangeptr, errptr)
-char	*str;
-int	defmin;
-int	defmax;
-int	defmult;
-int	(*parse_func)();
-char	**rangeptr;
-char	**errptr;
+parse_ranges(
+	char *str,
+	int defmin,
+	int defmax,
+	int defmult,
+	int (*parse_func)(),
+	char **rangeptr,
+	char **errptr)
 {
 	int		ncommas;
 	char		*tmpstr, *cp, *tok, *n1str, *n2str, *multstr;
@@ -194,9 +194,7 @@ char	**errptr;
  */
 
 static int
-str_to_int(str, ip)
-char	*str;
-int	*ip;
+str_to_int(char *str, int *ip)
 {
 	char	c;
 
@@ -214,25 +212,19 @@ int	*ip;
  */
 
 int
-range_min(rbuf, r)
-char	*rbuf;
-int	r;
+range_min(char *rbuf, int r)
 {
 	return ((struct range *)rbuf)[r].min;
 }
 
 int
-range_max(rbuf, r)
-char	*rbuf;
-int	r;
+range_max(char *rbuf, int r)
 {
 	return ((struct range *)rbuf)[r].max;
 }
 
 int
-range_mult(rbuf, r)
-char	*rbuf;
-int	r;
+range_mult(char *rbuf, int r)
 {
 	return ((struct range *)rbuf)[r].mult;
 }
@@ -263,11 +255,7 @@ int	r;
  *****************************************************************************/
 
 long
-random_range(min, max, mult, errp)
-int	min;
-int	max;
-int	mult;
-char	**errp;
+random_range(int min, int max, int mult, char **errp)
 {
 	int     	r, nmults, orig_min, orig_max, orig_mult, tmp;
 	extern long	lrand48();
@@ -333,11 +321,7 @@ char	**errp;
  * Just like random_range, but all values are longs.
  */
 long
-random_rangel(min, max, mult, errp)
-long	min;
-long	max;
-long	mult;
-char	**errp;
+random_range1(long min, long max, long mult, char **errp)
 {
 	long     	r, nmults, orig_min, orig_max, orig_mult, tmp;
 	extern long	lrand48();
@@ -424,11 +408,7 @@ char	**errp;
  *  Attempts to be just like random_range, but everything is long long (64 bit)
  */
 long long
-random_rangell(min, max, mult, errp)
-long long	min;
-long long	max;
-long long	mult;
-char		**errp;
+random_rangell(long long min, long long max, long long mult, char **errp)
 {
 	long long     	r, nmults, orig_min, orig_max, orig_mult, tmp;
         long long	randnum;
@@ -588,8 +568,7 @@ printf("   diff = %lld, half = %lld,   med = %lld\n", diff, half, med);
  *****************************************************************************/
 
 void
-random_range_seed(s)
-long    s;
+random_range_seed(long s)
 {
     extern void srand48();
 
@@ -652,9 +631,7 @@ random_bit(long mask)
 /*
  *  The following is a unit test main function for random_bit().
  */
-main(argc, argv)
-int argc;
-char **argv;
+main(int argc, char **argv)
 {
     int ind;
     int cnt, iter;
@@ -695,9 +672,7 @@ char **argv;
 #define MEG  1024*1024*1024
 #define GIG 1073741824
 int
-main(argc, argv)
-int argc;
-char **argv;
+main(int argc, char **argv)
 {
     int ind;
     int cnt, iter=10;
lib/str_to_bytes.c +3 -6
index 2f6b2b92..20cd2a0f 100644
@@ -42,8 +42,7 @@
 #define T_MULT	1099511627776	/* tera or 2^40 */
 
 int
-str_to_bytes(s)
-char    *s;
+str_to_bytes(char *s)
 {
     char    mult, junk;
     int	    nconv;
@@ -77,8 +76,7 @@ char    *s;
 }
 
 long
-str_to_lbytes(s)
-char    *s;
+str_to_lbytes(char *s)
 {
     char    mult, junk;
     long    nconv;
@@ -117,8 +115,7 @@ char    *s;
  */
 
 long long
-str_to_llbytes(s)
-char    *s;
+str_to_llbytes(char *s)
 {
     char    mult, junk;
     long    nconv;
lib/tlibio.c +24 -26
index f7259734..3c23bf4d 100644
@@ -143,13 +143,13 @@ static int Debug_level = 0;
  ***********************************************************************/
 
 int
-stride_bounds(offset, stride, nstrides, bytes_per_stride, min, max)
-int	offset;
-int	stride;
-int	nstrides;
-int	bytes_per_stride;
-int	*min;
-int	*max;
+stride_bounds(
+	int offset,
+	int stride,
+	int nstrides,
+	int bytes_per_stride,
+	int *min,
+	int *max)
 {
 	int	nbytes, min_byte, max_byte;
 
@@ -443,14 +443,14 @@ lio_random_methods(long curr_mask)
  * (rrl 04/96)
  ***********************************************************************/
 int
-lio_write_buffer(fd, method, buffer, size, sig, errmsg, wrd)
-int fd;		/* open file descriptor */
-int method;	/* contains io type and wait method bitmask */
-char *buffer;	/* pointer to buffer */
-int size;	/* the size of the io */
-int sig;	/* signal to use if async io */
-char **errmsg;	/* char pointer that will be updated to point to err message */
-long wrd;	/* to allow future features, use zero for now */
+lio_write_buffer(
+    int fd,		/* open file descriptor */
+    int method,		/* contains io type and wait method bitmask */
+    char *buffer,	/* pointer to buffer */
+    int size,		/* the size of the io */
+    int sig,		/* signal to use if async io */
+    char **errmsg,	/* char pointer that will be updated to point to err message */
+    long wrd)		/* to allow future features, use zero for now */
 {
     int ret = 0;	/* syscall return or used to get random method */
 #ifndef linux
@@ -640,14 +640,14 @@ long wrd;	/* to allow future features, use zero for now */
  * (rrl 04/96)
  ***********************************************************************/
 int
-lio_read_buffer(fd, method, buffer, size, sig, errmsg, wrd)
-int fd;		/* open file descriptor */
-int method;	/* contains io type and wait method bitmask */
-char *buffer;	/* pointer to buffer */
-int size;	/* the size of the io */
-int sig;	/* signal to use if async io */
-char **errmsg;	/* char pointer that will be updated to point to err message */
-long wrd;	/* to allow future features, use zero for now */
+lio_read_buffer(
+    int fd,		/* open file descriptor */
+    int method,		/* contains io type and wait method bitmask */
+    char *buffer,	/* pointer to buffer */
+    int size,		/* the size of the io */
+    int sig,		/* signal to use if async io */
+    char **errmsg,	/* char pointer that will be updated to point to err message */
+    long wrd)		/* to allow future features, use zero for now */
 {
     int ret = 0;	/* syscall return or used to get random method */
 #ifndef linux
@@ -1031,9 +1031,7 @@ struct unit_info_t {
 };
 
 int
-main(argc, argv)
-int argc;
-char **argv;
+main(int argc, char **argv)
 {
     extern char *optarg;
     extern int optind;
lib/write_log.c +10 -22
index cdc72593..c82cc1f4 100644
@@ -87,10 +87,7 @@ static int	wlog_rec_unpack();
  */
 
 int
-wlog_open(wfile, trunc, mode)
-struct wlog_file	*wfile;
-int			trunc;
-int			mode;
+wlog_open(struct wlog_file *wfile, int trunc, int mode)
 {
 	int	omask, oflags;
 
@@ -138,8 +135,7 @@ int			mode;
  */
 
 int
-wlog_close(wfile)
-struct wlog_file	*wfile;
+wlog_close(struct wlog_file *wfile)
 {
 	close(wfile->w_afd);
 	close(wfile->w_rfd);
@@ -173,10 +169,7 @@ struct wlog_file	*wfile;
  */
 
 int
-wlog_record_write(wfile, wrec, offset)
-struct wlog_file	*wfile;
-struct wlog_rec		*wrec;
-long			offset;
+wlog_record_write(struct wlog_file *wfile, struct wlog_rec *wrec, long offset)
 {
     int		reclen;
     char	wbuf[WLOG_REC_MAX_SIZE + 2];
@@ -221,11 +214,11 @@ long			offset;
  */
 
 int
-wlog_scan_backward(wfile, nrecs, func, data)
-struct wlog_file	*wfile;
-int 			nrecs;
-int 			(*func)();
-long			data;
+wlog_scan_backward(
+	struct wlog_file	*wfile,
+	int 			nrecs,
+	int 			(*func)(),
+	long			data)
 {
 	int			fd, leftover, nbytes, offset, recnum, reclen;
 	char    		buf[BSIZE*32], *bufend, *cp, *bufstart;
@@ -351,10 +344,7 @@ long			data;
  */
 
 static int
-wlog_rec_pack(wrec, buf, flag)
-struct wlog_rec	*wrec;
-char		*buf;
-int             flag;
+wlog_rec_pack(struct wlog_rec *wrec, char *buf, int flag)
 {
 	char			*file, *host, *pattern;
 	struct wlog_rec_disk	*wrecd;
@@ -400,9 +390,7 @@ int             flag;
 }
 
 static int
-wlog_rec_unpack(wrec, buf)
-struct wlog_rec	*wrec;
-char		*buf;
+wlog_rec_unpack(struct wlog_rec *wrec, char *buf)
 {
 	char			*file, *host, *pattern;
 	struct wlog_rec_disk	*wrecd;
Signature · 1 line
2.48.0
Reviewed-by on v1 3/7
#12 lore raw

Re: [PATCH 3/7] lib: Fix non-ANSI function declarations

In reply to Eric Sandeen
Quoted 2 lines · Eric Sandeen

lib/ was full of non-ANSI function declarations, fix them to make sparse happier.

Oh fun. Great to get this fixed up.

The path also seems to have a few formatting fixups in the area, but I'm not going to nitpick on this code..

#13 lore raw

PATCH 4/7 lib: fix empty arg function prototypes

In reply to Eric Sandeen

Several function prototypes used () when in fact they take arguments. Fix those to make sparse happy.

---
 include/random_range.h | 2 +-
 include/write_log.h    | 2 +-
 lib/random_range.c     | 6 ++----
 lib/string_to_tokens.c | 1 -
 lib/tlibio.c           | 2 +-
 lib/write_log.c        | 2 +-
 6 files changed, 6 insertions(+), 9 deletions(-)
include/random_range.h +1 -1
index b47aef9e..c352c5a9 100644
@@ -6,7 +6,7 @@
 #ifndef _RANDOM_RANGE_H_
 #define _RANDOM_RANGE_H_
 
-int       parse_ranges     ( char *, int, int, int, int (*)(), char **, char ** );
+int       parse_ranges     ( char *, int, int, int, int (*)(char *, int *), char **, char ** );
 int       range_min        ( char *, int );
 int       range_max        ( char *, int );
 int       range_mult       ( char *, int );
include/write_log.h +1 -1
index 025ebac0..d02f898a 100644
@@ -125,7 +125,7 @@ extern int	wlog_close(struct wlog_file *wfile);
 extern int	wlog_record_write(struct wlog_file *wfile,
 				  struct wlog_rec *wrec, long offset);
 extern int	wlog_scan_backward(struct wlog_file *wfile, int nrecs,
-				   int (*func)(struct wlog_rec *rec),
+				   int (*func)(struct wlog_rec *rec, long data),
 				   long data);
 #else
 int	wlog_open();
lib/random_range.c +2 -4
index 680bf71c..0b38eb7f 100644
@@ -69,7 +69,7 @@ struct range {
  * parse_range() returns -1 on error, or the number of ranges parsed.
  */
 
-static int       str_to_int();
+static int       str_to_int(char *str, int *ip);
 static long long divider(long long, long long, long long, long long);
 
 int
@@ -78,7 +78,7 @@ parse_ranges(
 	int defmin,
 	int defmax,
 	int defmult,
-	int (*parse_func)(),
+	int (*parse_func)(char *str, int *ip),
 	char **rangeptr,
 	char **errptr)
 {
@@ -570,8 +570,6 @@ printf("   diff = %lld, half = %lld,   med = %lld\n", diff, half, med);
 void
 random_range_seed(long s)
 {
-    extern void srand48();
-
     srand48(s);
 }
 
lib/string_to_tokens.c +0 -1
index 08df9fcc..8383ed4c 100644
@@ -54,7 +54,6 @@ int
 string_to_tokens(char *arg_string, char *arg_array[], int array_size, char *separator)
 {
    int num_toks = 0;  /* number of tokens found */
-   char *strtok();
 	
    if ( arg_array == NULL || array_size <= 1 || separator == NULL )
 	return -1;
lib/tlibio.c +1 -1
index 3c23bf4d..19192b38 100644
@@ -75,7 +75,7 @@
 
 
 #ifndef linux
-static void lio_async_signal_handler();
+static void lio_async_signal_handler(int sig);
 #endif
 
 /*
lib/write_log.c +1 -1
index c82cc1f4..e04fed4b 100644
@@ -217,7 +217,7 @@ int
 wlog_scan_backward(
 	struct wlog_file	*wfile,
 	int 			nrecs,
-	int 			(*func)(),
+	int 			(*func)(struct wlog_rec *, long data),
 	long			data)
 {
 	int			fd, leftover, nbytes, offset, recnum, reclen;
Signature · 1 line
2.48.0
Reviewed-by on v1 4/7
#14 lore raw

Re: [PATCH 4/7] lib: fix empty arg function prototypes

Quoted 31 lines · Eric Sandeen

Several function prototypes used () when in fact they take arguments. Fix those to make sparse happy.

---
 include/random_range.h | 2 +-
 include/write_log.h    | 2 +-
 lib/random_range.c     | 6 ++----
 lib/string_to_tokens.c | 1 -
 lib/tlibio.c           | 2 +-
 lib/write_log.c        | 2 +-
 6 files changed, 6 insertions(+), 9 deletions(-)
include/random_range.h +1 -1
index b47aef9e..c352c5a9 100644
@@ -6,7 +6,7 @@
 #ifndef _RANDOM_RANGE_H_
 #define _RANDOM_RANGE_H_
 
-int       parse_ranges     ( char *, int, int, int, int (*)(), char **, char ** );
+int       parse_ranges     ( char *, int, int, int, int (*)(char *, int *), char **, char ** );
 int       range_min        ( char *, int );
 int       range_max        ( char *, int );
 int       range_mult       ( char *, int );
include/write_log.h +0 -0
index 025ebac0..d02f898a 100644

include/write_log.h extern int wlog_close(struct wlog_file *wfile); · line 128

Quoted 5 lines
include/write_log.h +1 -1
@@ -125,7 +125,7 @@ extern int	wlog_close(struct wlog_file *wfile);
 extern int	wlog_record_write(struct wlog_file *wfile,
 				  struct wlog_rec *wrec, long offset);
 extern int	wlog_scan_backward(struct wlog_file *wfile, int nrecs,
-				   int (*func)(struct wlog_rec *rec),
+				   int (*func)(struct wlog_rec *rec, long data),

This is a very similar version to what's in testcases/kernel/fs/doio/write_log.c in the LTP source.

Maybe it's time to clean up both versions?

--D

Quoted 76 lines
include/write_log.h +0 -0
 				   long data);
 #else
 int	wlog_open();
lib/random_range.c +2 -4
index 680bf71c..0b38eb7f 100644
@@ -69,7 +69,7 @@ struct range {
  * parse_range() returns -1 on error, or the number of ranges parsed.
  */
 
-static int       str_to_int();
+static int       str_to_int(char *str, int *ip);
 static long long divider(long long, long long, long long, long long);
 
 int
@@ -78,7 +78,7 @@ parse_ranges(
 	int defmin,
 	int defmax,
 	int defmult,
-	int (*parse_func)(),
+	int (*parse_func)(char *str, int *ip),
 	char **rangeptr,
 	char **errptr)
 {
@@ -570,8 +570,6 @@ printf("   diff = %lld, half = %lld,   med = %lld\n", diff, half, med);
 void
 random_range_seed(long s)
 {
-    extern void srand48();
-
     srand48(s);
 }
 
lib/string_to_tokens.c +0 -1
index 08df9fcc..8383ed4c 100644
@@ -54,7 +54,6 @@ int
 string_to_tokens(char *arg_string, char *arg_array[], int array_size, char *separator)
 {
    int num_toks = 0;  /* number of tokens found */
-   char *strtok();
 
    if ( arg_array == NULL || array_size <= 1 || separator == NULL )
 	return -1;
lib/tlibio.c +1 -1
index 3c23bf4d..19192b38 100644
@@ -75,7 +75,7 @@
 
 
 #ifndef linux
-static void lio_async_signal_handler();
+static void lio_async_signal_handler(int sig);
 #endif
 
 /*
lib/write_log.c +1 -1
index c82cc1f4..e04fed4b 100644
@@ -217,7 +217,7 @@ int
 wlog_scan_backward(
 	struct wlog_file	*wfile,
 	int 			nrecs,
-	int 			(*func)(),
+	int 			(*func)(struct wlog_rec *, long data),
 	long			data)
 {
 	int			fd, leftover, nbytes, offset, recnum, reclen;
Signature · 1 line
2.48.0
#16 lore raw

PATCH 5/7 lib: replace aiocb_t with struct aiocb

In reply to Eric Sandeen

aiocb_t isn't defined anywhere, use struct aiocb instead, to make sparse happy.

---
 lib/tlibio.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
lib/tlibio.c +5 -3
index 19192b38..22ff1adc 100644
@@ -42,6 +42,7 @@
  *
  */
 
+#include <aio.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <fcntl.h>
@@ -810,7 +811,7 @@ lio_read_buffer(
  * (rrl 04/96)
  ***********************************************************************/
 int
-lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method)
+lio_check_asyncio(char *io_type, int size, const struct aiocb *aiocbp, int method)
 {
     int ret;
     int cnt = 1;
@@ -895,9 +896,10 @@ lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method)
  * (rrl 04/96)
  ***********************************************************************/
 int
-lio_wait4asyncio(int method, int fd, aiocb_t *aiocbp)
+lio_wait4asyncio(int method, int fd, const struct aiocb *aiocbp)
 {
-    int cnt;
+    struct aiocb *const aioary[1];
+    int cnt, ret;
 
     if ( (method & LIO_WAIT_RECALL)
 	|| ((method & LIO_WAIT_TYPES) == 0) ){
Signature · 1 line
2.48.0
Reviewed-by on v1 5/7
#17 lore raw

Re: [PATCH 5/7] lib: replace aiocb_t with struct aiocb

Quoted 4 lines · Eric Sandeen

aiocb_t isn't defined anywhere, use struct aiocb instead, to make sparse happy.

libaio<shudder>

--D

Quoted 42 lines
---
 lib/tlibio.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
lib/tlibio.c +5 -3
index 19192b38..22ff1adc 100644
@@ -42,6 +42,7 @@
  *
  */
 
+#include <aio.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <fcntl.h>
@@ -810,7 +811,7 @@ lio_read_buffer(
  * (rrl 04/96)
  ***********************************************************************/
 int
-lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method)
+lio_check_asyncio(char *io_type, int size, const struct aiocb *aiocbp, int method)
 {
     int ret;
     int cnt = 1;
@@ -895,9 +896,10 @@ lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method)
  * (rrl 04/96)
  ***********************************************************************/
 int
-lio_wait4asyncio(int method, int fd, aiocb_t *aiocbp)
+lio_wait4asyncio(int method, int fd, const struct aiocb *aiocbp)
 {
-    int cnt;
+    struct aiocb *const aioary[1];
+    int cnt, ret;
 
     if ( (method & LIO_WAIT_RECALL)
 	|| ((method & LIO_WAIT_TYPES) == 0) ){
Signature · 1 line
2.48.0
#19 lore raw

PATCH 6/7 lib: make a few symbols static

In reply to Eric Sandeen

There are a few symbols in lib/tlibio.c which should be static, and sparse notices this so fix it.

---
 lib/tlibio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/tlibio.c +3 -1
index 22ff1adc..2aa8175b 100644
@@ -82,6 +82,7 @@ static void lio_async_signal_handler(int sig);
 /*
  * Define the structure as used in lio_parse_arg1 and lio_help1
  */
+static
 struct lio_info_type  Lio_info1[] = {
     { "s", LIO_IO_SYNC, "sync i/o" },
     { "p", LIO_IO_ASYNC|LIO_WAIT_SIGACTIVE, "async i/o using a loop to wait for a signal" },
@@ -101,6 +102,7 @@ struct lio_info_type  Lio_info1[] = {
 /*
  * Define the structure used by lio_parse_arg2 and lio_help2
  */
+static
 struct lio_info_type  Lio_info2[] = {
     { "sync",      LIO_IO_SYNC,		"sync i/o (read/write)"},
     { "async",     LIO_IO_ASYNC,	"async i/o (reada/writea/aio_read/aio_write)" },
@@ -120,7 +122,7 @@ struct lio_info_type  Lio_info2[] = {
 	"all random i/o types and wait methods (except nowait)" },
 };
 
-char Lio_SysCall[PATH_MAX];	/* string containing last i/o system call */
+static char Lio_SysCall[PATH_MAX];	/* string containing last i/o system call */
 
 static volatile int Received_signal = 0;	/* number of signals received */
 static volatile int Rec_signal;
Signature · 1 line
2.48.0
Reviewed-by on v1 6/7
#20 lore raw

Re: [PATCH 6/7] lib: make a few symbols static

Quoted 4 lines · Eric Sandeen

There are a few symbols in lib/tlibio.c which should be static, and sparse notices this so fix it.

Yep, that's pretty straightforward.

--D

Quoted 37 lines
---
 lib/tlibio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/tlibio.c +3 -1
index 22ff1adc..2aa8175b 100644
@@ -82,6 +82,7 @@ static void lio_async_signal_handler(int sig);
 /*
  * Define the structure as used in lio_parse_arg1 and lio_help1
  */
+static
 struct lio_info_type  Lio_info1[] = {
     { "s", LIO_IO_SYNC, "sync i/o" },
     { "p", LIO_IO_ASYNC|LIO_WAIT_SIGACTIVE, "async i/o using a loop to wait for a signal" },
@@ -101,6 +102,7 @@ struct lio_info_type  Lio_info1[] = {
 /*
  * Define the structure used by lio_parse_arg2 and lio_help2
  */
+static
 struct lio_info_type  Lio_info2[] = {
     { "sync",      LIO_IO_SYNC,		"sync i/o (read/write)"},
     { "async",     LIO_IO_ASYNC,	"async i/o (reada/writea/aio_read/aio_write)" },
@@ -120,7 +122,7 @@ struct lio_info_type  Lio_info2[] = {
 	"all random i/o types and wait methods (except nowait)" },
 };
 
-char Lio_SysCall[PATH_MAX];	/* string containing last i/o system call */
+static char Lio_SysCall[PATH_MAX];	/* string containing last i/o system call */
 
 static volatile int Received_signal = 0;	/* number of signals received */
 static volatile int Rec_signal;
Signature · 1 line
2.48.0
#22 lore raw

PATCH 7/7 lib: remove random.c

In reply to Eric Sandeen

sparse points out that lots of things in random.c could be static, and upon doing so we realize that nothing in this file is used. Which is unsurprising since these are all part of the standard C library ... so just remove the file.

---
 lib/Makefile |   5 +-
 lib/random.c | 224 ---------------------------------------------------
 2 files changed, 2 insertions(+), 227 deletions(-)
 delete mode 100644 lib/random.c
lib/Makefile +2 -3
index 53540ca7..ce4381a2 100644
@@ -11,13 +11,12 @@ LT_REVISION = 0
 LT_AGE = 0
 
 #
-# Everything (except for random.c) copied directly from LTP.
+# Everything copied directly from LTP.
 # Refer to http://ltp.sourceforge.net/ for complete source.
 #
 CFILES = dataascii.c databin.c datapid.c file_lock.c forker.c \
 	pattern.c open_flags.c random_range.c string_to_tokens.c \
-	str_to_bytes.c tlibio.c write_log.c \
-	random.c
+	str_to_bytes.c tlibio.c write_log.c
 
 default: depend $(LTLIBRARY)
 
lib/random.c deleted +0 -224

224 lines not on this page · raw message

Signature · 1 line
2.48.0
Reviewed-by on v1 7/7
#23 lore raw

Re: [PATCH 7/7] lib: remove random.c

Quoted 10 lines · Eric Sandeen

sparse points out that lots of things in random.c could be static, and upon doing so we realize that nothing in this file is used. Which is unsurprising since these are all part of the standard C library ... so just remove the file.

---
 lib/Makefile |   5 +-
 lib/random.c | 224 ---------------------------------------------------
 2 files changed, 2 insertions(+), 227 deletions(-)

Thus marks the return of Sandeen, Remover of Code!!

--D

Quoted 256 lines
 delete mode 100644 lib/random.c
lib/Makefile +2 -3
index 53540ca7..ce4381a2 100644
@@ -11,13 +11,12 @@ LT_REVISION = 0
 LT_AGE = 0
 
 #
-# Everything (except for random.c) copied directly from LTP.
+# Everything copied directly from LTP.
 # Refer to http://ltp.sourceforge.net/ for complete source.
 #
 CFILES = dataascii.c databin.c datapid.c file_lock.c forker.c \
 	pattern.c open_flags.c random_range.c string_to_tokens.c \
-	str_to_bytes.c tlibio.c write_log.c \
-	random.c
+	str_to_bytes.c tlibio.c write_log.c
 
 default: depend $(LTLIBRARY)
 
lib/random.c deleted +0 -224
deleted file mode 100644
index d5c81be8..00000000
@@ -1,224 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * random.c -- pseudo random number generator
- * Copyright (C) 1994  Chris Wallace ([email protected])
- */
-
-#include <sys/types.h>
-
-/*
- * modified by [email protected] so that this file acts as a drop in replacement
- * for srandom and random.
- */
-
-/*
- *	A random number generator called as a function by
- *	random (iseed)	or	irandm (iseed)
- *	The parameter should be a pointer to a 2-element int32_t vector.
- *	The first function returns a double uniform in 0 .. 1.
- *	The second returns a int32_t integer uniform in 0 .. 2**31-1
- *	Both update iseed[] in exactly the same way.
- *	iseed[] must be a 2-element integer vector.
- *	The initial value of the second element may be anything.
- *
- *	The period of the random sequence is 2**32 * (2**32-1)
- *	The table mt[0:127] is defined by mt[i] = 69069 ** (128-i)
- */
-
-#define MASK ((int32_t) 593970775)
-/*	or in hex, 23674657	*/
-
-#define SCALE ((double) 1.0 / (1024.0 * 1024.0 * 1024.0 * 2.0))
-/*	i.e. 2 to power -31	*/
-
-static int32_t mt [128] =   {
-      902906369,
-     2030498053,
-     -473499623,
-     1640834941,
-      723406961,
-     1993558325,
-     -257162999,
-    -1627724755,
-      913952737,
-      278845029,
-     1327502073,
-    -1261253155,
-      981676113,
-    -1785280363,
-     1700077033,
-      366908557,
-    -1514479167,
-     -682799163,
-      141955545,
-     -830150595,
-      317871153,
-     1542036469,
-     -946413879,
-    -1950779155,
-      985397153,
-      626515237,
-      530871481,
-      783087261,
-    -1512358895,
-     1031357269,
-    -2007710807,
-    -1652747955,
-    -1867214463,
-      928251525,
-     1243003801,
-    -2132510467,
-     1874683889,
-     -717013323,
-      218254473,
-    -1628774995,
-    -2064896159,
-       69678053,
-      281568889,
-    -2104168611,
-     -165128239,
-     1536495125,
-      -39650967,
-      546594317,
-     -725987007,
-     1392966981,
-     1044706649,
-      687331773,
-    -2051306575,
-     1544302965,
-     -758494647,
-    -1243934099,
-      -75073759,
-      293132965,
-    -1935153095,
-      118929437,
-      807830417,
-    -1416222507,
-    -1550074071,
-      -84903219,
-     1355292929,
-     -380482555,
-    -1818444007,
-     -204797315,
-      170442609,
-    -1636797387,
-      868931593,
-     -623503571,
-     1711722209,
-      381210981,
-     -161547783,
-     -272740131,
-    -1450066095,
-     2116588437,
-     1100682473,
-      358442893,
-    -1529216831,
-     2116152005,
-     -776333095,
-     1265240893,
-     -482278607,
-     1067190005,
-      333444553,
-       86502381,
-      753481377,
-       39000101,
-     1779014585,
-      219658653,
-     -920253679,
-     2029538901,
-     1207761577,
-    -1515772851,
-     -236195711,
-      442620293,
-      423166617,
-    -1763648515,
-     -398436623,
-    -1749358155,
-     -538598519,
-     -652439379,
-      430550625,
-    -1481396507,
-     2093206905,
-    -1934691747,
-     -962631983,
-     1454463253,
-    -1877118871,
-     -291917555,
-    -1711673279,
-      201201733,
-     -474645415,
-      -96764739,
-    -1587365199,
-     1945705589,
-     1303896393,
-     1744831853,
-      381957665,
-     2135332261,
-      -55996615,
-    -1190135011,
-     1790562961,
-    -1493191723,
-      475559465,
-          69069
-		};
-
-double 
-_random (int32_t is [2])
-{
-	int32_t it, leh, nit;
-
-	it = is [0];
-	leh = is [1];
-	if (it <= 0)	
-		it = (it + it) ^ MASK;
-	else
-		it = it + it;
-	nit = it - 1;
-/*	to ensure all-ones pattern omitted    */
-	leh = leh * mt[nit & 127] + nit;
-	is [0] = it;    is [1] = leh;
-	if (leh < 0) leh = ~leh;
-	return (SCALE * ((int32_t) (leh | 1)));
-}
-
-
-
-int32_t 
-_irandm (int32_t is [2])
-{
-	int32_t it, leh, nit;
-
-	it = is [0];
-	leh = is [1];
-	if (it <= 0)	
-		it = (it + it) ^ MASK;
-	else
-		it = it + it;
-	nit = it - 1;
-/*	to ensure all-ones pattern omitted    */
-	leh = leh * mt[nit & 127] + nit;
-	is [0] = it;    is [1] = leh;
-	if (leh < 0) leh = ~leh;
-	return (leh);
-}
-
-/*
- * make this a drop in replacement for random and srandom
- *
- * XXX not thread safe I guess.
- */
-
-static int32_t saved_seed[2];
-
-long random(void)
-{
-    return _irandm(saved_seed);
-}
-
-void srandom(unsigned seed)
-{
-    saved_seed[0]=seed;
-    saved_seed[1]=0;
-    _irandm(saved_seed);
-}
-
Signature · 1 line
2.48.0
Reviewed-by on v1 7/7
#24 lore raw

Re: [PATCH 7/7] lib: remove random.c

In reply to Eric Sandeen
Quoted 4 lines · Eric Sandeen

sparse points out that lots of things in random.c could be static, and upon doing so we realize that nothing in this file is used. Which is unsurprising since these are all part of the standard C library ... so just remove the file.

Heh.

Looks good: