From: Markus Elfring elfring@users.sourceforge.net Date: Sun, 15 Nov 2015 09:34:12 +0100
Another update suggestion was taken into account after a patch was applied from static source code analysis.
Markus Elfring (2): Delete unnecessary checks before the function call "kfree_skb" Less checks in batadv_tvlv_unicast_send()
net/batman-adv/main.c | 15 +++++---------- net/batman-adv/network-coding.c | 4 +--- net/batman-adv/send.c | 3 +-- 3 files changed, 7 insertions(+), 15 deletions(-)
From: Markus Elfring elfring@users.sourceforge.net Date: Sun, 15 Nov 2015 08:04:43 +0100
The kfree_skb() function tests whether its argument is NULL and then returns immediately. Thus the test around the calls is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- net/batman-adv/main.c | 2 +- net/batman-adv/network-coding.c | 4 +--- net/batman-adv/send.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index d7f17c1..9e9b8f6 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -1184,7 +1184,7 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src, ret = true;
out: - if (skb && !ret) + if (!ret) kfree_skb(skb); if (orig_node) batadv_orig_node_free_ref(orig_node); diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c index f5276be..c98b0ab 100644 --- a/net/batman-adv/network-coding.c +++ b/net/batman-adv/network-coding.c @@ -244,9 +244,7 @@ static void batadv_nc_path_free_ref(struct batadv_nc_path *nc_path) */ static void batadv_nc_packet_free(struct batadv_nc_packet *nc_packet) { - if (nc_packet->skb) - kfree_skb(nc_packet->skb); - + kfree_skb(nc_packet->skb); batadv_nc_path_free_ref(nc_packet->nc_path); kfree(nc_packet); } diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c index f664324..782fa33 100644 --- a/net/batman-adv/send.c +++ b/net/batman-adv/send.c @@ -407,8 +407,7 @@ void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface)
static void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet) { - if (forw_packet->skb) - kfree_skb(forw_packet->skb); + kfree_skb(forw_packet->skb); if (forw_packet->if_incoming) batadv_hardif_free_ref(forw_packet->if_incoming); if (forw_packet->if_outgoing)
On Sunday, November 15, 2015 09:43:26 SF Markus Elfring wrote:
From: Markus Elfring elfring@users.sourceforge.net Date: Sun, 15 Nov 2015 08:04:43 +0100
The kfree_skb() function tests whether its argument is NULL and then returns immediately. Thus the test around the calls is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net
net/batman-adv/main.c | 2 +- net/batman-adv/network-coding.c | 4 +--- net/batman-adv/send.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-)
Applied in revision 77d84a6.
Thanks, Marek
From: Markus Elfring elfring@users.sourceforge.net Date: Sun, 15 Nov 2015 09:00:42 +0100
* Let us return directly if a call of the batadv_orig_hash_find() function returned a null pointer.
* Omit the initialisation for the variable "skb" at the beginning.
* Replace an assignment by a call of the kfree_skb() function and delete the affected variable "ret" then.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- net/batman-adv/main.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index 9e9b8f6..4eaa09a 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -1143,15 +1143,14 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src, struct batadv_unicast_tvlv_packet *unicast_tvlv_packet; struct batadv_tvlv_hdr *tvlv_hdr; struct batadv_orig_node *orig_node; - struct sk_buff *skb = NULL; + struct sk_buff *skb; unsigned char *tvlv_buff; unsigned int tvlv_len; ssize_t hdr_len = sizeof(*unicast_tvlv_packet); - bool ret = false;
orig_node = batadv_orig_hash_find(bat_priv, dst); if (!orig_node) - goto out; + return;
tvlv_len = sizeof(*tvlv_hdr) + tvlv_value_len;
@@ -1180,14 +1179,10 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src, tvlv_buff += sizeof(*tvlv_hdr); memcpy(tvlv_buff, tvlv_value, tvlv_value_len);
- if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP) - ret = true; - -out: - if (!ret) + if (batadv_send_skb_to_orig(skb, orig_node, NULL) == NET_XMIT_DROP) kfree_skb(skb); - if (orig_node) - batadv_orig_node_free_ref(orig_node); +out: + batadv_orig_node_free_ref(orig_node); }
/**
On Sunday, November 15, 2015 09:45:51 SF Markus Elfring wrote:
From: Markus Elfring elfring@users.sourceforge.net Date: Sun, 15 Nov 2015 09:00:42 +0100
Let us return directly if a call of the batadv_orig_hash_find() function returned a null pointer.
Omit the initialisation for the variable "skb" at the beginning.
Replace an assignment by a call of the kfree_skb() function and delete the affected variable "ret" then.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net
net/batman-adv/main.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
Applied in revision 5a878b8.
Thanks, Marek
b.a.t.m.a.n@lists.open-mesh.org