mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-01 08:04:22 +08:00
rds: tcp: cleanup if kmem_cache_alloc fails in rds_tcp_conn_alloc()
If kmem_cache_alloc() fails in the middle of the for() loop, cleanup anything that might have been allocated so far. Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com> Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
b319109396
commit
66261da169
@ -270,16 +270,33 @@ static int rds_tcp_laddr_check(struct net *net, __be32 addr)
|
|||||||
return -EADDRNOTAVAIL;
|
return -EADDRNOTAVAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void rds_tcp_conn_free(void *arg)
|
||||||
|
{
|
||||||
|
struct rds_tcp_connection *tc = arg;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
rdsdebug("freeing tc %p\n", tc);
|
||||||
|
|
||||||
|
spin_lock_irqsave(&rds_tcp_conn_lock, flags);
|
||||||
|
if (!tc->t_tcp_node_detached)
|
||||||
|
list_del(&tc->t_tcp_node);
|
||||||
|
spin_unlock_irqrestore(&rds_tcp_conn_lock, flags);
|
||||||
|
|
||||||
|
kmem_cache_free(rds_tcp_conn_slab, tc);
|
||||||
|
}
|
||||||
|
|
||||||
static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp)
|
static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp)
|
||||||
{
|
{
|
||||||
struct rds_tcp_connection *tc;
|
struct rds_tcp_connection *tc;
|
||||||
int i;
|
int i, j;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
for (i = 0; i < RDS_MPATH_WORKERS; i++) {
|
for (i = 0; i < RDS_MPATH_WORKERS; i++) {
|
||||||
tc = kmem_cache_alloc(rds_tcp_conn_slab, gfp);
|
tc = kmem_cache_alloc(rds_tcp_conn_slab, gfp);
|
||||||
if (!tc)
|
if (!tc) {
|
||||||
return -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
mutex_init(&tc->t_conn_path_lock);
|
mutex_init(&tc->t_conn_path_lock);
|
||||||
tc->t_sock = NULL;
|
tc->t_sock = NULL;
|
||||||
tc->t_tinc = NULL;
|
tc->t_tinc = NULL;
|
||||||
@ -296,22 +313,11 @@ static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp)
|
|||||||
rdsdebug("rds_conn_path [%d] tc %p\n", i,
|
rdsdebug("rds_conn_path [%d] tc %p\n", i,
|
||||||
conn->c_path[i].cp_transport_data);
|
conn->c_path[i].cp_transport_data);
|
||||||
}
|
}
|
||||||
|
if (ret) {
|
||||||
return 0;
|
for (j = 0; j < i; j++)
|
||||||
}
|
rds_tcp_conn_free(conn->c_path[j].cp_transport_data);
|
||||||
|
}
|
||||||
static void rds_tcp_conn_free(void *arg)
|
return ret;
|
||||||
{
|
|
||||||
struct rds_tcp_connection *tc = arg;
|
|
||||||
unsigned long flags;
|
|
||||||
rdsdebug("freeing tc %p\n", tc);
|
|
||||||
|
|
||||||
spin_lock_irqsave(&rds_tcp_conn_lock, flags);
|
|
||||||
if (!tc->t_tcp_node_detached)
|
|
||||||
list_del(&tc->t_tcp_node);
|
|
||||||
spin_unlock_irqrestore(&rds_tcp_conn_lock, flags);
|
|
||||||
|
|
||||||
kmem_cache_free(rds_tcp_conn_slab, tc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool list_has_conn(struct list_head *list, struct rds_connection *conn)
|
static bool list_has_conn(struct list_head *list, struct rds_connection *conn)
|
||||||
|
Loading…
Reference in New Issue
Block a user