diff options
author | Joey Pabalinas <joeypabalinas@gmail.com> | 2018-04-25 08:48:03 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-04-25 15:54:26 +0300 |
commit | 2ea0452c5a222be7f581d8cd48058ee6472d1449 (patch) | |
tree | 7e9bfacc250e42da27c6dcd8b9373e34957270d2 /drivers/tty/nozomi.c | |
parent | c1c734cb1f54b062f7e67ffc9656d82f5b412b9c (diff) | |
download | linux-2ea0452c5a222be7f581d8cd48058ee6472d1449.tar.xz |
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>
Diffstat (limited to 'drivers/tty/nozomi.c')
-rw-r--r-- | drivers/tty/nozomi.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c index bf05946d80a1..675c02c51598 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" |