batman-adv: only call post function if something changed

Currently, the post function is also called on errors or if there were
no changes, which is redundant for the functions currently using these
facilities.

Signed-off-by: Simon Wunderlich <simon@open-mesh.com>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
This commit is contained in:
Simon Wunderlich
2015-11-17 14:11:26 +01:00
committed by Antonio Quartulli
parent e1544f3c87
commit 9e728e8438
+9 -3
View File
@@ -242,10 +242,13 @@ ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \
static int batadv_store_bool_attr(char *buff, size_t count, static int batadv_store_bool_attr(char *buff, size_t count,
struct net_device *net_dev, struct net_device *net_dev,
const char *attr_name, atomic_t *attr) const char *attr_name, atomic_t *attr,
bool *changed)
{ {
int enabled = -1; int enabled = -1;
*changed = false;
if (buff[count - 1] == '\n') if (buff[count - 1] == '\n')
buff[count - 1] = '\0'; buff[count - 1] = '\0';
@@ -272,6 +275,8 @@ static int batadv_store_bool_attr(char *buff, size_t count,
atomic_read(attr) == 1 ? "enabled" : "disabled", atomic_read(attr) == 1 ? "enabled" : "disabled",
enabled == 1 ? "enabled" : "disabled"); enabled == 1 ? "enabled" : "disabled");
*changed = true;
atomic_set(attr, (unsigned int)enabled); atomic_set(attr, (unsigned int)enabled);
return count; return count;
} }
@@ -282,11 +287,12 @@ __batadv_store_bool_attr(char *buff, size_t count,
struct attribute *attr, struct attribute *attr,
atomic_t *attr_store, struct net_device *net_dev) atomic_t *attr_store, struct net_device *net_dev)
{ {
bool changed;
int ret; int ret;
ret = batadv_store_bool_attr(buff, count, net_dev, attr->name, ret = batadv_store_bool_attr(buff, count, net_dev, attr->name,
attr_store); attr_store, &changed);
if (post_func && ret) if (post_func && changed)
post_func(net_dev); post_func(net_dev);
return ret; return ret;