9pnet: trans_fd : allocate struct p9_trans_fd and struct p9_conn together.

There is no point in allocating these structs separately.
Changing this makes the code a little simpler and saves a few bytes of
memory.

Reported-by: Herve Vico
Signed-off-by: Simon Derr <simon.derr@bull.net>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
This commit is contained in:
Simon Derr 2014-03-11 10:13:09 +01:00 committed by Eric Van Hensbergen
parent 7b4f307276
commit 263c582888

View file

@ -66,20 +66,6 @@ struct p9_fd_opts {
int privport; int privport;
}; };
/**
* struct p9_trans_fd - transport state
* @rd: reference to file to read from
* @wr: reference of file to write to
* @conn: connection state reference
*
*/
struct p9_trans_fd {
struct file *rd;
struct file *wr;
struct p9_conn *conn;
};
/* /*
* Option Parsing (code inspired by NFS code) * Option Parsing (code inspired by NFS code)
* - a little lazy - parse all fd-transport options * - a little lazy - parse all fd-transport options
@ -159,6 +145,20 @@ struct p9_conn {
unsigned long wsched; unsigned long wsched;
}; };
/**
* struct p9_trans_fd - transport state
* @rd: reference to file to read from
* @wr: reference of file to write to
* @conn: connection state reference
*
*/
struct p9_trans_fd {
struct file *rd;
struct file *wr;
struct p9_conn conn;
};
static void p9_poll_workfn(struct work_struct *work); static void p9_poll_workfn(struct work_struct *work);
static DEFINE_SPINLOCK(p9_poll_lock); static DEFINE_SPINLOCK(p9_poll_lock);
@ -569,21 +569,19 @@ p9_pollwait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p)
} }
/** /**
* p9_conn_create - allocate and initialize the per-session mux data * p9_conn_create - initialize the per-session mux data
* @client: client instance * @client: client instance
* *
* Note: Creates the polling task if this is the first session. * Note: Creates the polling task if this is the first session.
*/ */
static struct p9_conn *p9_conn_create(struct p9_client *client) static void p9_conn_create(struct p9_client *client)
{ {
int n; int n;
struct p9_conn *m; struct p9_trans_fd *ts = client->trans;
struct p9_conn *m = &ts->conn;
p9_debug(P9_DEBUG_TRANS, "client %p msize %d\n", client, client->msize); p9_debug(P9_DEBUG_TRANS, "client %p msize %d\n", client, client->msize);
m = kzalloc(sizeof(struct p9_conn), GFP_KERNEL);
if (!m)
return ERR_PTR(-ENOMEM);
INIT_LIST_HEAD(&m->mux_list); INIT_LIST_HEAD(&m->mux_list);
m->client = client; m->client = client;
@ -605,8 +603,6 @@ static struct p9_conn *p9_conn_create(struct p9_client *client)
p9_debug(P9_DEBUG_TRANS, "mux %p can write\n", m); p9_debug(P9_DEBUG_TRANS, "mux %p can write\n", m);
set_bit(Wpending, &m->wsched); set_bit(Wpending, &m->wsched);
} }
return m;
} }
/** /**
@ -665,7 +661,7 @@ static int p9_fd_request(struct p9_client *client, struct p9_req_t *req)
{ {
int n; int n;
struct p9_trans_fd *ts = client->trans; struct p9_trans_fd *ts = client->trans;
struct p9_conn *m = ts->conn; struct p9_conn *m = &ts->conn;
p9_debug(P9_DEBUG_TRANS, "mux %p task %p tcall %p id %d\n", p9_debug(P9_DEBUG_TRANS, "mux %p task %p tcall %p id %d\n",
m, current, req->tc, req->tc->id); m, current, req->tc, req->tc->id);
@ -788,7 +784,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
static int p9_fd_open(struct p9_client *client, int rfd, int wfd) static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
{ {
struct p9_trans_fd *ts = kmalloc(sizeof(struct p9_trans_fd), struct p9_trans_fd *ts = kzalloc(sizeof(struct p9_trans_fd),
GFP_KERNEL); GFP_KERNEL);
if (!ts) if (!ts)
return -ENOMEM; return -ENOMEM;
@ -814,9 +810,8 @@ static int p9_socket_open(struct p9_client *client, struct socket *csocket)
{ {
struct p9_trans_fd *p; struct p9_trans_fd *p;
struct file *file; struct file *file;
int ret;
p = kmalloc(sizeof(struct p9_trans_fd), GFP_KERNEL); p = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL);
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
@ -837,20 +832,12 @@ static int p9_socket_open(struct p9_client *client, struct socket *csocket)
p->rd->f_flags |= O_NONBLOCK; p->rd->f_flags |= O_NONBLOCK;
p->conn = p9_conn_create(client); p9_conn_create(client);
if (IS_ERR(p->conn)) {
ret = PTR_ERR(p->conn);
p->conn = NULL;
kfree(p);
sockfd_put(csocket);
sockfd_put(csocket);
return ret;
}
return 0; return 0;
} }
/** /**
* p9_mux_destroy - cancels all pending requests and frees mux resources * p9_mux_destroy - cancels all pending requests of mux
* @m: mux to destroy * @m: mux to destroy
* *
*/ */
@ -867,7 +854,6 @@ static void p9_conn_destroy(struct p9_conn *m)
p9_conn_cancel(m, -ECONNRESET); p9_conn_cancel(m, -ECONNRESET);
m->client = NULL; m->client = NULL;
kfree(m);
} }
/** /**
@ -889,7 +875,7 @@ static void p9_fd_close(struct p9_client *client)
client->status = Disconnected; client->status = Disconnected;
p9_conn_destroy(ts->conn); p9_conn_destroy(&ts->conn);
if (ts->rd) if (ts->rd)
fput(ts->rd); fput(ts->rd);
@ -1041,14 +1027,7 @@ p9_fd_create(struct p9_client *client, const char *addr, char *args)
return err; return err;
p = (struct p9_trans_fd *) client->trans; p = (struct p9_trans_fd *) client->trans;
p->conn = p9_conn_create(client); p9_conn_create(client);
if (IS_ERR(p->conn)) {
err = PTR_ERR(p->conn);
p->conn = NULL;
fput(p->rd);
fput(p->wr);
return err;
}
return 0; return 0;
} }