Commit ae001dc6 authored by Matthew Wood's avatar Matthew Wood Committed by David S. Miller

net: netconsole: move newline trimming to function

Move newline trimming logic from `dev_name_store()` to a new function
(trim_newline()) for shared use in netconsole.c
Signed-off-by: default avatarMatthew Wood <thepacketgeek@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bd9c69a3
...@@ -230,6 +230,16 @@ static struct netconsole_target *to_target(struct config_item *item) ...@@ -230,6 +230,16 @@ static struct netconsole_target *to_target(struct config_item *item)
struct netconsole_target, group); struct netconsole_target, group);
} }
/* Get rid of possible trailing newline, returning the new length */
static void trim_newline(char *s, size_t maxlen)
{
size_t len;
len = strnlen(s, maxlen);
if (s[len - 1] == '\n')
s[len - 1] = '\0';
}
/* /*
* Attribute operations for netconsole_target. * Attribute operations for netconsole_target.
*/ */
...@@ -424,7 +434,6 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf, ...@@ -424,7 +434,6 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf,
size_t count) size_t count)
{ {
struct netconsole_target *nt = to_target(item); struct netconsole_target *nt = to_target(item);
size_t len;
mutex_lock(&dynamic_netconsole_mutex); mutex_lock(&dynamic_netconsole_mutex);
if (nt->enabled) { if (nt->enabled) {
...@@ -435,11 +444,7 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf, ...@@ -435,11 +444,7 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf,
} }
strscpy(nt->np.dev_name, buf, IFNAMSIZ); strscpy(nt->np.dev_name, buf, IFNAMSIZ);
trim_newline(nt->np.dev_name, IFNAMSIZ);
/* Get rid of possible trailing newline from echo(1) */
len = strnlen(nt->np.dev_name, IFNAMSIZ);
if (nt->np.dev_name[len - 1] == '\n')
nt->np.dev_name[len - 1] = '\0';
mutex_unlock(&dynamic_netconsole_mutex); mutex_unlock(&dynamic_netconsole_mutex);
return strnlen(buf, count); return strnlen(buf, count);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment