Skip to content

Commit

Permalink
batman-adv: only call post function if something changed
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Marek Lindner <[email protected]>
Signed-off-by: Antonio Quartulli <[email protected]>
  • Loading branch information
Simon Wunderlich authored and ordex committed Jan 9, 2016
1 parent e1544f3 commit 9e728e8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions net/batman-adv/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,13 @@ ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \

static int batadv_store_bool_attr(char *buff, size_t count,
struct net_device *net_dev,
const char *attr_name, atomic_t *attr)
const char *attr_name, atomic_t *attr,
bool *changed)
{
int enabled = -1;

*changed = false;

if (buff[count - 1] == '\n')
buff[count - 1] = '\0';

Expand All @@ -272,6 +275,8 @@ static int batadv_store_bool_attr(char *buff, size_t count,
atomic_read(attr) == 1 ? "enabled" : "disabled",
enabled == 1 ? "enabled" : "disabled");

*changed = true;

atomic_set(attr, (unsigned int)enabled);
return count;
}
Expand All @@ -282,11 +287,12 @@ __batadv_store_bool_attr(char *buff, size_t count,
struct attribute *attr,
atomic_t *attr_store, struct net_device *net_dev)
{
bool changed;
int ret;

ret = batadv_store_bool_attr(buff, count, net_dev, attr->name,
attr_store);
if (post_func && ret)
attr_store, &changed);
if (post_func && changed)
post_func(net_dev);

return ret;
Expand Down

0 comments on commit 9e728e8

Please sign in to comment.