Skip to contentSkip to conversation

tty/nozomi: general module cleanup

PATCH Superseded Joey Pabalinas 2 participants 7 messages Apr 24, 2018 – Apr 25, 2018 TTY layer and serial drivers

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover tty/nozomi: general module cleanup

The nozomi module has a few sections which could use a bit of cleanup; both style and clarity could be improved while maintaining equivalent semantics.

Cleanup messy portions of the module code while preserving existing behavior by:

- Replacing constructs like len__ > TMP_BUF_MAX ? TMP_BUF_MAX : len__ with min_t(u32, len__, TMP_BUF_MAX) and function calls like snprintf(tbuf, ..., "%s", ...). with strscpy(tbuf, ..., ...).
- Correct inconsistently indented lines and extraneous whitespace.

CC Greg Kroah-Hartman <[email protected]>
CC Arnd Bergmann <[email protected]>
CC Jiri Slaby <[email protected]>

Joey Pabalinas (2):
tty/nozomi: cleanup DUMP() macro
tty/nozomi: fix inconsistent indentation

 drivers/tty/nozomi.c | 100 +++++++++++++++++++++----------------------
 1 file changed, 50 insertions(+), 50 deletions(-)
Signature · 1 line
2.17.0.rc1.35.g90bbd502d54fe92035.dirty
#1 lore raw

PATCH v3 1/2 tty/nozomi: cleanup DUMP() macro

Replace snprint() with strscpy() and use min_t() instead of the conditional operator to clamp buffer length.

 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/tty/nozomi.c +13 -13
