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

usb: gadget: uvc: move video disable logic to its own function

This patch refactors the video disable logic in uvcg_video_enable
into its own separate function 'uvcg_video_disable'. This function
is now used anywhere uvcg_video_enable(video, 0) was used.

Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Suggested-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Avichal Rakesh <arakesh@google.com>
Link: https://lore.kernel.org/r/20231109004104.3467968-3-arakesh@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Avichal Rakesh and committed by
Greg Kroah-Hartman
2079b60b aeb686a9

+34 -21
+3 -3
drivers/usb/gadget/function/uvc_v4l2.c
··· 443 443 return -EINVAL; 444 444 445 445 /* Enable UVC video. */ 446 - ret = uvcg_video_enable(video, 1); 446 + ret = uvcg_video_enable(video); 447 447 if (ret < 0) 448 448 return ret; 449 449 ··· 469 469 return -EINVAL; 470 470 471 471 uvc->state = UVC_STATE_CONNECTED; 472 - ret = uvcg_video_enable(video, 0); 472 + ret = uvcg_video_disable(video); 473 473 if (ret < 0) 474 474 return ret; 475 475 ··· 515 515 if (uvc->state == UVC_STATE_STREAMING) 516 516 uvc->state = UVC_STATE_CONNECTED; 517 517 518 - uvcg_video_enable(&uvc->video, 0); 518 + uvcg_video_disable(&uvc->video); 519 519 uvcg_free_buffers(&uvc->video.queue); 520 520 uvc->func_connected = false; 521 521 wake_up_interruptible(&uvc->func_connected_queue);
+29 -17
drivers/usb/gadget/function/uvc_video.c
··· 493 493 } 494 494 495 495 /* 496 - * Enable or disable the video stream. 496 + * Disable the video stream 497 497 */ 498 - int uvcg_video_enable(struct uvc_video *video, int enable) 498 + int 499 + uvcg_video_disable(struct uvc_video *video) 500 + { 501 + struct uvc_request *ureq; 502 + 503 + if (video->ep == NULL) { 504 + uvcg_info(&video->uvc->func, 505 + "Video disable failed, device is uninitialized.\n"); 506 + return -ENODEV; 507 + } 508 + 509 + cancel_work_sync(&video->pump); 510 + uvcg_queue_cancel(&video->queue, 0); 511 + 512 + list_for_each_entry(ureq, &video->ureqs, list) { 513 + if (ureq->req) 514 + usb_ep_dequeue(video->ep, ureq->req); 515 + } 516 + 517 + uvc_video_free_requests(video); 518 + uvcg_queue_enable(&video->queue, 0); 519 + return 0; 520 + } 521 + 522 + /* 523 + * Enable the video stream. 524 + */ 525 + int uvcg_video_enable(struct uvc_video *video) 499 526 { 500 527 int ret; 501 - struct uvc_request *ureq; 502 528 503 529 if (video->ep == NULL) { 504 530 uvcg_info(&video->uvc->func, 505 531 "Video enable failed, device is uninitialized.\n"); 506 532 return -ENODEV; 507 - } 508 - 509 - if (!enable) { 510 - cancel_work_sync(&video->pump); 511 - uvcg_queue_cancel(&video->queue, 0); 512 - 513 - list_for_each_entry(ureq, &video->ureqs, list) { 514 - if (ureq->req) 515 - usb_ep_dequeue(video->ep, ureq->req); 516 - } 517 - 518 - uvc_video_free_requests(video); 519 - uvcg_queue_enable(&video->queue, 0); 520 - return 0; 521 533 } 522 534 523 535 if ((ret = uvcg_queue_enable(&video->queue, 1)) < 0)
+2 -1
drivers/usb/gadget/function/uvc_video.h
··· 14 14 15 15 struct uvc_video; 16 16 17 - int uvcg_video_enable(struct uvc_video *video, int enable); 17 + int uvcg_video_enable(struct uvc_video *video); 18 + int uvcg_video_disable(struct uvc_video *video); 18 19 19 20 int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc); 20 21