Skip to contentSkip to conversation

Staging: dgnc: show() methods should use scnprintf()

PATCH In review Ksenija Stanojevic 2 participants 2 messages Sep 29, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: dgnc: show() methods should use scnprintf()

snprintf() may return a value that exceeds its second argument, show() methods should use scnprintf() instead of snprintf().

---
 drivers/staging/dgnc/dgnc_sysfs.c | 52 +++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 26 deletions(-)
drivers/staging/dgnc/dgnc_sysfs.c +26 -26
index 44db870..1267318 100644
@@ -29,28 +29,28 @@
 
 static ssize_t dgnc_driver_version_show(struct device_driver *ddp, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
+	return scnprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
 }
 static DRIVER_ATTR(version, S_IRUSR, dgnc_driver_version_show, NULL);
 
 
 static ssize_t dgnc_driver_boards_show(struct device_driver *ddp, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%d\n", dgnc_NumBoards);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", dgnc_NumBoards);
 }
 static DRIVER_ATTR(boards, S_IRUSR, dgnc_driver_boards_show, NULL);
 
 
 static ssize_t dgnc_driver_maxboards_show(struct device_driver *ddp, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
 }
 static DRIVER_ATTR(maxboards, S_IRUSR, dgnc_driver_maxboards_show, NULL);
 
 
 static ssize_t dgnc_driver_pollrate_show(struct device_driver *ddp, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%dms\n", dgnc_poll_tick);
+	return scnprintf(buf, PAGE_SIZE, "%dms\n", dgnc_poll_tick);
 }
 
 static ssize_t dgnc_driver_pollrate_store(struct device_driver *ddp,
@@ -156,7 +156,7 @@ static ssize_t dgnc_ports_state_show(struct device *p,
 	DGNC_VERIFY_BOARD(p, bd);
 
 	for (i = 0; i < bd->nasync; i++) {
-		count += snprintf(buf + count, PAGE_SIZE - count,
+		count += scnprintf(buf + count, PAGE_SIZE - count,
 			"%d %s\n", bd->channels[i]->ch_portnum,
 			bd->channels[i]->ch_open_count ? "Open" : "Closed");
 	}
@@ -175,7 +175,7 @@ static ssize_t dgnc_ports_baud_show(struct device *p,
 	DGNC_VERIFY_BOARD(p, bd);
 
 	for (i = 0; i < bd->nasync; i++) {
-		count +=  snprintf(buf + count, PAGE_SIZE - count,
+		count +=  scnprintf(buf + count, PAGE_SIZE - count,
 			"%d %d\n", bd->channels[i]->ch_portnum,
 			bd->channels[i]->ch_old_baud);
 	}
@@ -196,7 +196,7 @@ static ssize_t dgnc_ports_msignals_show(struct device *p,
 
 	for (i = 0; i < bd->nasync; i++) {
 		if (bd->channels[i]->ch_open_count) {
-			count += snprintf(buf + count, PAGE_SIZE - count,
+			count += scnprintf(buf + count, PAGE_SIZE - count,
 				"%d %s %s %s %s %s %s\n",
 				bd->channels[i]->ch_portnum,
 				(bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
@@ -206,7 +206,7 @@ static ssize_t dgnc_ports_msignals_show(struct device *p,
 				(bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
 				(bd->channels[i]->ch_mistat & UART_MSR_RI)  ? "RI"  : "");
 		} else {
-			count += snprintf(buf + count, PAGE_SIZE - count,
+			count += scnprintf(buf + count, PAGE_SIZE - count,
 				"%d\n", bd->channels[i]->ch_portnum);
 		}
 	}
@@ -225,7 +225,7 @@ static ssize_t dgnc_ports_iflag_show(struct device *p,
 	DGNC_VERIFY_BOARD(p, bd);
 
 	for (i = 0; i < bd->nasync; i++) {
-		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
+		count += scnprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
 			bd->channels[i]->ch_portnum,
 			bd->channels[i]->ch_c_iflag);
 	}
@@ -244,7 +244,7 @@ static ssize_t dgnc_ports_cflag_show(struct device *p,
 	DGNC_VERIFY_BOARD(p, bd);
 
 	for (i = 0; i < bd->nasync; i++) {
-		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
+		count += scnprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
 			bd->channels[i]->ch_portnum,
 			bd->channels[i]->ch_c_cflag);
 	}
@@ -263,7 +263,7 @@ static ssize_t dgnc_ports_oflag_show(struct device *p,
 	DGNC_VERIFY_BOARD(p, bd);
 
 	for (i = 0; i < bd->nasync; i++) {
-		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
+		count += scnprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
 			bd->channels[i]->ch_portnum,
 			bd->channels[i]->ch_c_oflag);
 	}
@@ -282,7 +282,7 @@ static ssize_t dgnc_ports_lflag_show(struct device *p,
 	DGNC_VERIFY_BOARD(p, bd);
 
 	for (i = 0; i < bd->nasync; i++) {
-		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
+		count += scnprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
 			bd->channels[i]->ch_portnum,
 			bd->channels[i]->ch_c_lflag);
 	}
@@ -302,7 +302,7 @@ static ssize_t dgnc_ports_digi_flag_show(struct device *p,
 	DGNC_VERIFY_BOARD(p, bd);
 
 	for (i = 0; i < bd->nasync; i++) {
-		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
+		count += scnprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
 			bd->channels[i]->ch_portnum,
 			bd->channels[i]->ch_digi.digi_flags);
 	}
@@ -321,7 +321,7 @@ static ssize_t dgnc_ports_rxcount_show(struct device *p,
 	DGNC_VERIFY_BOARD(p, bd);
 
 	for (i = 0; i < bd->nasync; i++) {
-		count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
+		count += scnprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
 			bd->channels[i]->ch_portnum,
 			bd->channels[i]->ch_rxcount);
 	}
@@ -340,7 +340,7 @@ static ssize_t dgnc_ports_txcount_show(struct device *p,
 	DGNC_VERIFY_BOARD(p, bd);
 
 	for (i = 0; i < bd->nasync; i++) {
-		count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
+		count += scnprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
 			bd->channels[i]->ch_portnum,
 			bd->channels[i]->ch_txcount);
 	}
@@ -413,7 +413,7 @@ static ssize_t dgnc_tty_state_show(struct device *d,
 	if (bd->state != BOARD_READY)
 		return 0;
 
-	return snprintf(buf, PAGE_SIZE, "%s",
+	return scnprintf(buf, PAGE_SIZE, "%s",
 			un->un_open_count ? "Open" : "Closed");
 }
 static DEVICE_ATTR(state, S_IRUSR, dgnc_tty_state_show, NULL);
@@ -440,7 +440,7 @@ static ssize_t dgnc_tty_baud_show(struct device *d,
 	if (bd->state != BOARD_READY)
 		return 0;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_old_baud);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", ch->ch_old_baud);
 }
 static DEVICE_ATTR(baud, S_IRUSR, dgnc_tty_baud_show, NULL);
 
@@ -467,7 +467,7 @@ static ssize_t dgnc_tty_msignals_show(struct device *d,
 		return 0;
 
 	if (ch->ch_open_count) {
-		return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
+		return scnprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
 			(ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
 			(ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
 			(ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
@@ -501,7 +501,7 @@ static ssize_t dgnc_tty_iflag_show(struct device *d,
 	if (bd->state != BOARD_READY)
 		return 0;
 
-	return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
+	return scnprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
 }
 static DEVICE_ATTR(iflag, S_IRUSR, dgnc_tty_iflag_show, NULL);
 
@@ -527,7 +527,7 @@ static ssize_t dgnc_tty_cflag_show(struct device *d,
 	if (bd->state != BOARD_READY)
 		return 0;
 
-	return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
+	return scnprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
 }
 static DEVICE_ATTR(cflag, S_IRUSR, dgnc_tty_cflag_show, NULL);
 
@@ -553,7 +553,7 @@ static ssize_t dgnc_tty_oflag_show(struct device *d,
 	if (bd->state != BOARD_READY)
 		return 0;
 
-	return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
+	return scnprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
 }
 static DEVICE_ATTR(oflag, S_IRUSR, dgnc_tty_oflag_show, NULL);
 
@@ -579,7 +579,7 @@ static ssize_t dgnc_tty_lflag_show(struct device *d,
 	if (bd->state != BOARD_READY)
 		return 0;
 
-	return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
+	return scnprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
 }
 static DEVICE_ATTR(lflag, S_IRUSR, dgnc_tty_lflag_show, NULL);
 
@@ -605,7 +605,7 @@ static ssize_t dgnc_tty_digi_flag_show(struct device *d,
 	if (bd->state != BOARD_READY)
 		return 0;
 
-	return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
+	return scnprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
 }
 static DEVICE_ATTR(digi_flag, S_IRUSR, dgnc_tty_digi_flag_show, NULL);
 
@@ -631,7 +631,7 @@ static ssize_t dgnc_tty_rxcount_show(struct device *d,
 	if (bd->state != BOARD_READY)
 		return 0;
 
-	return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
+	return scnprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
 }
 static DEVICE_ATTR(rxcount, S_IRUSR, dgnc_tty_rxcount_show, NULL);
 
@@ -657,7 +657,7 @@ static ssize_t dgnc_tty_txcount_show(struct device *d,
 	if (bd->state != BOARD_READY)
 		return 0;
 
-	return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
+	return scnprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
 }
 static DEVICE_ATTR(txcount, S_IRUSR, dgnc_tty_txcount_show, NULL);
 
@@ -683,7 +683,7 @@ static ssize_t dgnc_tty_name_show(struct device *d,
 	if (bd->state != BOARD_READY)
 		return 0;
 
-	return snprintf(buf, PAGE_SIZE, "%sn%d%c\n",
+	return scnprintf(buf, PAGE_SIZE, "%sn%d%c\n",
 		(un->un_type == DGNC_PRINT) ? "pr" : "tty",
 		bd->boardnum + 1, 'a' + ch->ch_portnum);
 }
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 13 lines · Ksenija Stanojevic

snprintf() may return a value that exceeds its second argument, show() methods should use scnprintf() instead of snprintf().

---
 drivers/staging/dgnc/dgnc_sysfs.c | 52 +++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 26 deletions(-)
drivers/staging/dgnc/dgnc_sysfs.c +0 -0
index 44db870..1267318 100644

drivers/staging/dgnc/dgnc_sysfs.c line 32

Quoted 5 lines
drivers/staging/dgnc/dgnc_sysfs.c +1 -1
@@ -29,28 +29,28 @@
 
 static ssize_t dgnc_driver_version_show(struct device_driver *ddp, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
+	return scnprintf(buf, PAGE_SIZE, "%s\n", DG_PART);

Same as my other comment, these are just fine as-is.

thanks,

greg k-h