[][kernel][common][app][Fix Coverity issue for the regs utility]

[Description]
Fix Coverity issue for the regs utility.

Without this patch, the coverity might detect ERR33-C warnings.

[Release-log]
N/A


Change-Id: Ifd968064e03d930f33f8f52624f515ed97319cf6
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/8063030
diff --git a/feed/regs/src/regs.c b/feed/regs/src/regs.c
index 2e54c1d..24a8f6e 100755
--- a/feed/regs/src/regs.c
+++ b/feed/regs/src/regs.c
@@ -68,7 +68,7 @@
 	    (start_bit + data_len > 32)) {
 		fprintf(stderr,
 			"Startbit range[0~31], and DataLen range[1~32], and Startbit + DataLen <= 32\n");
-		return;
+		exit(1);
 	}
 
 	for (i = 0; i < data_len; i++) {
@@ -107,7 +107,7 @@
 	    (start_bit + data_len > 32)) {
 		fprintf(stderr,
 			"Startbit range[0~31], and DataLen range[1~32], and Startbit + DataLen <= 32\n");
-		return;
+		exit(1);
 	}
 
 	for (i = 0; i < data_len; i++) {
@@ -150,6 +150,7 @@
 		"\tRead    : regs r 0x1b100000 29 3      //read 0x1b100000[29:31]\n"
 		"\tWrite   : regs w 0x1b100000 0x1234    //write 0x1b100000=0x1234\n"
 		"\tModify  : regs m 0x1b100000 0x0 29 3  //modify 0x1b100000[29:31]=0\n");
+	exit(1);
 }
 
 int main(int argc, char **argv)
@@ -182,7 +183,11 @@
 
 	/* Map one page */
 	offset = strtoul(argv[2], NULL, 16);
-	map_base = mmap(0, 2*MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset & ~MAP_MASK);
+	if (offset > 0xFFFFFFFFFFFF)
+		PRINT_ERROR;
+
+	map_base = mmap(0, 2 * MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
+			fd, offset & ~MAP_MASK);
 	if(map_base == (void *) -1)
 		PRINT_ERROR;
 
@@ -194,12 +199,20 @@
 	switch(access_type) {
 		case 'm':
 			writeval = strtoul(argv[3], 0, 16);
+			if (writeval > UINT_MAX)
+				PRINT_ERROR;
 			startbit = strtoul(argv[4], 0, 10);
+			if (startbit > 32)
+				PRINT_ERROR;
 			datalen  = strtoul(argv[5], 0, 10);
+			if (datalen > 32)
+				PRINT_ERROR;
 			reg_mod_bits((uint32_t *)virt_addr, writeval, startbit, datalen);
 			break;
 		case 'w':
 			writeval = strtoul(argv[3], 0, 16);
+			if (writeval > UINT_MAX)
+				PRINT_ERROR;
 			*((uint32_t *) virt_addr) = writeval;
 			printf("Written 0x%X; ", writeval);
 			break;
@@ -215,7 +228,11 @@
 					      0, 32);
 			else {
 				startbit = strtoul(argv[3], 0, 10);
-				datalen  = strtoul(argv[4], 0, 10);
+				if (startbit > 32)
+					PRINT_ERROR;
+				datalen = strtoul(argv[4], 0, 10);
+				if (datalen > 32)
+					PRINT_ERROR;
 				reg_read_bits((uint32_t *)virt_addr,
 					      (uint32_t *)map_base,
 					      (uint32_t *)(offset & ~MAP_MASK),
@@ -223,7 +240,7 @@
 			}
 			goto out;
 		default:
-			fprintf(stderr, "Illegal data type '%c'.\n", access_type);
+			printf("Illegal data type '%c'.\n", access_type);
 			goto out;
 	}