Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: f_uvc: eliminate abuse of ep->driver data

Since ep->driver_data is not used for endpoint claiming, neither for
enabled/disabled state storing, we can reduce number of places where
we read or modify it's value, as now it has no particular meaning for
function or framework logic.

In case of f_uvc, ep->driver_data was used only for endpoint claiming
and marking endpoints as enabled, so we can simplify code by reducing
it.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>

authored by

Robert Baldyga and committed by
Felipe Balbi
d62bf8c1 887d8206

+8 -34
+8 -34
drivers/usb/gadget/function/f_uvc.c
··· 280 280 else if (interface != uvc->streaming_intf) 281 281 return -EINVAL; 282 282 else 283 - return uvc->video.ep->driver_data ? 1 : 0; 283 + return uvc->video.ep->enabled ? 1 : 0; 284 284 } 285 285 286 286 static int ··· 298 298 if (alt) 299 299 return -EINVAL; 300 300 301 - if (uvc->control_ep->driver_data) { 302 - INFO(cdev, "reset UVC Control\n"); 303 - usb_ep_disable(uvc->control_ep); 304 - uvc->control_ep->driver_data = NULL; 305 - } 301 + INFO(cdev, "reset UVC Control\n"); 302 + usb_ep_disable(uvc->control_ep); 306 303 307 304 if (!uvc->control_ep->desc) 308 305 if (config_ep_by_speed(cdev->gadget, f, uvc->control_ep)) 309 306 return -EINVAL; 310 307 311 308 usb_ep_enable(uvc->control_ep); 312 - uvc->control_ep->driver_data = uvc; 313 309 314 310 if (uvc->state == UVC_STATE_DISCONNECTED) { 315 311 memset(&v4l2_event, 0, sizeof(v4l2_event)); ··· 332 336 if (uvc->state != UVC_STATE_STREAMING) 333 337 return 0; 334 338 335 - if (uvc->video.ep) { 339 + if (uvc->video.ep) 336 340 usb_ep_disable(uvc->video.ep); 337 - uvc->video.ep->driver_data = NULL; 338 - } 339 341 340 342 memset(&v4l2_event, 0, sizeof(v4l2_event)); 341 343 v4l2_event.type = UVC_EVENT_STREAMOFF; ··· 349 355 if (!uvc->video.ep) 350 356 return -EINVAL; 351 357 352 - if (uvc->video.ep->driver_data) { 353 - INFO(cdev, "reset UVC\n"); 354 - usb_ep_disable(uvc->video.ep); 355 - uvc->video.ep->driver_data = NULL; 356 - } 358 + INFO(cdev, "reset UVC\n"); 359 + usb_ep_disable(uvc->video.ep); 357 360 358 361 ret = config_ep_by_speed(f->config->cdev->gadget, 359 362 &(uvc->func), uvc->video.ep); 360 363 if (ret) 361 364 return ret; 362 365 usb_ep_enable(uvc->video.ep); 363 - uvc->video.ep->driver_data = uvc; 364 366 365 367 memset(&v4l2_event, 0, sizeof(v4l2_event)); 366 368 v4l2_event.type = UVC_EVENT_STREAMON; ··· 382 392 383 393 uvc->state = UVC_STATE_DISCONNECTED; 384 394 385 - if (uvc->video.ep->driver_data) { 386 - usb_ep_disable(uvc->video.ep); 387 - uvc->video.ep->driver_data = NULL; 388 - } 389 - 390 - if (uvc->control_ep->driver_data) { 391 - usb_ep_disable(uvc->control_ep); 392 - uvc->control_ep->driver_data = NULL; 393 - } 395 + usb_ep_disable(uvc->video.ep); 396 + usb_ep_disable(uvc->control_ep); 394 397 } 395 398 396 399 /* -------------------------------------------------------------------------- ··· 634 651 goto error; 635 652 } 636 653 uvc->control_ep = ep; 637 - ep->driver_data = uvc; 638 654 639 655 if (gadget_is_superspeed(c->cdev->gadget)) 640 656 ep = usb_ep_autoconfig_ss(cdev->gadget, &uvc_ss_streaming_ep, ··· 648 666 goto error; 649 667 } 650 668 uvc->video.ep = ep; 651 - ep->driver_data = uvc; 652 669 653 670 uvc_fs_streaming_ep.bEndpointAddress = uvc->video.ep->address; 654 671 uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address; ··· 735 754 736 755 error: 737 756 v4l2_device_unregister(&uvc->v4l2_dev); 738 - 739 - if (uvc->control_ep) 740 - uvc->control_ep->driver_data = NULL; 741 - if (uvc->video.ep) 742 - uvc->video.ep->driver_data = NULL; 743 757 744 758 if (uvc->control_req) 745 759 usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); ··· 862 886 863 887 video_unregister_device(&uvc->vdev); 864 888 v4l2_device_unregister(&uvc->v4l2_dev); 865 - uvc->control_ep->driver_data = NULL; 866 - uvc->video.ep->driver_data = NULL; 867 889 868 890 usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); 869 891 kfree(uvc->control_buf);