LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Joey Pabalinas <joeypabalinas@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>, Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH v3 1/2] tty/nozomi: cleanup DUMP() macro
Date: Tue, 24 Apr 2018 12:39:14 -1000 [thread overview]
Message-ID: <58b559776732f0fc14b1c30ec7da6fc27c3f1cc8.1524606061.git.joeypabalinas@gmail.com> (raw)
In-Reply-To: <cover.1524606061.git.joeypabalinas@gmail.com>
In-Reply-To: <cover.1524606061.git.joeypabalinas@gmail.com>
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>
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
@@ -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"
--
2.17.0.rc1.35.g90bbd502d54fe92035.dirty
next prev parent reply other threads:[~2018-04-24 22:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-24 22:39 [PATCH v3 0/2] tty/nozomi: general module cleanup Joey Pabalinas
2018-04-24 22:39 ` Joey Pabalinas [this message]
2018-04-25 5:38 ` [PATCH v3 1/2] tty/nozomi: cleanup DUMP() macro Greg Kroah-Hartman
2018-04-25 5:45 ` Joey Pabalinas
2018-04-25 6:09 ` Greg Kroah-Hartman
2018-04-25 6:34 ` Joey Pabalinas
2018-04-24 22:39 ` [PATCH v3 2/2] tty/nozomi: fix inconsistent indentation Joey Pabalinas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58b559776732f0fc14b1c30ec7da6fc27c3f1cc8.1524606061.git.joeypabalinas@gmail.com \
--to=joeypabalinas@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--subject='Re: [PATCH v3 1/2] tty/nozomi: cleanup DUMP() macro' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).