Skip to content

Commit dc0b98a

Browse files
committed
ethtool: Add and use ethnl_update_bool.
Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7a98143 commit dc0b98a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

net/ethtool/mm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ int ethnl_set_mm(struct sk_buff *skb, struct genl_info *info)
225225
ethnl_update_u32(&cfg.verify_time, tb[ETHTOOL_A_MM_VERIFY_TIME], &mod);
226226
ethnl_update_bool(&cfg.tx_enabled, tb[ETHTOOL_A_MM_TX_ENABLED], &mod);
227227
ethnl_update_bool(&cfg.pmac_enabled, tb[ETHTOOL_A_MM_PMAC_ENABLED],
228-
&mod);
228+
&mod);
229229
ethnl_update_u32(&cfg.tx_min_frag_size,
230230
tb[ETHTOOL_A_MM_TX_MIN_FRAG_SIZE], &mod);
231231

net/ethtool/netlink.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,32 @@ static inline void ethnl_update_bool32(u32 *dst, const struct nlattr *attr,
137137
*mod = true;
138138
}
139139

140+
/**
141+
* ethnl_update_bool() - updateb bool used as bool from NLA_U8 attribute
142+
* @dst: value to update
143+
* @attr: netlink attribute with new value or null
144+
* @mod: pointer to bool for modification tracking
145+
*
146+
* Use the bool value from NLA_U8 netlink attribute @attr to set bool variable
147+
* pointed to by @dst to 0 (if zero) or 1 (if not); do nothing if @attr is
148+
* null. Bool pointed to by @mod is set to true if this function changed the
149+
* logical value of *dst, otherwise it is left as is.
150+
*/
151+
static inline void ethnl_update_bool(bool *dst, const struct nlattr *attr,
152+
bool *mod)
153+
{
154+
u8 val;
155+
156+
if (!attr)
157+
return;
158+
val = !!nla_get_u8(attr);
159+
if (!!*dst == val)
160+
return;
161+
162+
*dst = val;
163+
*mod = true;
164+
}
165+
140166
/**
141167
* ethnl_update_binary() - update binary data from NLA_BINARY attribute
142168
* @dst: value to update

0 commit comments

Comments
 (0)