aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Genoud <richard.genoud@gmail.com>2009-05-17 07:06:31 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-06-19 14:00:54 -0400
commitc854b5e58f2a564af1428e12cdb183e9b876fa0f (patch)
treeafa5d3568ae8e7b1d07a4e0db20e54db9f55abed
parentf2d46e248a8a825506c21f972fff11e423ff1eea (diff)
Staging: rspiusb.c: break the huge piusb_ioctl function into several ones
This makes the code more readable, makes checkpatch really happy and factorize some code. Signed-off-by: Richard Genoud <richard.genoud@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/staging/rspiusb/rspiusb.c206
1 files changed, 116 insertions, 90 deletions
diff --git a/drivers/staging/rspiusb/rspiusb.c b/drivers/staging/rspiusb/rspiusb.c
index 72241f28bde4..685ab3f33861 100644
--- a/drivers/staging/rspiusb/rspiusb.c
+++ b/drivers/staging/rspiusb/rspiusb.c
@@ -198,6 +198,111 @@ object_null:
198 return retval; 198 return retval;
199} 199}
200 200
201static int pixis_io(struct ioctl_struct *ctrl, struct device_extension *pdx,
202 struct ioctl_struct *arg)
203{
204 unsigned int numToRead = 0;
205 unsigned int totalRead = 0;
206 unsigned char *uBuf;
207 int numbytes;
208 int i;
209
210 uBuf = kmalloc(ctrl->numbytes, GFP_KERNEL);
211 if (!uBuf) {
212 dbg("Alloc for uBuf failed");
213 return 0;
214 }
215 numbytes = (int) ctrl->numbytes;
216 numToRead = (unsigned int) ctrl->numbytes;
217 dbg("numbytes to read = %d", numbytes);
218 dbg("endpoint # %d", ctrl->endpoint);
219
220 if (copy_from_user(uBuf, ctrl->pData, numbytes))
221 dbg("copying ctrl->pData to dummyBuf failed");
222
223 do {
224 i = usb_bulk_msg(pdx->udev, pdx->hEP[ctrl->endpoint],
225 (uBuf + totalRead),
226 /* EP0 can only handle 64 bytes at a time */
227 (numToRead > 64) ? 64 : numToRead,
228 &numbytes, HZ * 10);
229 if (i) {
230 dbg("CMD = %s, Address = 0x%02X",
231 ((uBuf[3] == 0x02) ? "WRITE" : "READ"),
232 uBuf[1]);
233 dbg("Number of bytes Attempted to read = %d",
234 (int)ctrl->numbytes);
235 dbg("Blocking ReadI/O Failed with status %d", i);
236 kfree(uBuf);
237 return -1;
238 }
239 dbg("Pixis EP0 Read %d bytes", numbytes);
240 totalRead += numbytes;
241 numToRead -= numbytes;
242 } while (numToRead);
243
244 memcpy(ctrl->pData, uBuf, totalRead);
245 dbg("Total Bytes Read from PIXIS EP0 = %d", totalRead);
246 ctrl->numbytes = totalRead;
247
248 if (copy_to_user(arg, ctrl, sizeof(struct ioctl_struct)))
249 dbg("copy_to_user failed in IORB");
250
251 kfree(uBuf);
252 return ctrl->numbytes;
253}
254
255static int pixis_io2(struct ioctl_struct *ctrl, struct device_extension *pdx,
256 struct ioctl_struct *arg)
257{
258 unsigned char *uBuf;
259 int numbytes;
260 int i;
261
262 uBuf = kmalloc(ctrl->numbytes, GFP_KERNEL);
263 if (!uBuf) {
264 dbg("Alloc for uBuf failed");
265 return 0;
266 }
267 numbytes = (int) ctrl->numbytes;
268 /* dbg( "numbytes to read = %d", numbytes ); */
269 if (copy_from_user(uBuf, ctrl->pData, numbytes))
270 dbg("copying ctrl->pData to dummyBuf failed");
271
272 i = usb_bulk_msg(pdx->udev, pdx->hEP[ctrl->endpoint],
273 uBuf, numbytes, &numbytes, HZ * 10);
274 if (i) {
275 dbg("Blocking ReadI/O Failed with status %d", i);
276 kfree(uBuf);
277 return -1;
278 }
279 ctrl->numbytes = numbytes;
280 memcpy(ctrl->pData, uBuf, numbytes);
281 if (copy_to_user(arg, ctrl, sizeof(struct ioctl_struct)))
282 dbg("copy_to_user failed in IORB");
283 kfree(uBuf);
284 return ctrl->numbytes;
285}
286
287static int pixel_data(struct ioctl_struct *ctrl, struct device_extension *pdx)
288{
289 int i;
290
291 if (!pdx->gotPixelData)
292 return 0;
293
294 pdx->gotPixelData = 0;
295 ctrl->numbytes = pdx->bulk_in_size_returned;
296 pdx->bulk_in_size_returned -= pdx->frameSize;
297
298 for (i = 0; i < pdx->maplist_numPagesMapped[pdx->active_frame]; i++)
299 SetPageDirty(pdx->sgl[pdx->active_frame][i].page_link);
300
301 pdx->active_frame = ((pdx->active_frame + 1) % pdx->num_frames);
302
303 return ctrl->numbytes;
304}
305
201/** 306/**
202 * piusb_ioctl 307 * piusb_ioctl
203 */ 308 */
@@ -207,12 +312,9 @@ static int piusb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
207 struct device_extension *pdx; 312 struct device_extension *pdx;
208 char dummyCtlBuf[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 313 char dummyCtlBuf[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
209 unsigned long devRB = 0; 314 unsigned long devRB = 0;
210 int i = 0;
211 int err = 0; 315 int err = 0;
212 int retval = 0; 316 int retval = 0;
213 struct ioctl_struct ctrl; 317 struct ioctl_struct ctrl;
214 unsigned char *uBuf;
215 int numbytes = 0;
216 unsigned short controlData = 0; 318 unsigned short controlData = 0;
217 319
218 pdx = (struct device_extension *)file->private_data; 320 pdx = (struct device_extension *)file->private_data;
@@ -292,104 +394,28 @@ static int piusb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
292 return retval; 394 return retval;
293 395
294 case PIUSB_READPIPE: 396 case PIUSB_READPIPE:
295 if (copy_from_user 397 if (copy_from_user(&ctrl, (void __user *)arg,
296 (&ctrl, (void __user *)arg, sizeof(struct ioctl_struct))) 398 sizeof(struct ioctl_struct)))
297 dev_err(&pdx->udev->dev, "copy_from_user failed\n"); 399 dev_err(&pdx->udev->dev, "copy_from_user failed\n");
400
298 switch (ctrl.endpoint) { 401 switch (ctrl.endpoint) {
299 case 0: /* ST133 Pixel Data or PIXIS IO */ 402 case 0: /* ST133 Pixel Data or PIXIS IO */
300 if (pdx->iama == PIXIS_PID) { 403 if (pdx->iama == PIXIS_PID) {
301 unsigned int numToRead = 0; 404 return pixis_io(&ctrl, pdx,
302 unsigned int totalRead = 0; 405 (struct ioctl_struct *)arg);
303 uBuf = kmalloc(ctrl.numbytes, GFP_KERNEL);
304 if (!uBuf) {
305 dbg("Alloc for uBuf failed");
306 return 0;
307 }
308 numbytes = ctrl.numbytes;
309 numToRead = numbytes;
310 dbg("numbytes to read = %d", numbytes);
311 dbg("endpoint # %d", ctrl.endpoint);
312 if (copy_from_user(uBuf, ctrl.pData, numbytes))
313 dbg("copying ctrl.pData to dummyBuf failed");
314 do {
315 i = usb_bulk_msg(pdx->udev, pdx->hEP[ctrl.endpoint], (uBuf + totalRead), (numToRead > 64) ? 64 : numToRead, &numbytes, HZ * 10); /* EP0 can only handle 64 bytes at a time */
316 if (i) {
317 dbg("CMD = %s, Address = 0x%02X", ((uBuf[3] == 0x02) ? "WRITE" : "READ"), uBuf[1]);
318 dbg("Number of bytes Attempted to read = %d", (int)ctrl.numbytes);
319 dbg("Blocking ReadI/O Failed with status %d", i);
320 kfree(uBuf);
321 return -1;
322 }
323 dbg("Pixis EP0 Read %d bytes",
324 numbytes);
325 totalRead += numbytes;
326 numToRead -= numbytes;
327 } while (numToRead);
328 memcpy(ctrl.pData, uBuf, totalRead);
329 dbg("Total Bytes Read from PIXIS EP0 = %d",
330 totalRead);
331 ctrl.numbytes = totalRead;
332 if (copy_to_user
333 ((struct ioctl_struct *) arg, &ctrl,
334 sizeof(struct ioctl_struct)))
335 dbg("copy_to_user failed in IORB");
336 kfree(uBuf);
337 return ctrl.numbytes;
338 } 406 }
339 /* ST133 Pixel Data */ 407 /* ST133 Pixel Data */
340 if (!pdx->gotPixelData)
341 return 0;
342 pdx->gotPixelData = 0;
343 ctrl.numbytes = pdx->bulk_in_size_returned;
344 pdx->bulk_in_size_returned -= pdx->frameSize;
345 for (i = 0; i < pdx->maplist_numPagesMapped[pdx->active_frame]; i++)
346 SetPageDirty(pdx->sgl[pdx->active_frame][i].page_link);
347 pdx->active_frame = ((pdx->active_frame + 1)
348 % pdx->num_frames);
349 return ctrl.numbytes;
350
351 case 1: /* ST133IO */
352 /* fall through */ 408 /* fall through */
353 case 4: /* PIXIS IO */
354 uBuf = kmalloc(ctrl.numbytes, GFP_KERNEL);
355 if (!uBuf) {
356 dbg("Alloc for uBuf failed");
357 return 0;
358 }
359 numbytes = ctrl.numbytes;
360 /* dbg( "numbytes to read = %d", numbytes ); */
361 if (copy_from_user(uBuf, ctrl.pData, numbytes))
362 dbg("copying ctrl.pData to dummyBuf failed");
363 i = usb_bulk_msg(pdx->udev, pdx->hEP[ctrl.endpoint],
364 uBuf, numbytes, &numbytes, HZ * 10);
365 if (i) {
366 dbg("Blocking ReadI/O Failed with status %d",
367 i);
368 kfree(uBuf);
369 return -1;
370 }
371 ctrl.numbytes = numbytes;
372 memcpy(ctrl.pData, uBuf, numbytes);
373 if (copy_to_user((struct ioctl_struct *) arg, &ctrl,
374 sizeof(struct ioctl_struct)))
375 dbg("copy_to_user failed in IORB");
376 kfree(uBuf);
377 return ctrl.numbytes;
378
379 case 2: /* PIXIS Ping */ 409 case 2: /* PIXIS Ping */
380 /* fall through */ 410 /* fall through */
381 case 3: /* PIXIS Pong */ 411 case 3: /* PIXIS Pong */
382 if (!pdx->gotPixelData) 412 return pixel_data(&ctrl, pdx);
383 return 0;
384 pdx->gotPixelData = 0;
385 ctrl.numbytes = pdx->bulk_in_size_returned;
386 pdx->bulk_in_size_returned -= pdx->frameSize;
387 for (i = 0; i < pdx->maplist_numPagesMapped[pdx->active_frame]; i++)
388 SetPageDirty(pdx->sgl[pdx->active_frame][i].page_link);
389 pdx->active_frame =
390 ((pdx->active_frame + 1) % pdx->num_frames);
391 return ctrl.numbytes;
392 413
414 case 1: /* ST133IO */
415 /* fall through */
416 case 4: /* PIXIS IO */
417 return pixis_io2(&ctrl, pdx,
418 (struct ioctl_struct *)arg);
393 default: 419 default:
394 break; 420 break;
395 } 421 }