Commit fb5ca8131c4c94745a42d618701392bc74fd22a7

Authored by matt mooney
Committed by Greg Kroah-Hartman
1 parent 756d6726f8

staging: usbip: userspace: usbip_network.c: coding style cleanup

Change messges to debug, and fix a few coding style issues.

Signed-off-by: matt mooney <mfm@muteddisk.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 1 changed file with 42 additions and 31 deletions Side-by-side Diff

drivers/staging/usbip/userspace/src/usbip_network.c
1 1 /*
  2 + * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
  3 + * 2005-2007 Takahiro Hirofuchi
2 4 *
3   - * Copyright (C) 2005-2007 Takahiro Hirofuchi
  5 + * This program is free software: you can redistribute it and/or modify
  6 + * it under the terms of the GNU General Public License as published by
  7 + * the Free Software Foundation, either version 2 of the License, or
  8 + * (at your option) any later version.
  9 + *
  10 + * This program is distributed in the hope that it will be useful,
  11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 + * GNU General Public License for more details.
  14 + *
  15 + * You should have received a copy of the GNU General Public License
  16 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4 17 */
5 18  
6 19 #include <sys/socket.h>
7 20  
8 21  
... ... @@ -56,17 +69,15 @@
56 69 /* uint8_t members need nothing */
57 70 }
58 71  
59   -
60 72 static ssize_t usbip_xmit(int sockfd, void *buff, size_t bufflen, int sending)
61 73 {
  74 + ssize_t nbytes;
62 75 ssize_t total = 0;
63 76  
64 77 if (!bufflen)
65 78 return 0;
66 79  
67 80 do {
68   - ssize_t nbytes;
69   -
70 81 if (sending)
71 82 nbytes = send(sockfd, buff, bufflen, 0);
72 83 else
73 84  
... ... @@ -75,13 +86,12 @@
75 86 if (nbytes <= 0)
76 87 return -1;
77 88  
78   - buff = (void *) ((intptr_t) buff + nbytes);
  89 + buff = (void *)((intptr_t) buff + nbytes);
79 90 bufflen -= nbytes;
80 91 total += nbytes;
81 92  
82 93 } while (bufflen > 0);
83 94  
84   -
85 95 return total;
86 96 }
87 97  
88 98  
... ... @@ -97,8 +107,8 @@
97 107  
98 108 int usbip_send_op_common(int sockfd, uint32_t code, uint32_t status)
99 109 {
100   - int ret;
101 110 struct op_common op_common;
  111 + int rc;
102 112  
103 113 memset(&op_common, 0, sizeof(op_common));
104 114  
... ... @@ -108,9 +118,9 @@
108 118  
109 119 PACK_OP_COMMON(1, &op_common);
110 120  
111   - ret = usbip_send(sockfd, (void *) &op_common, sizeof(op_common));
112   - if (ret < 0) {
113   - err("usbip_send has failed");
  121 + rc = usbip_send(sockfd, &op_common, sizeof(op_common));
  122 + if (rc < 0) {
  123 + dbg("usbip_send failed: %d", rc);
114 124 return -1;
115 125 }
116 126  
117 127  
118 128  
119 129  
120 130  
121 131  
... ... @@ -119,36 +129,38 @@
119 129  
120 130 int usbip_recv_op_common(int sockfd, uint16_t *code)
121 131 {
122   - int ret;
123 132 struct op_common op_common;
  133 + int rc;
124 134  
125 135 memset(&op_common, 0, sizeof(op_common));
126 136  
127   - ret = usbip_recv(sockfd, (void *) &op_common, sizeof(op_common));
128   - if (ret < 0) {
129   - err("usbip_recv has failed ret=%d", ret);
  137 + rc = usbip_recv(sockfd, &op_common, sizeof(op_common));
  138 + if (rc < 0) {
  139 + dbg("usbip_recv failed: %d", rc);
130 140 goto err;
131 141 }
132 142  
133 143 PACK_OP_COMMON(0, &op_common);
134 144  
135 145 if (op_common.version != USBIP_VERSION) {
136   - err("version mismatch, %d %d", op_common.version, USBIP_VERSION);
  146 + dbg("version mismatch: %d %d", op_common.version,
  147 + USBIP_VERSION);
137 148 goto err;
138 149 }
139 150  
140   - switch(*code) {
141   - case OP_UNSPEC:
142   - break;
143   - default:
144   - if (op_common.code != *code) {
145   - info("unexpected pdu %d for %d", op_common.code, *code);
146   - goto err;
147   - }
  151 + switch (*code) {
  152 + case OP_UNSPEC:
  153 + break;
  154 + default:
  155 + if (op_common.code != *code) {
  156 + dbg("unexpected pdu %#0x for %#0x", op_common.code,
  157 + *code);
  158 + goto err;
  159 + }
148 160 }
149 161  
150 162 if (op_common.status != ST_OK) {
151   - info("request failed at peer, %d", op_common.status);
  163 + dbg("request failed at peer: %d", op_common.status);
152 164 goto err;
153 165 }
154 166  
... ... @@ -159,7 +171,6 @@
159 171 return -1;
160 172 }
161 173  
162   -
163 174 int usbip_set_reuseaddr(int sockfd)
164 175 {
165 176 const int val = 1;
... ... @@ -167,7 +178,7 @@
167 178  
168 179 ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
169 180 if (ret < 0)
170   - err("setsockopt SO_REUSEADDR");
  181 + dbg("setsockopt: SO_REUSEADDR");
171 182  
172 183 return ret;
173 184 }
... ... @@ -179,7 +190,7 @@
179 190  
180 191 ret = setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
181 192 if (ret < 0)
182   - err("setsockopt TCP_NODELAY");
  193 + dbg("setsockopt: TCP_NODELAY");
183 194  
184 195 return ret;
185 196 }
... ... @@ -191,7 +202,7 @@
191 202  
192 203 ret = setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
193 204 if (ret < 0)
194   - err("setsockopt SO_KEEPALIVE");
  205 + dbg("setsockopt: SO_KEEPALIVE");
195 206  
196 207 return ret;
197 208 }
... ... @@ -199,7 +210,7 @@
199 210 /*
200 211 * IPv6 Ready
201 212 */
202   -int usbip_net_tcp_connect(char *hostname, char *port)
  213 +int usbip_net_tcp_connect(char *hostname, char *service)
203 214 {
204 215 struct addrinfo hints, *res, *rp;
205 216 int sockfd;
206 217  
... ... @@ -210,9 +221,9 @@
210 221 hints.ai_socktype = SOCK_STREAM;
211 222  
212 223 /* get all possible addresses */
213   - ret = getaddrinfo(hostname, port, &hints, &res);
  224 + ret = getaddrinfo(hostname, service, &hints, &res);
214 225 if (ret < 0) {
215   - dbg("getaddrinfo: %s port %s: %s", hostname, port,
  226 + dbg("getaddrinfo: %s service %s: %s", hostname, service,
216 227 gai_strerror(ret));
217 228 return ret;
218 229 }