diff options
author | Simon Derr <simon.derr@bull.net> | 2014-03-11 05:13:09 -0400 |
---|---|---|
committer | Eric Van Hensbergen <ericvh@gmail.com> | 2014-03-25 17:38:17 -0400 |
commit | 263c582888d3cd2a5c8e32225140723ec31f1709 (patch) | |
tree | 65875d5c0fcf78a842221d7a01bdc0c902ca5590 /net/9p | |
parent | 7b4f307276ae3f69fc4d7c4fb6a188c906755d98 (diff) |
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>
Diffstat (limited to 'net/9p')
-rw-r--r-- | net/9p/trans_fd.c | 71 |
1 files changed, 25 insertions, 46 deletions
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 9c806428e91a..80d08f6664cb 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c | |||
@@ -66,20 +66,6 @@ struct p9_fd_opts { | |||
66 | int privport; | 66 | int privport; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | /** | ||
70 | * struct p9_trans_fd - transport state | ||
71 | * @rd: reference to file to read from | ||
72 | * @wr: reference of file to write to | ||
73 | * @conn: connection state reference | ||
74 | * | ||
75 | */ | ||
76 | |||
77 | struct p9_trans_fd { | ||
78 | struct file *rd; | ||
79 | struct file *wr; | ||
80 | struct p9_conn *conn; | ||
81 | }; | ||
82 | |||
83 | /* | 69 | /* |
84 | * Option Parsing (code inspired by NFS code) | 70 | * Option Parsing (code inspired by NFS code) |
85 | * - a little lazy - parse all fd-transport options | 71 | * - a little lazy - parse all fd-transport options |
@@ -159,6 +145,20 @@ struct p9_conn { | |||
159 | unsigned long wsched; | 145 | unsigned long wsched; |
160 | }; | 146 | }; |
161 | 147 | ||
148 | /** | ||
149 | * struct p9_trans_fd - transport state | ||
150 | * @rd: reference to file to read from | ||
151 | * @wr: reference of file to write to | ||
152 | * @conn: connection state reference | ||
153 | * | ||
154 | */ | ||
155 | |||
156 | struct p9_trans_fd { | ||
157 | struct file *rd; | ||
158 | struct file *wr; | ||
159 | struct p9_conn conn; | ||
160 | }; | ||
161 | |||
162 | static void p9_poll_workfn(struct work_struct *work); | 162 | static void p9_poll_workfn(struct work_struct *work); |
163 | 163 | ||
164 | static DEFINE_SPINLOCK(p9_poll_lock); | 164 | static DEFINE_SPINLOCK(p9_poll_lock); |
@@ -569,21 +569,19 @@ p9_pollwait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p) | |||
569 | } | 569 | } |
570 | 570 | ||
571 | /** | 571 | /** |
572 | * p9_conn_create - allocate and initialize the per-session mux data | 572 | * p9_conn_create - initialize the per-session mux data |
573 | * @client: client instance | 573 | * @client: client instance |
574 | * | 574 | * |
575 | * Note: Creates the polling task if this is the first session. | 575 | * Note: Creates the polling task if this is the first session. |
576 | */ | 576 | */ |
577 | 577 | ||
578 | static struct p9_conn *p9_conn_create(struct p9_client *client) | 578 | static void p9_conn_create(struct p9_client *client) |
579 | { | 579 | { |
580 | int n; | 580 | int n; |
581 | struct p9_conn *m; | 581 | struct p9_trans_fd *ts = client->trans; |
582 | struct p9_conn *m = &ts->conn; | ||
582 | 583 | ||
583 | p9_debug(P9_DEBUG_TRANS, "client %p msize %d\n", client, client->msize); | 584 | p9_debug(P9_DEBUG_TRANS, "client %p msize %d\n", client, client->msize); |
584 | m = kzalloc(sizeof(struct p9_conn), GFP_KERNEL); | ||
585 | if (!m) | ||
586 | return ERR_PTR(-ENOMEM); | ||
587 | 585 | ||
588 | INIT_LIST_HEAD(&m->mux_list); | 586 | INIT_LIST_HEAD(&m->mux_list); |
589 | m->client = client; | 587 | m->client = client; |
@@ -605,8 +603,6 @@ static struct p9_conn *p9_conn_create(struct p9_client *client) | |||
605 | p9_debug(P9_DEBUG_TRANS, "mux %p can write\n", m); | 603 | p9_debug(P9_DEBUG_TRANS, "mux %p can write\n", m); |
606 | set_bit(Wpending, &m->wsched); | 604 | set_bit(Wpending, &m->wsched); |
607 | } | 605 | } |
608 | |||
609 | return m; | ||
610 | } | 606 | } |
611 | 607 | ||
612 | /** | 608 | /** |
@@ -665,7 +661,7 @@ static int p9_fd_request(struct p9_client *client, struct p9_req_t *req) | |||
665 | { | 661 | { |
666 | int n; | 662 | int n; |
667 | struct p9_trans_fd *ts = client->trans; | 663 | struct p9_trans_fd *ts = client->trans; |
668 | struct p9_conn *m = ts->conn; | 664 | struct p9_conn *m = &ts->conn; |
669 | 665 | ||
670 | p9_debug(P9_DEBUG_TRANS, "mux %p task %p tcall %p id %d\n", | 666 | p9_debug(P9_DEBUG_TRANS, "mux %p task %p tcall %p id %d\n", |
671 | m, current, req->tc, req->tc->id); | 667 | m, current, req->tc, req->tc->id); |
@@ -788,7 +784,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts) | |||
788 | 784 | ||
789 | static int p9_fd_open(struct p9_client *client, int rfd, int wfd) | 785 | static int p9_fd_open(struct p9_client *client, int rfd, int wfd) |
790 | { | 786 | { |
791 | struct p9_trans_fd *ts = kmalloc(sizeof(struct p9_trans_fd), | 787 | struct p9_trans_fd *ts = kzalloc(sizeof(struct p9_trans_fd), |
792 | GFP_KERNEL); | 788 | GFP_KERNEL); |
793 | if (!ts) | 789 | if (!ts) |
794 | return -ENOMEM; | 790 | return -ENOMEM; |
@@ -814,9 +810,8 @@ static int p9_socket_open(struct p9_client *client, struct socket *csocket) | |||
814 | { | 810 | { |
815 | struct p9_trans_fd *p; | 811 | struct p9_trans_fd *p; |
816 | struct file *file; | 812 | struct file *file; |
817 | int ret; | ||
818 | 813 | ||
819 | p = kmalloc(sizeof(struct p9_trans_fd), GFP_KERNEL); | 814 | p = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL); |
820 | if (!p) | 815 | if (!p) |
821 | return -ENOMEM; | 816 | return -ENOMEM; |
822 | 817 | ||
@@ -837,20 +832,12 @@ static int p9_socket_open(struct p9_client *client, struct socket *csocket) | |||
837 | 832 | ||
838 | p->rd->f_flags |= O_NONBLOCK; | 833 | p->rd->f_flags |= O_NONBLOCK; |
839 | 834 | ||
840 | p->conn = p9_conn_create(client); | 835 | p9_conn_create(client); |
841 | if (IS_ERR(p->conn)) { | ||
842 | ret = PTR_ERR(p->conn); | ||
843 | p->conn = NULL; | ||
844 | kfree(p); | ||
845 | sockfd_put(csocket); | ||
846 | sockfd_put(csocket); | ||
847 | return ret; | ||
848 | } | ||
849 | return 0; | 836 | return 0; |
850 | } | 837 | } |
851 | 838 | ||
852 | /** | 839 | /** |
853 | * p9_mux_destroy - cancels all pending requests and frees mux resources | 840 | * p9_mux_destroy - cancels all pending requests of mux |
854 | * @m: mux to destroy | 841 | * @m: mux to destroy |
855 | * | 842 | * |
856 | */ | 843 | */ |
@@ -867,7 +854,6 @@ static void p9_conn_destroy(struct p9_conn *m) | |||
867 | p9_conn_cancel(m, -ECONNRESET); | 854 | p9_conn_cancel(m, -ECONNRESET); |
868 | 855 | ||
869 | m->client = NULL; | 856 | m->client = NULL; |
870 | kfree(m); | ||
871 | } | 857 | } |
872 | 858 | ||
873 | /** | 859 | /** |
@@ -889,7 +875,7 @@ static void p9_fd_close(struct p9_client *client) | |||
889 | 875 | ||
890 | client->status = Disconnected; | 876 | client->status = Disconnected; |
891 | 877 | ||
892 | p9_conn_destroy(ts->conn); | 878 | p9_conn_destroy(&ts->conn); |
893 | 879 | ||
894 | if (ts->rd) | 880 | if (ts->rd) |
895 | fput(ts->rd); | 881 | fput(ts->rd); |
@@ -1041,14 +1027,7 @@ p9_fd_create(struct p9_client *client, const char *addr, char *args) | |||
1041 | return err; | 1027 | return err; |
1042 | 1028 | ||
1043 | p = (struct p9_trans_fd *) client->trans; | 1029 | p = (struct p9_trans_fd *) client->trans; |
1044 | p->conn = p9_conn_create(client); | 1030 | p9_conn_create(client); |
1045 | if (IS_ERR(p->conn)) { | ||
1046 | err = PTR_ERR(p->conn); | ||
1047 | p->conn = NULL; | ||
1048 | fput(p->rd); | ||
1049 | fput(p->wr); | ||
1050 | return err; | ||
1051 | } | ||
1052 | 1031 | ||
1053 | return 0; | 1032 | return 0; |
1054 | } | 1033 | } |