Commit e8666130 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Jakub Kicinski

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: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Tested-by: default avatarMichael Walle <michael@walle.cc>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 94793a56
...@@ -79,7 +79,7 @@ const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops) ...@@ -79,7 +79,7 @@ const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
/* Function takes a reference on the module owning the tagger, /* Function takes a reference on the module owning the tagger,
* so dsa_tag_driver_put must be called afterwards. * so dsa_tag_driver_put must be called afterwards.
*/ */
const struct dsa_device_ops *dsa_find_tagger_by_name(const char *buf) const struct dsa_device_ops *dsa_find_tagger_by_name(const char *name)
{ {
const struct dsa_device_ops *ops = ERR_PTR(-ENOPROTOOPT); const struct dsa_device_ops *ops = ERR_PTR(-ENOPROTOOPT);
struct dsa_tag_driver *dsa_tag_driver; struct dsa_tag_driver *dsa_tag_driver;
...@@ -88,7 +88,7 @@ const struct dsa_device_ops *dsa_find_tagger_by_name(const char *buf) ...@@ -88,7 +88,7 @@ const struct dsa_device_ops *dsa_find_tagger_by_name(const char *buf)
list_for_each_entry(dsa_tag_driver, &dsa_tag_drivers_list, list) { list_for_each_entry(dsa_tag_driver, &dsa_tag_drivers_list, list) {
const struct dsa_device_ops *tmp = dsa_tag_driver->ops; const struct dsa_device_ops *tmp = dsa_tag_driver->ops;
if (!sysfs_streq(buf, tmp->name)) if (strcmp(name, tmp->name))
continue; continue;
if (!try_module_get(dsa_tag_driver->owner)) if (!try_module_get(dsa_tag_driver->owner))
......
...@@ -245,7 +245,7 @@ struct dsa_slave_priv { ...@@ -245,7 +245,7 @@ struct dsa_slave_priv {
/* dsa.c */ /* dsa.c */
const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol); const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol);
void dsa_tag_driver_put(const struct dsa_device_ops *ops); void dsa_tag_driver_put(const struct dsa_device_ops *ops);
const struct dsa_device_ops *dsa_find_tagger_by_name(const char *buf); const struct dsa_device_ops *dsa_find_tagger_by_name(const char *name);
bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b); bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b);
......
...@@ -299,12 +299,23 @@ static ssize_t tagging_store(struct device *d, struct device_attribute *attr, ...@@ -299,12 +299,23 @@ static ssize_t tagging_store(struct device *d, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
const struct dsa_device_ops *new_tag_ops, *old_tag_ops; 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 net_device *dev = to_net_dev(d);
struct dsa_port *cpu_dp = dev->dsa_ptr; struct dsa_port *cpu_dp = dev->dsa_ptr;
size_t len = end - buf;
int err; 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; 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? */ /* Bad tagger name, or module is not loaded? */
if (IS_ERR(new_tag_ops)) if (IS_ERR(new_tag_ops))
return PTR_ERR(new_tag_ops); return PTR_ERR(new_tag_ops);
......
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