summaryrefslogtreecommitdiff
path: root/net/dsa/master.c
diff options
context:
space:
mode:
authorVladimir Oltean <vladimir.oltean@nxp.com>2022-11-15 03:18:45 +0200
committerJakub Kicinski <kuba@kernel.org>2022-11-17 21:16:42 -0800
commite8666130b995a6a1a99c319d33fae2046213c39b (patch)
tree3787020961d1255b11386d9fe32a9ef232868417 /net/dsa/master.c
parent94793a56b3df0ff2b8c5680f926c19effd8b9ccc (diff)
downloadlwn-e8666130b995a6a1a99c319d33fae2046213c39b.tar.gz
lwn-e8666130b995a6a1a99c319d33fae2046213c39b.zip
net: dsa: strip sysfs "tagging" string of trailing newline
Currently, dsa_find_tagger_by_name() uses sysfs_streq() which works both with strings that contain \n at the end (echo ocelot > .../dsa/tagging) and with strings that don't (printf ocelot > .../dsa/tagging). There will be a problem once we'll want to construct the modalias string based on which we auto-load the protocol kernel module. If the sysfs buffer ends in a newline, we need to strip it first. This is a preparatory patch specifically for that. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Tested-by: Michael Walle <michael@walle.cc> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/dsa/master.c')
-rw-r--r--net/dsa/master.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/net/dsa/master.c b/net/dsa/master.c
index 421de166515f..f443bf4a3c8c 100644
--- a/net/dsa/master.c
+++ b/net/dsa/master.c
@@ -299,12 +299,23 @@ static ssize_t tagging_store(struct device *d, struct device_attribute *attr,
const char *buf, size_t count)
{
const struct dsa_device_ops *new_tag_ops, *old_tag_ops;
+ const char *end = strchrnul(buf, '\n'), *name;
struct net_device *dev = to_net_dev(d);
struct dsa_port *cpu_dp = dev->dsa_ptr;
+ size_t len = end - buf;
int err;
+ /* Empty string passed */
+ if (!len)
+ return -ENOPROTOOPT;
+
+ name = kstrndup(buf, len, GFP_KERNEL);
+ if (!name)
+ return -ENOMEM;
+
old_tag_ops = cpu_dp->tag_ops;
- new_tag_ops = dsa_find_tagger_by_name(buf);
+ new_tag_ops = dsa_find_tagger_by_name(name);
+ kfree(name);
/* Bad tagger name, or module is not loaded? */
if (IS_ERR(new_tag_ops))
return PTR_ERR(new_tag_ops);