From patchwork Mon May 21 10:24:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Zabel X-Patchwork-Id: 10414591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F88B60365 for ; Mon, 21 May 2018 10:25:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F74128701 for ; Mon, 21 May 2018 10:25:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 041B8287D4; Mon, 21 May 2018 10:25:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 688A128701 for ; Mon, 21 May 2018 10:25:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750978AbeEUKZs (ORCPT ); Mon, 21 May 2018 06:25:48 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:39849 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750948AbeEUKZr (ORCPT ); Mon, 21 May 2018 06:25:47 -0400 Received: by mail-wr0-f193.google.com with SMTP id w18-v6so11703499wrn.6 for ; Mon, 21 May 2018 03:25:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=5C72WqXAARqAl519W3qJSY94TIQqIctZXPzNWnNbGtU=; b=K4LhqEWKGMENUzUvCSwPXmxPyaQ3jvAS/r2R5vv8WtcOFB0jGE0ut4YZkqZC2ixcRU xJ7RH+N0YSIhNXN8dRvk68oZ/pIgktdMEUogPuo1LkxX+LHHWWsg07/UUzx68g2MV6/k qtQ0VCP7P/QQ5vLRqlm+qtgwdApUuwPpQzxQ1326NvPZehWhUvvcurd4j7NmZ2YNVugK p1pqWGAmZST3tIX7+qpT4FHlm+3wfwYScq+rfM/i8pPqAQo+ISg+/lidMkFEqjCjQRXi A6dcWRBdIrnRRd8TGD1RNp/aV2fsIQnM6UlbEpITpPJ1xRvk8w+aqTUAVa8MooJBydVu Zapw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=5C72WqXAARqAl519W3qJSY94TIQqIctZXPzNWnNbGtU=; b=LCvqLtBuVBWinWe9khC8MJScjiaWIYynPG9Pc0zcHe0qiaKu2WRU9iUar6AZo/Io/p YCUsjpfdinzq9zmcQbf+rxZhWhc8e6QYpvG2RzpEbhYdRlo8jkG1yek3R9R6iW4eRGs2 UJhS+rJtY/COwTJZQl+c6Lj7ydzBcr30amIUTBA90s7NyIAiHeMl5kU3cn9cTLExl3D8 W9PPY5/Fi9HVC57hGOSAiRXjM0NZ5oZPlns7bYGn7oZ8gCiaYXVVfgqS57lA60/Z/9dy EBNmJLdWhvChQSI+xUTE0nh/aW/W0D3kubDBuWhbxwcfmNHzmY+ex1cJbYu/f5eYid9Q eFAA== X-Gm-Message-State: ALKqPweslTbfobxQhIq0pw03cNDKstq8PF3xtlfEz5hunZcrIxI2C84r KMl/4i3liqbp1iDrwhT+Wz8= X-Google-Smtp-Source: AB8JxZr1ushuK1Nw2wnnSlW+JkoKllXio5AJG/fyT9Yb0h4iAEgLFH3UmW1lNi3TfYNqnW4n5Le1Ug== X-Received: by 2002:adf:a299:: with SMTP id s25-v6mr8897648wra.114.1526898345945; Mon, 21 May 2018 03:25:45 -0700 (PDT) Received: from ped.lan (ip1f12fa6a.dynamic.kabel-deutschland.de. [31.18.250.106]) by smtp.googlemail.com with ESMTPSA id p35-v6sm22490754wrb.12.2018.05.21.03.25.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 May 2018 03:25:45 -0700 (PDT) From: Philipp Zabel To: Laurent Pinchart Cc: Guennadi Liakhovetski , linux-media@vger.kernel.org, Philipp Zabel Subject: [PATCH] media: uvcvideo: Fix driver reference counting Date: Mon, 21 May 2018 12:24:58 +0200 Message-Id: <20180521102458.3288-1-philipp.zabel@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP kref_init initializes the reference count to 1, not 0. This additional reference is never released since the conversion to reference counters. As a result, uvc_delete is not called anymore when UVC cameras are disconnected. Fix this by adding an additional kref_put in uvc_disconnect and in the probe error path. This also allows to remove the temporary additional reference in uvc_unregister_video. Fixes: 9d15cd958c17 ("media: uvcvideo: Convert from using an atomic variable to a reference count") Signed-off-by: Philipp Zabel Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_driver.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 2469b49b2b30..8e138201330f 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1871,13 +1871,6 @@ static void uvc_unregister_video(struct uvc_device *dev) { struct uvc_streaming *stream; - /* Unregistering all video devices might result in uvc_delete() being - * called from inside the loop if there's no open file handle. To avoid - * that, increment the refcount before iterating over the streams and - * decrement it when done. - */ - kref_get(&dev->ref); - list_for_each_entry(stream, &dev->streams, list) { if (!video_is_registered(&stream->vdev)) continue; @@ -1887,8 +1880,6 @@ static void uvc_unregister_video(struct uvc_device *dev) uvc_debugfs_cleanup_stream(stream); } - - kref_put(&dev->ref, uvc_delete); } int uvc_register_video_device(struct uvc_device *dev, @@ -2184,6 +2175,7 @@ static int uvc_probe(struct usb_interface *intf, error: uvc_unregister_video(dev); + kref_put(&dev->ref, uvc_delete); return -ENODEV; } @@ -2201,6 +2193,7 @@ static void uvc_disconnect(struct usb_interface *intf) return; uvc_unregister_video(dev); + kref_put(&dev->ref, uvc_delete); } static int uvc_suspend(struct usb_interface *intf, pm_message_t message)