tty/nozomi: cleanup DUMP() macro

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Joey Pabalinas 2018-04-24 19:48:03 -10:00 committed by Greg Kroah-Hartman
parent c1c734cb1f
commit 2ea0452c5a
1 changed files with 13 additions and 13 deletions

View File

@ -72,19 +72,19 @@ do { \
#define TMP_BUF_MAX 256 #define TMP_BUF_MAX 256
#define DUMP(buf__,len__) \ #define DUMP(buf__, len__) \
do { \ do { \
char tbuf[TMP_BUF_MAX] = {0};\ char tbuf[TMP_BUF_MAX] = {0}; \
if (len__ > 1) {\ if (len__ > 1) { \
snprintf(tbuf, len__ > TMP_BUF_MAX ? TMP_BUF_MAX : len__, "%s", buf__);\ u32 data_len = min_t(u32, len__, TMP_BUF_MAX); \
if (tbuf[len__-2] == '\r') {\ strscpy(tbuf, buf__, data_len); \
tbuf[len__-2] = 'r';\ if (tbuf[data_len - 2] == '\r') \
} \ tbuf[data_len - 2] = 'r'; \
DBG1("SENDING: '%s' (%d+n)", tbuf, len__);\ DBG1("SENDING: '%s' (%d+n)", tbuf, len__); \
} else {\ } else { \
DBG1("SENDING: '%s' (%d)", tbuf, len__);\ DBG1("SENDING: '%s' (%d)", tbuf, len__); \
} \ } \
} while (0) } while (0)
/* Defines */ /* Defines */
#define NOZOMI_NAME "nozomi" #define NOZOMI_NAME "nozomi"