Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4518034imm; Tue, 7 Aug 2018 02:58:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfMJdUdhADOA5B0qLKb1GbXFUKBrFq9Ft7OkujBrMmnQ/JIFwJAlykvShuSLgGkLRTo3QWu X-Received: by 2002:a63:ff4d:: with SMTP id s13-v6mr18132383pgk.150.1533635881306; Tue, 07 Aug 2018 02:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533635881; cv=none; d=google.com; s=arc-20160816; b=1DZ6XU9cE87QtMHnPRy8roEQ2M1Hc5ZlF9ivYu9rjnTT6Wt3Gc0Z8nKba+z8MCKEgA 0JfAxYe8dzNLqYcomYJ2m/S4W9f3TH0kU7/hLNqgctKOh9ZpG/gmSjqRh+/iXWzDfhWq 0BWK2TzZZllKTNOOYr0JXqFm60tF8Uhg2eGLgP5pJQqoo+/KsF74w1eYRoi6eEDPVQKB ERC58E1OZg1FdshXIOri2U+aH7d4MYjsnZ8DOO9qEF4Y3BINQUJg5rraRvbFVpPbF6qf Ic/jMgqqaQEUS4JN6sejn48o0oH/Eid0pqDz64J20LhDL5CXAOWtrNRgGbsgEMnO3O2C qIJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=2600SaDnSCl2xBLDeQoYH/9Eo37GW/s+rvzp56iCP1U=; b=MEa4sLc2wF0w9bsoX5oPMv2V389pK0SqJBnF2ZItGKAgay4y7VQ+vj/0NC9BDWU/Jy FPBLvIZy0gEXrY6qDtCLqWGoU8pnhkGiIBDa54MbBbC9PU8tC+gxWuRGVXMdnx2UZako uQem/8+TOS/2H3psR2IcM47Ir+H1qRNQceeYPg+sh4zjr7AmR4rb+/8yssWlMm67IPeh waIqxr2GtxGzwxKpnXrx7rGi9HNo8wl/SQXBEOJPPQLxrL5D92MB5QdMuZ69VdRAN6vw 9NBl4rVB3jQlvz1Qr861oBftkqI4I5fd7h5eIzd3qcVlys3QLduy1JjfqYe1d0jECIZu rdLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vGOIEoSB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c25-v6si1014467pgm.523.2018.08.07.02.57.22; Tue, 07 Aug 2018 02:58:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vGOIEoSB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388665AbeHGMHr (ORCPT + 99 others); Tue, 7 Aug 2018 08:07:47 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:44812 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388099AbeHGMHr (ORCPT ); Tue, 7 Aug 2018 08:07:47 -0400 Received: by mail-yw1-f67.google.com with SMTP id l9-v6so4695640ywc.11 for ; Tue, 07 Aug 2018 02:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2600SaDnSCl2xBLDeQoYH/9Eo37GW/s+rvzp56iCP1U=; b=vGOIEoSBqz8tGkpF3ekm/70yhKMja1mx3WSBA52ZP9W/v+bKd+EicKiqN9vo6icrGf trvnRuJeMt1m1answr+w+0IRvwwhUBcu7t90Mg5kr2jLJWVrasCFFLLQxZzQDNCfD1aB L04tb8zEr1w3BDksb+B5h5LQ6bVYDDbomkar+/w1zV5Y6nmb9TnHW5RkGebFe8DNZ7Tj /QGjrVhoNOW8j5C24ed6712S8ih04wIs5gLgIAQWS7IksMns1Cj7ckEsRwBDrl0ifn+t NGyAKl4KwstKkIUwxaxl0onQcWpVyzSe9vx+H2k/1CH3dkQ8KsoSJ3gdrLgVMX64djGh Ya4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2600SaDnSCl2xBLDeQoYH/9Eo37GW/s+rvzp56iCP1U=; b=WPV2PbtFZbljJkYwDK1qv9F7HfsjnTt9jmzZLNAYrKInQdnT4LOBr4H7cWgEMqRYCz Nk6x4CUilOjckuS4rkI1/gwWSHAT4zM6hbYqz/QHRINvxONa6JP1hraPEQWQ356svFrY iv1VzOeUk18Gu/pRGuj/AQ6pv14K+fDFWD+AGA9tZaj0CWxD9SHC5C511M3dFbEo8a7C qYjm/UOLbsrE8EO5MqX6uflAhnMqn4wA6vvqlzNtA2QUGP/5ZvdJcByjIEBzY4SfDN3F lRisWroD3fEMKU8MmN1S2f7RYDc2ncliEl25aNlr7nIVMbLJ435PYSFEskJmwpWD0VfZ ekSA== X-Gm-Message-State: AOUpUlGXUAKzWICUVqx4pLfc3NH9alNYzPoduapVtf1y9UxI5m+ywK8q oUYxphnqADv1RfyRv/3Dp1JNIA+K9MBOk9T8/mhlww== X-Received: by 2002:a0d:e7c1:: with SMTP id q184-v6mr9365951ywe.435.1533635654023; Tue, 07 Aug 2018 02:54:14 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Tomasz Figa Date: Tue, 7 Aug 2018 18:54:02 +0900 Message-ID: Subject: Re: [PATCH v4 6/6] media: uvcvideo: Move decode processing to process context To: Kieran Bingham Cc: Laurent Pinchart , Linux Media Mailing List , g.liakhovetski@gmx.de, olivier.braun@stereolabs.com, troy.kisky@boundarydevices.com, Randy Dunlap , philipp.zabel@gmail.com, Mauro Carvalho Chehab , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kieran, On Wed, Mar 28, 2018 at 1:47 AM Kieran Bingham wrote: [snip] > @@ -1544,25 +1594,29 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, > */ > static void uvc_uninit_video(struct uvc_streaming *stream, int free_buffers) > { > - struct urb *urb; > - unsigned int i; > + struct uvc_urb *uvc_urb; > > uvc_video_stats_stop(stream); > > - for (i = 0; i < UVC_URBS; ++i) { > - struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; > + /* > + * We must poison the URBs rather than kill them to ensure that even > + * after the completion handler returns, any asynchronous workqueues > + * will be prevented from resubmitting the URBs > + */ > + for_each_uvc_urb(uvc_urb, stream) > + usb_poison_urb(uvc_urb->urb); > > - urb = uvc_urb->urb; > - if (urb == NULL) > - continue; > + flush_workqueue(stream->async_wq); > > - usb_kill_urb(urb); > - usb_free_urb(urb); > + for_each_uvc_urb(uvc_urb, stream) { > + usb_free_urb(uvc_urb->urb); > uvc_urb->urb = NULL; > } > > if (free_buffers) > uvc_free_urb_buffers(stream); > + > + destroy_workqueue(stream->async_wq); In our testing, this function ends up being called twice, if before suspend the camera is streaming and if the camera disconnects between suspend and resume. This is because uvc_video_suspend() calls this function (with free_buffers = 0), but uvc_video_resume() wouldn't call uvc_init_video() due to an earlier failure and uvc_v4l2_release() would end up calling this function again, while the workqueue is already destroyed. The following diff seems to take care of it: 8<~~~ diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index c5e0ab564b1a..6fb890c8ba67 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1493,10 +1493,11 @@ static void uvc_uninit_video(struct uvc_streaming *stream, int free_buffers) uvc_urb->urb = NULL; } - if (free_buffers) + if (free_buffers) { uvc_free_urb_buffers(stream); - - destroy_workqueue(stream->async_wq); + destroy_workqueue(stream->async_wq); + stream->async_wq = NULL; + } } /* @@ -1648,10 +1649,12 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) uvc_video_stats_start(stream); - stream->async_wq = alloc_workqueue("uvcvideo", WQ_UNBOUND | WQ_HIGHPRI, - 0); - if (!stream->async_wq) - return -ENOMEM; + if (!stream->async_wq) { + stream->async_wq = alloc_workqueue("uvcvideo", + WQ_UNBOUND | WQ_HIGHPRI, 0); + if (!stream->async_wq) + return -ENOMEM; + } if (intf->num_altsetting > 1) { struct usb_host_endpoint *best_ep = NULL; ~~~>8 Best regards, Tomasz