Skip to content

Commit

Permalink
[NET]: kfree cleanup
Browse files Browse the repository at this point in the history
From: Jesper Juhl <[email protected]>

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: Jesper Juhl <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Acked-by: Marcel Holtmann <[email protected]>
Acked-by: YOSHIFUJI Hideaki <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Jesper Juhl authored and davem330 committed Nov 8, 2005
1 parent ac7c98e commit a51482b
Show file tree
Hide file tree
Showing 47 changed files with 99 additions and 191 deletions.
3 changes: 1 addition & 2 deletions net/802/p8023.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions net/ax25/ax25_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
19 changes: 6 additions & 13 deletions net/ax25/ax25_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions net/bluetooth/hidp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,7 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock,
failed:
up_write(&hidp_session_sem);

if (session->input)
kfree(session->input);

kfree(session->input);
kfree(session);
return err;
}
Expand Down
3 changes: 1 addition & 2 deletions net/core/dev_mcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions net/dccp/ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions net/dccp/proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions net/decnet/dn_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions net/ethernet/pe2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/fib_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/ip_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 4 additions & 8 deletions net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 4 additions & 8 deletions net/ipv4/ip_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions net/ipv4/ipvs/ip_vs_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down
10 changes: 3 additions & 7 deletions net/ipv4/multipath_wrandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/netfilter/ip_nat_snmp_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/tcp_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,7 @@ static int tcp_v4_send_synack(struct sock *sk, struct request_sock *req,
*/
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)
Expand Down
3 changes: 1 addition & 2 deletions net/ipv6/addrconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3090,8 +3090,7 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,

nlmsg_failure:
rtattr_failure:
if (array)
kfree(array);
kfree(array);
skb_trim(skb, b - skb->data);
return -1;
}
Expand Down
15 changes: 5 additions & 10 deletions net/ipv6/ip6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
skb->next = NULL;
}

if (tmp_hdr)
kfree(tmp_hdr);
kfree(tmp_hdr);

if (err == 0) {
IP6_INC_STATS(IPSTATS_MIB_FRAGOKS);
Expand Down Expand Up @@ -1186,10 +1185,8 @@ int ip6_push_pending_frames(struct sock *sk)

out:
inet->cork.flags &= ~IPCORK_OPT;
if (np->cork.opt) {
kfree(np->cork.opt);
np->cork.opt = NULL;
}
kfree(np->cork.opt);
np->cork.opt = NULL;
if (np->cork.rt) {
dst_release(&np->cork.rt->u.dst);
np->cork.rt = NULL;
Expand All @@ -1214,10 +1211,8 @@ void ip6_flush_pending_frames(struct sock *sk)

inet->cork.flags &= ~IPCORK_OPT;

if (np->cork.opt) {
kfree(np->cork.opt);
np->cork.opt = NULL;
}
kfree(np->cork.opt);
np->cork.opt = NULL;
if (np->cork.rt) {
dst_release(&np->cork.rt->u.dst);
np->cork.rt = NULL;
Expand Down
6 changes: 2 additions & 4 deletions net/ipv6/ip6_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
}
ip6_tnl_dst_store(t, dst);

if (opt)
kfree(opt);
kfree(opt);

t->recursion--;
return 0;
Expand All @@ -766,8 +765,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
dst_link_failure(skb);
tx_err_dst_release:
dst_release(dst);
if (opt)
kfree(opt);
kfree(opt);
tx_err:
stats->tx_errors++;
stats->tx_dropped++;
Expand Down
3 changes: 1 addition & 2 deletions net/ipv6/ipcomp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ static int ipcomp6_input(struct xfrm_state *x, struct xfrm_decap_state *decap, s
out_put_cpu:
put_cpu();
out:
if (tmp_hdr)
kfree(tmp_hdr);
kfree(tmp_hdr);
if (err)
goto error_out;
return nexthdr;
Expand Down
Loading

0 comments on commit a51482b

Please sign in to comment.