Commit a51482bd authored by Jesper Juhl's avatar Jesper Juhl Committed by David S. Miller
Browse files

[NET]: kfree cleanup



From: Jesper Juhl <jesper.juhl@gmail.com>

This is the net/ part of the big kfree cleanup patch.

Remove pointless checks for NULL prior to calling kfree() in net/.
Signed-off-by: default avatarJesper Juhl <jesper.juhl@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
Acked-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Acked-by: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
parent ac7c98ec
......@@ -54,8 +54,7 @@ struct datalink_proto *make_8023_client(void)
*/
void destroy_8023_client(struct datalink_proto *dl)
{
if (dl)
kfree(dl);
kfree(dl);
}
EXPORT_SYMBOL(destroy_8023_client);
......
......@@ -1138,10 +1138,8 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
sk->sk_state = TCP_CLOSE;
sock->state = SS_UNCONNECTED;
if (ax25->digipeat != NULL) {
kfree(ax25->digipeat);
ax25->digipeat = NULL;
}
kfree(ax25->digipeat);
ax25->digipeat = NULL;
/*
* Handle digi-peaters to be used.
......
......@@ -401,10 +401,8 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
}
if (dp.ndigi == 0) {
if (ax25->digipeat != NULL) {
kfree(ax25->digipeat);
ax25->digipeat = NULL;
}
kfree(ax25->digipeat);
ax25->digipeat = NULL;
} else {
/* Reverse the source SABM's path */
memcpy(ax25->digipeat, &reverse_dp, sizeof(ax25_digi));
......
......@@ -54,15 +54,13 @@ void ax25_rt_device_down(struct net_device *dev)
if (s->dev == dev) {
if (ax25_route_list == s) {
ax25_route_list = s->next;
if (s->digipeat != NULL)
kfree(s->digipeat);
kfree(s->digipeat);
kfree(s);
} else {
for (t = ax25_route_list; t != NULL; t = t->next) {
if (t->next == s) {
t->next = s->next;
if (s->digipeat != NULL)
kfree(s->digipeat);
kfree(s->digipeat);
kfree(s);
break;
}
......@@ -90,10 +88,8 @@ static int ax25_rt_add(struct ax25_routes_struct *route)
while (ax25_rt != NULL) {
if (ax25cmp(&ax25_rt->callsign, &route->dest_addr) == 0 &&
ax25_rt->dev == ax25_dev->dev) {
if (ax25_rt->digipeat != NULL) {
kfree(ax25_rt->digipeat);
ax25_rt->digipeat = NULL;
}
kfree(ax25_rt->digipeat);
ax25_rt->digipeat = NULL;
if (route->digi_count != 0) {
if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
write_unlock(&ax25_route_lock);
......@@ -145,8 +141,7 @@ static int ax25_rt_add(struct ax25_routes_struct *route)
static void ax25_rt_destroy(ax25_route *ax25_rt)
{
if (atomic_read(&ax25_rt->ref) == 0) {
if (ax25_rt->digipeat != NULL)
kfree(ax25_rt->digipeat);
kfree(ax25_rt->digipeat);
kfree(ax25_rt);
return;
}
......@@ -530,9 +525,7 @@ void __exit ax25_rt_free(void)
s = ax25_rt;
ax25_rt = ax25_rt->next;
if (s->digipeat != NULL)
kfree(s->digipeat);
kfree(s->digipeat);
kfree(s);
}
write_unlock(&ax25_route_lock);
......
......@@ -660,9 +660,7 @@ unlink:
failed:
up_write(&hidp_session_sem);
if (session->input)
kfree(session->input);
kfree(session->input);
kfree(session);
return err;
}
......
......@@ -194,8 +194,7 @@ int dev_mc_add(struct net_device *dev, void *addr, int alen, int glbl)
done:
spin_unlock_bh(&dev->xmit_lock);
if (dmi1)
kfree(dmi1);
kfree(dmi1);
return err;
}
......
......@@ -1242,8 +1242,7 @@ static void sock_def_write_space(struct sock *sk)
static void sock_def_destruct(struct sock *sk)
{
if (sk->sk_protinfo)
kfree(sk->sk_protinfo);
kfree(sk->sk_protinfo);
}
void sk_send_sigurg(struct sock *sk)
......
......@@ -1263,10 +1263,8 @@ static int dccp_v4_destroy_sock(struct sock *sk)
if (inet_csk(sk)->icsk_bind_hash != NULL)
inet_put_port(&dccp_hashinfo, sk);
if (dp->dccps_service_list != NULL) {
kfree(dp->dccps_service_list);
dp->dccps_service_list = NULL;
}
kfree(dp->dccps_service_list);
dp->dccps_service_list = NULL;
ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk);
ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk);
......
......@@ -238,8 +238,7 @@ static int dccp_setsockopt_service(struct sock *sk, const u32 service,
lock_sock(sk);
dp->dccps_service = service;
if (dp->dccps_service_list != NULL)
kfree(dp->dccps_service_list);
kfree(dp->dccps_service_list);
dp->dccps_service_list = sl;
release_sock(sk);
......
......@@ -784,16 +784,14 @@ struct dn_fib_table *dn_fib_get_table(int n, int create)
static void dn_fib_del_tree(int n)
{
struct dn_fib_table *t;
struct dn_fib_table *t;
write_lock(&dn_fib_tables_lock);
t = dn_fib_tables[n];
dn_fib_tables[n] = NULL;
write_unlock(&dn_fib_tables_lock);
write_lock(&dn_fib_tables_lock);
t = dn_fib_tables[n];
dn_fib_tables[n] = NULL;
write_unlock(&dn_fib_tables_lock);
if (t) {
kfree(t);
}
kfree(t);
}
struct dn_fib_table *dn_fib_empty_table(void)
......
......@@ -32,8 +32,7 @@ struct datalink_proto *make_EII_client(void)
void destroy_EII_client(struct datalink_proto *dl)
{
if (dl)
kfree(dl);
kfree(dl);
}
EXPORT_SYMBOL(destroy_EII_client);
......
......@@ -147,8 +147,7 @@ void inet_sock_destruct(struct sock *sk)
BUG_TRAP(!sk->sk_wmem_queued);
BUG_TRAP(!sk->sk_forward_alloc);
if (inet->opt)
kfree(inet->opt);
kfree(inet->opt);
dst_release(sk->sk_dst_cache);
sk_refcnt_debug_dec(sk);
}
......
......@@ -266,8 +266,7 @@ int ip_rt_ioctl(unsigned int cmd, void __user *arg)
if (tb)
err = tb->tb_insert(tb, &req.rtm, &rta, &req.nlh, NULL);
}
if (rta.rta_mx)
kfree(rta.rta_mx);
kfree(rta.rta_mx);
}
rtnl_unlock();
return err;
......
......@@ -510,8 +510,7 @@ static int ip_options_get_finish(struct ip_options **optp,
kfree(opt);
return -EINVAL;
}
if (*optp)
kfree(*optp);
kfree(*optp);
*optp = opt;
return 0;
}
......
......@@ -1262,10 +1262,8 @@ int ip_push_pending_frames(struct sock *sk)
out:
inet->cork.flags &= ~IPCORK_OPT;
if (inet->cork.opt) {
kfree(inet->cork.opt);
inet->cork.opt = NULL;
}
kfree(inet->cork.opt);
inet->cork.opt = NULL;
if (inet->cork.rt) {
ip_rt_put(inet->cork.rt);
inet->cork.rt = NULL;
......@@ -1289,10 +1287,8 @@ void ip_flush_pending_frames(struct sock *sk)
kfree_skb(skb);
inet->cork.flags &= ~IPCORK_OPT;
if (inet->cork.opt) {
kfree(inet->cork.opt);
inet->cork.opt = NULL;
}
kfree(inet->cork.opt);
inet->cork.opt = NULL;
if (inet->cork.rt) {
ip_rt_put(inet->cork.rt);
inet->cork.rt = NULL;
......
......@@ -202,8 +202,7 @@ int ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct s
if (ra->sk == sk) {
if (on) {
write_unlock_bh(&ip_ra_lock);
if (new_ra)
kfree(new_ra);
kfree(new_ra);
return -EADDRINUSE;
}
*rap = ra->next;
......@@ -446,8 +445,7 @@ int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
#endif
}
opt = xchg(&inet->opt, opt);
if (opt)
kfree(opt);
kfree(opt);
break;
}
case IP_PKTINFO:
......@@ -828,10 +826,8 @@ int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
err = ip_mc_msfilter(sk, msf, ifindex);
mc_msf_out:
if (msf)
kfree(msf);
if (gsf)
kfree(gsf);
kfree(msf);
kfree(gsf);
break;
}
case IP_ROUTER_ALERT:
......
......@@ -110,8 +110,7 @@ ip_vs_app_inc_new(struct ip_vs_app *app, __u16 proto, __u16 port)
return 0;
out:
if (inc->timeout_table)
kfree(inc->timeout_table);
kfree(inc->timeout_table);
kfree(inc);
return ret;
}
......@@ -136,8 +135,7 @@ ip_vs_app_inc_release(struct ip_vs_app *inc)
list_del(&inc->a_list);
if (inc->timeout_table != NULL)
kfree(inc->timeout_table);
kfree(inc->timeout_table);
kfree(inc);
}
......
......@@ -207,16 +207,12 @@ static void wrandom_select_route(const struct flowi *flp,
decision = mpc->rt;
last_power = mpc->power;
if (last_mpc)
kfree(last_mpc);
kfree(last_mpc);
last_mpc = mpc;
}
if (last_mpc) {
/* concurrent __multipath_flush may lead to !last_mpc */
kfree(last_mpc);
}
/* concurrent __multipath_flush may lead to !last_mpc */
kfree(last_mpc);
decision->u.dst.__use++;
*rp = decision;
......
......@@ -1161,8 +1161,7 @@ static int snmp_parse_mangle(unsigned char *msg,
if (!snmp_object_decode(&ctx, obj)) {
if (*obj) {
if ((*obj)->id)
kfree((*obj)->id);
kfree((*obj)->id);
kfree(*obj);
}
kfree(obj);
......
......@@ -823,8 +823,7 @@ out:
*/
static void tcp_v4_reqsk_destructor(struct request_sock *req)
{
if (inet_rsk(req)->opt)
kfree(inet_rsk(req)->opt);
kfree(inet_rsk(req)->opt);
}
static inline void syn_flood_warning(struct sk_buff *skb)
......
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