All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/2] tty/nozomi: general module cleanup
@ 2018-04-25  5:48 Joey Pabalinas
  2018-04-25  5:48 ` [PATCH v4 1/2] tty/nozomi: cleanup DUMP() macro Joey Pabalinas
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Joey Pabalinas @ 2018-04-25  5:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman, Arnd Bergmann, Jiri Slaby

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 <gregkh@linuxfoundation.org>
CC: Arnd Bergmann <arnd@arndb.de>
CC: Jiri Slaby <jslaby@suse.cz>

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(-)

-- 
2.17.0.rc1.35.g90bbd502d54fe92035.dirty

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 1/2] tty/nozomi: cleanup DUMP() macro
  2018-04-25  5:48 [PATCH v4 0/2] tty/nozomi: general module cleanup Joey Pabalinas
@ 2018-04-25  5:48 ` Joey Pabalinas
  2018-04-25  5:48 ` [PATCH v4 2/2] tty/nozomi: fix inconsistent indentation Joey Pabalinas
  2018-04-25  6:05 ` [PATCH v4 0/2] tty/nozomi: general module cleanup Greg Kroah-Hartman
  2 siblings, 0 replies; 5+ messages in thread
From: Joey Pabalinas @ 2018-04-25  5:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman, Arnd Bergmann, Jiri Slaby

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

Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>
---
 drivers/tty/nozomi.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
index b57b35066ebea94639..f26bf1d1e9ee0e74eb 100644
--- a/drivers/tty/nozomi.c
+++ b/drivers/tty/nozomi.c
@@ -70,23 +70,23 @@ do {							\
 
 /* TODO: rewrite to optimize macros... */
 
 #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"
 #define NOZOMI_NAME_TTY		"nozomi_tty"
 #define DRIVER_DESC		"Nozomi driver"
-- 
2.17.0.rc1.35.g90bbd502d54fe92035.dirty

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/2] tty/nozomi: fix inconsistent indentation
  2018-04-25  5:48 [PATCH v4 0/2] tty/nozomi: general module cleanup Joey Pabalinas
  2018-04-25  5:48 ` [PATCH v4 1/2] tty/nozomi: cleanup DUMP() macro Joey Pabalinas
@ 2018-04-25  5:48 ` Joey Pabalinas
  2018-04-25  6:05 ` [PATCH v4 0/2] tty/nozomi: general module cleanup Greg Kroah-Hartman
  2 siblings, 0 replies; 5+ messages in thread
From: Joey Pabalinas @ 2018-04-25  5:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman, Arnd Bergmann, Jiri Slaby

Correct misaligned indentation and remove extraneous spaces.

Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>
---
 drivers/tty/nozomi.c | 74 ++++++++++++++++++++++----------------------
 1 file changed, 37 insertions(+), 37 deletions(-)

diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
index f26bf1d1e9ee0e74eb..0fcb4db721d2a42f08 100644
--- a/drivers/tty/nozomi.c
+++ b/drivers/tty/nozomi.c
@@ -100,45 +100,45 @@ do {							\
 /* Size of tmp send buffer to card */
 #define SEND_BUF_MAX		1024
 #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
 #define NOZOMI_MAX_CARDS	(NTTY_TTY_MAXMINORS / MAX_PORT)
 
@@ -363,11 +363,11 @@ struct nozomi {
 struct buffer {
 	u32 size;		/* size is the length of the data buffer */
 	u8 *data;
 } __attribute__ ((packed));
 
-/*    Global variables */
+/* Global variables */
 static const struct pci_device_id nozomi_pci_tbl[] = {
 	{PCI_DEVICE(0x1931, 0x000c)},	/* Nozomi HSDPA */
 	{},
 };
 
@@ -1684,16 +1684,16 @@ static int ntty_tiocmget(struct tty_struct *tty)
 	const struct ctrl_dl *ctrl_dl = &port->ctrl_dl;
 	const struct ctrl_ul *ctrl_ul = &port->ctrl_ul;
 
 	/* 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 */
 static int ntty_tiocmset(struct tty_struct *tty,
 					unsigned int set, unsigned int clear)
@@ -1720,14 +1720,14 @@ static int ntty_cflags_changed(struct port *port, unsigned long flags,
 		struct async_icount *cprev)
 {
 	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;
 
 	return ret;
 }
-- 
2.17.0.rc1.35.g90bbd502d54fe92035.dirty

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 0/2] tty/nozomi: general module cleanup
  2018-04-25  5:48 [PATCH v4 0/2] tty/nozomi: general module cleanup Joey Pabalinas
  2018-04-25  5:48 ` [PATCH v4 1/2] tty/nozomi: cleanup DUMP() macro Joey Pabalinas
  2018-04-25  5:48 ` [PATCH v4 2/2] tty/nozomi: fix inconsistent indentation Joey Pabalinas
@ 2018-04-25  6:05 ` Greg Kroah-Hartman
  2018-04-25  6:24   ` Joey Pabalinas
  2 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2018-04-25  6:05 UTC (permalink / raw)
  To: Joey Pabalinas; +Cc: linux-kernel, Arnd Bergmann, Jiri Slaby

On Tue, Apr 24, 2018 at 07:48:02PM -1000, Joey Pabalinas wrote:
> 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 <gregkh@linuxfoundation.org>
> CC: Arnd Bergmann <arnd@arndb.de>
> CC: Jiri Slaby <jslaby@suse.cz>
> 
> 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(-)

What changed between versions of this series?

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 0/2] tty/nozomi: general module cleanup
  2018-04-25  6:05 ` [PATCH v4 0/2] tty/nozomi: general module cleanup Greg Kroah-Hartman
@ 2018-04-25  6:24   ` Joey Pabalinas
  0 siblings, 0 replies; 5+ messages in thread
From: Joey Pabalinas @ 2018-04-25  6:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Joey Pabalinas, linux-kernel, Arnd Bergmann, Jiri Slaby

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

On Wed, Apr 25, 2018 at 08:05:13AM +0200, Greg Kroah-Hartman wrote:
> What changed between versions of this series?

Ah no changes, I thought this was normal convention when doing
a resend, but after looking through other LKML patches
they just use a giant RESEND instead of bumping the version.

Sorry about all the mess; I mostly have only sent single
patches before this.

-- 
Cheers,
Joey Pabalinas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-04-25  6:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-25  5:48 [PATCH v4 0/2] tty/nozomi: general module cleanup Joey Pabalinas
2018-04-25  5:48 ` [PATCH v4 1/2] tty/nozomi: cleanup DUMP() macro Joey Pabalinas
2018-04-25  5:48 ` [PATCH v4 2/2] tty/nozomi: fix inconsistent indentation Joey Pabalinas
2018-04-25  6:05 ` [PATCH v4 0/2] tty/nozomi: general module cleanup Greg Kroah-Hartman
2018-04-25  6:24   ` Joey Pabalinas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.