[Patch V2 6/6] Staging: unisys: visorutil: Clean up sparse warnings in visorutil code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Clean up code to get rid of sparse warnings.

Also fixed variable length arrays declared on the stack by removing
visor_hexDumpToBuffer() and using hex_dump_to_buffer() instead.

Signed-off-by: Ken Cox <jkc@xxxxxxxxxx>
---
 drivers/staging/unisys/include/timskmodutils.h     | 22 ------
 .../unisys/visorchannel/visorchannel_funcs.c       | 15 ++--
 drivers/staging/unisys/visorutil/procobjecttree.c  |  2 +-
 drivers/staging/unisys/visorutil/visorkmodutils.c  | 87 ----------------------
 4 files changed, 11 insertions(+), 115 deletions(-)

diff --git a/drivers/staging/unisys/include/timskmodutils.h b/drivers/staging/unisys/include/timskmodutils.h
index ea0ec49..2d81d46 100644
--- a/drivers/staging/unisys/include/timskmodutils.h
+++ b/drivers/staging/unisys/include/timskmodutils.h
@@ -24,28 +24,6 @@ void *kmalloc_kernel(size_t siz);
 void  myprintk(const char *myDrvName, const char *devname,
 		const char *template, ...);
 
-/** Print the hexadecimal contents of a data buffer to a supplied print buffer.
- *  @param dest               the print buffer where text characters will be
- *                            written
- *  @param destSize           the maximum number of bytes that can be written
- *                            to #dest
- *  @param src                the buffer that contains the data that is to be
- *                            hex-dumped
- *  @param srcLen             the number of bytes at #src to be hex-dumped
- *  @param bytesToDumpPerLine output will be formatted such that at most this
- *                            many of the input data bytes will be represented
- *                            on each line of output
- *  @return                   the number of text characters written to #dest
- *                            (not including the trailing '\0' byte)
- *  @ingroup internal
- */
-int   visor_hexDumpToBuffer(char *dest,
-			    int destSize,
-			    char *prefix,
-			    char *src,
-			    int srcLen,
-			    int bytesToDumpPerLine);
-
 /*--------------------------------*
  *---  GENERAL MESSAGEQ STUFF  ---*
  *--------------------------------*/