index b57b35066ebea94639..f26bf1d1e9ee0e74eb 100644
@@ -72,19 +72,19 @@ do {							\
 
 #define TMP_BUF_MAX 256
 
-#define DUMP(buf__,len__) \
-  do {  \
-    char tbuf[TMP_BUF_MAX] = {0};\
-    if (len__ > 1) {\
-	snprintf(tbuf, len__ > TMP_BUF_MAX ? TMP_BUF_MAX : len__, "%s", buf__);\
-	if (tbuf[len__-2] == '\r') {\
-		tbuf[len__-2] = 'r';\
-	} \
-	DBG1("SENDING: '%s' (%d+n)", tbuf, len__);\
-    } else {\
-	DBG1("SENDING: '%s' (%d)", tbuf, len__);\
-    } \
-} while (0)
+#define DUMP(buf__, len__)						\
+	do {								\
+		char tbuf[TMP_BUF_MAX] = {0};				\
+		if (len__ > 1) {					\
+			u32 data_len = min_t(u32, len__, TMP_BUF_MAX);	\
+			strscpy(tbuf, buf__, data_len);			\
+			if (tbuf[data_len - 2] == '\r')			\
+				tbuf[data_len - 2] = 'r';		\
+			DBG1("SENDING: '%s' (%d+n)", tbuf, len__);	\
+		} else {						\
+			DBG1("SENDING: '%s' (%d)", tbuf, len__);	\
+		}							\
+	} while (0)
 
 /*    Defines */
 #define NOZOMI_NAME		"nozomi"
Signature · 1 line
2.17.0.rc1.35.g90bbd502d54fe92035.dirty
#2 lore raw

Re: [PATCH v3 1/2] tty/nozomi: cleanup DUMP() macro

Quoted 6 lines · Joey Pabalinas

Replace snprint() with strscpy() and use min_t() instead of the conditional operator to clamp buffer length.

 1 file changed, 13 insertions(+), 13 deletions(-)

Again, this is odd...

How are you sending these patches? How are you creating them? What is taking part of the diffstat off and just leaving that line?

thanks,

greg k-h

#3 lore raw

Re: [PATCH v3 1/2] tty/nozomi: cleanup DUMP() macro

Quoted 2 lines · Greg Kroah-Hartman

How are you sending these patches? How are you creating them? What is taking part of the diffstat off and just leaving that line?

Hm, my git format-patch alias included --shortstat for some odd reason, very sorry about that.

Going to resend.

Signature · 2 lines
Cheers,
Joey Pabalinas
#4 lore raw

Re: [PATCH v3 1/2] tty/nozomi: cleanup DUMP() macro

Quoted 8 lines · Joey Pabalinas
Quoted 2 lines · Greg Kroah-Hartman

How are you sending these patches? How are you creating them? What is taking part of the diffstat off and just leaving that line?

Hm, my git format-patch alias included --shortstat for some odd reason, very sorry about that.

Going to resend.

Ah, never seen that before. Just use the defaults and you should be fine. Having the normal diffstat is good.

thanks,

greg k-h

#5 lore raw

Re: [PATCH v3 1/2] tty/nozomi: cleanup DUMP() macro

Quoted 2 lines · Greg Kroah-Hartman

Ah, never seen that before. Just use the defaults and you should be fine. Having the normal diffstat is good.

Yes, will definitely do from now on.

Signature · 2 lines
Cheers,
Joey Pabalinas
#6 lore raw

PATCH v3 2/2 tty/nozomi: fix inconsistent indentation

In reply to Joey Pabalinas

Correct misaligned indentation and remove extraneous spaces.

 1 file changed, 37 insertions(+), 37 deletions(-)
drivers/tty/nozomi.c +37 -37
index f26bf1d1e9ee0e74eb..0fcb4db721d2a42f08 100644
@@ -102,41 +102,41 @@ do {							\
 #define RECEIVE_BUF_MAX		4
 
 
-#define R_IIR		0x0000	/* Interrupt Identity Register */
-#define R_FCR		0x0000	/* Flow Control Register */
-#define R_IER		0x0004	/* Interrupt Enable Register */
+#define R_IIR			0x0000	/* Interrupt Identity Register */
+#define R_FCR			0x0000	/* Flow Control Register */
+#define R_IER			0x0004	/* Interrupt Enable Register */
 
 #define NOZOMI_CONFIG_MAGIC	0xEFEFFEFE
 #define TOGGLE_VALID		0x0000
 
 /* Definition of interrupt tokens */
-#define MDM_DL1		0x0001
-#define MDM_UL1		0x0002
-#define MDM_DL2		0x0004
-#define MDM_UL2		0x0008
-#define DIAG_DL1	0x0010
-#define DIAG_DL2	0x0020
-#define DIAG_UL		0x0040
-#define APP1_DL		0x0080
-#define APP1_UL		0x0100
-#define APP2_DL		0x0200
-#define APP2_UL		0x0400
-#define CTRL_DL		0x0800
-#define CTRL_UL		0x1000
-#define RESET		0x8000
+#define MDM_DL1			0x0001
+#define MDM_UL1			0x0002
+#define MDM_DL2			0x0004
+#define MDM_UL2			0x0008
+#define DIAG_DL1		0x0010
+#define DIAG_DL2		0x0020
+#define DIAG_UL			0x0040
+#define APP1_DL			0x0080
+#define APP1_UL			0x0100
+#define APP2_DL			0x0200
+#define APP2_UL			0x0400
+#define CTRL_DL			0x0800
+#define CTRL_UL			0x1000
+#define RESET			0x8000
 
-#define MDM_DL		(MDM_DL1  | MDM_DL2)
-#define MDM_UL		(MDM_UL1  | MDM_UL2)
-#define DIAG_DL		(DIAG_DL1 | DIAG_DL2)
+#define MDM_DL			(MDM_DL1  | MDM_DL2)
+#define MDM_UL			(MDM_UL1  | MDM_UL2)
+#define DIAG_DL			(DIAG_DL1 | DIAG_DL2)
 
 /* modem signal definition */
-#define CTRL_DSR	0x0001
-#define CTRL_DCD	0x0002
-#define CTRL_RI		0x0004
-#define CTRL_CTS	0x0008
+#define CTRL_DSR		0x0001
+#define CTRL_DCD		0x0002
+#define CTRL_RI			0x0004
+#define CTRL_CTS		0x0008
 
-#define CTRL_DTR	0x0001
-#define CTRL_RTS	0x0002
+#define CTRL_DTR		0x0001
+#define CTRL_RTS		0x0002
 
 #define MAX_PORT		4
 #define NOZOMI_MAX_PORTS	5
@@ -365,7 +365,7 @@ struct buffer {
 	u8 *data;
 } __attribute__ ((packed));
 
-/*    Global variables */
+/* Global variables */
 static const struct pci_device_id nozomi_pci_tbl[] = {
 	{PCI_DEVICE(0x1931, 0x000c)},	/* Nozomi HSDPA */
 	{},
@@ -1686,12 +1686,12 @@ static int ntty_tiocmget(struct tty_struct *tty)
 
 	/* Note: these could change under us but it is not clear this
 	   matters if so */
-	return	(ctrl_ul->RTS ? TIOCM_RTS : 0) |
-		(ctrl_ul->DTR ? TIOCM_DTR : 0) |
-		(ctrl_dl->DCD ? TIOCM_CAR : 0) |
-		(ctrl_dl->RI  ? TIOCM_RNG : 0) |
-		(ctrl_dl->DSR ? TIOCM_DSR : 0) |
-		(ctrl_dl->CTS ? TIOCM_CTS : 0);
+	return (ctrl_ul->RTS ? TIOCM_RTS : 0)
+		| (ctrl_ul->DTR ? TIOCM_DTR : 0)
+		| (ctrl_dl->DCD ? TIOCM_CAR : 0)
+		| (ctrl_dl->RI  ? TIOCM_RNG : 0)
+		| (ctrl_dl->DSR ? TIOCM_DSR : 0)
+		| (ctrl_dl->CTS ? TIOCM_CTS : 0);
 }
 
 /* Sets io controls parameters */
@@ -1722,10 +1722,10 @@ static int ntty_cflags_changed(struct port *port, unsigned long flags,
 	const struct async_icount cnow = port->tty_icount;
 	int ret;
 
-	ret =	((flags & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
-		((flags & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
-		((flags & TIOCM_CD)  && (cnow.dcd != cprev->dcd)) ||
-		((flags & TIOCM_CTS) && (cnow.cts != cprev->cts));
+	ret = ((flags & TIOCM_RNG) && (cnow.rng != cprev->rng))
+		|| ((flags & TIOCM_DSR) && (cnow.dsr != cprev->dsr))
+		|| ((flags & TIOCM_CD)  && (cnow.dcd != cprev->dcd))
+		|| ((flags & TIOCM_CTS) && (cnow.cts != cprev->cts));
 
 	*cprev = cnow;
 
Signature · 1 line
2.17.0.rc1.35.g90bbd502d54fe92035.dirty