diff --git a/drivers/staging/unisys/visorchannel/visorchannel_funcs.c b/drivers/staging/unisys/visorchannel/visorchannel_funcs.c
index 611be77..f397d83 100644
--- a/drivers/staging/unisys/visorchannel/visorchannel_funcs.c
+++ b/drivers/staging/unisys/visorchannel/visorchannel_funcs.c
@@ -603,9 +603,9 @@ void
 visorchannel_dump_section(VISORCHANNEL *chan, char *s,
 			  int off, int len, struct seq_file *seq)
 {
-	char *buf = NULL, *fmtbuf = NULL;
+	char *buf, *tbuf, *fmtbuf;
 	int fmtbufsize = 0;
-	int i = 0;
+	int i;
 	int errcode = 0;
 
 	fmtbufsize = 100 * COVQ(len, 16);
@@ -621,9 +621,14 @@ visorchannel_dump_section(VISORCHANNEL *chan, char *s,
 		goto Away;
 	}
 	seq_printf(seq, "channel %s:\n", s);
-	visor_hexDumpToBuffer(fmtbuf, fmtbufsize, "  ", buf, len, 16);
-	for (i = 0; fmtbuf[i] != '\0'; i++)
-		seq_printf(seq, "%c", fmtbuf[i]);
+	tbuf = buf;
+	while (len > 0) {
+		i = (len < 16) ? len : 16;
+		hex_dump_to_buffer(tbuf, i, 16, 1, fmtbuf, fmtbufsize, TRUE);
+		seq_printf(seq, "%s\n", fmtbuf);
+		tbuf += 16;
+		len -= 16;
+	}
 
 Away:
 	if (buf != NULL) {
diff --git a/drivers/staging/unisys/visorutil/procobjecttree.c b/drivers/staging/unisys/visorutil/procobjecttree.c
index e4d734e..7c7f001 100644
--- a/drivers/staging/unisys/visorutil/procobjecttree.c
+++ b/drivers/staging/unisys/visorutil/procobjecttree.c
@@ -150,7 +150,7 @@ MYPROCTYPE *visor_proc_CreateType(struct proc_dir_entry *procDirRoot,
 	type->nNames = 0;
 	type->show_property = show_property;
 	type->procDirRoot = procDirRoot;
-	if (type->propertyNames != 0)
+	if (type->propertyNames != NULL)
 		while (type->propertyNames[type->nProperties] != NULL)
 			type->nProperties++;
 	while (type->name[type->nNames] != NULL)
diff --git a/drivers/staging/unisys/visorutil/visorkmodutils.c b/drivers/staging/unisys/visorutil/visorkmodutils.c
index ed46208..ef06469 100644
--- a/drivers/staging/unisys/visorutil/visorkmodutils.c
+++ b/drivers/staging/unisys/visorutil/visorkmodutils.c
@@ -20,93 +20,6 @@
 
 #define MYDRVNAME "timskmodutils"
 
-BOOL Debug_Malloc_Enabled = FALSE;
-
-/** Print the hexadecimal contents of a data buffer to a supplied print buffer.
- *  @param dest               the print buffer where text characters will
- *			      be written
- *  @param destSize           the maximum number of bytes that can be written
- *			      to #dest
- *  @param src                the buffer that contains the data that is to be
- *			      hex-dumped
- *  @param srcLen             the number of bytes at #src to be hex-dumped
- *  @param bytesToDumpPerLine output will be formatted such that at most
- *			      this many of the input data bytes will be
- *			      represented on each line of output
- *  @return                   the number of text characters written to #dest
- *                            (not including the trailing '\0' byte)
- *  @ingroup internal
- */
-int visor_hexDumpToBuffer(char *dest, int destSize, char *prefix, char *src,
-			  int srcLen, int bytesToDumpPerLine)
-{
-	int i = 0;
-	int pos = 0;
-	char printable[bytesToDumpPerLine + 1];
-	char hex[(bytesToDumpPerLine * 3) + 1];
-	char *line = NULL;
-	int linesize = 1000;
-	int linelen = 0;
-	int currentlen = 0;
-	char emptystring[] = "";
-	char *pfx = prefix;
-	int baseaddr = 0;
-	int rc = 0;
-
-	line = vmalloc(linesize);
-	if (line == NULL)
-		RETINT(currentlen);
-
-	if (pfx == NULL || (strlen(pfx) > 50))
-		pfx = emptystring;
-	memset(hex, ' ', bytesToDumpPerLine * 3);
-	hex[bytesToDumpPerLine * 3] = '\0';
-	memset(printable, ' ', bytesToDumpPerLine);
-	printable[bytesToDumpPerLine] = '\0';
-	if (destSize > 0)
-		dest[0] = '\0';
-
-	for (i = 0; i < srcLen; i++) {
-		pos = i % bytesToDumpPerLine;
-		if ((pos == 0) && (i > 0)) {
-			hex[bytesToDumpPerLine*3] = '\0';
-			linelen = sprintf(line, "%s%-6.6x %s %s\n", pfx,
-					  baseaddr, hex, printable);
-			if ((currentlen) + (linelen) >= destSize)
-				RETINT(currentlen);
-			strcat(dest, line);
-			currentlen += linelen;
-			memset(hex, ' ', bytesToDumpPerLine * 3);
-			memset(printable, ' ', bytesToDumpPerLine);
-			baseaddr = i;
-		}
-		sprintf(hex + (pos * 3), "%-2.2x ", (uint8_t)(src[i]));
-		*(hex + (pos * 3) + 3) = ' ';  /* get rid of null */
-		if (((uint8_t)(src[i]) >= ' ') && (uint8_t)(src[i]) < 127)
-			printable[pos] = src[i];
-		else
-			printable[pos] = '.';
-	}
-	pos = i%bytesToDumpPerLine;
-	if (i > 0) {
-		hex[bytesToDumpPerLine * 3] = '\0';
-		linelen = sprintf(line, "%s%-6.6x %s %s\n",
-				  pfx, baseaddr, hex, printable);
-		if ((currentlen) + (linelen) >= destSize)
-			RETINT(currentlen);
-		strcat(dest, line);
-		currentlen += linelen;
-	}
-	RETINT(currentlen);
-
-Away:
-	if (line)
-		vfree(line);
-	return rc;
-}
-EXPORT_SYMBOL_GPL(visor_hexDumpToBuffer);
-
-
 /** Callers to interfaces that set __GFP_NORETRY flag below
  *  must check for a NULL (error) result as we are telling the
  *  kernel interface that it is okay to fail.
-- 
1.8.5.3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux