Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1007959pxb; Wed, 1 Sep 2021 15:09:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8r/njz2liG/sH3ixfy4Wj760hRPvyoknOmi5OJE9SmQPPGfyuJxxsQkRnPcZwwlyoWj1a X-Received: by 2002:a05:6e02:928:: with SMTP id o8mr1154796ilt.37.1630534141568; Wed, 01 Sep 2021 15:09:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630534141; cv=none; d=google.com; s=arc-20160816; b=z5INhcHo+lqJfbor6jotusgsVRg2zjIFZfI4MB1Rb2mG+J6nBhazMVOoCF5pmhgB7d 6EqsNLXD1oBMHMkDUG0QgdcSTMiALREPdt4NwHXnHNMmSXoyGb3OD/ShqL8kGSY0qEEk l4gtpGaouvGJ1B2ICDXD6TRgNycqkw2i8tY+hBPxP1rHwmi2VzE7RPFdY5rpnH1eNjGN wlxZguK3lFX8jenEiotJqPbS4C1GdOQ1SdmGtmtBxd3J1eF98OZSUHHYDwgmtYIhNXIQ pwMmkde4ITkc4ZL2zmxLkG0io+ExjF5cfgVMpXmH1+i/gApP5A6c2YgBUx4meiLt8XNF WGOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=QB28QXaTuKd/PkL52ssrT1OvX5TeWKYDtWZRsL2UHO4=; b=qvIzQHz8u9OkXirRTJw6OjC8QpqWCS5hb2eMgvuWn9C5Vq4NtXO2Q6ElY86KCu2CTR TXtuinueM51I2KA45dcLs9zFPrjXP+btvcxeV1+YF2yU4P4XeeNa2yr/sTHf1Enovhba uTkv4lGSJatVI9lfY95SvB7mq44GwmOfV3FHshBoy6RXWGlmSPJOEVlqw+2sHAEoMwo6 MuY+LFI8KcnvyLfWcgAq2TLolSRk3IOr2VPp6Z/2S9Ejut5ybLd0IbE4DaEx3Z/UoGWJ UxpsVsjHLBgWi0YvpScdlaukj9GAq4/wxr8AZPjQjZjNuDK46gaTR2yUpg5sn6oG/c1q QYbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a17si727592jal.14.2021.09.01.15.08.49; Wed, 01 Sep 2021 15:09:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345258AbhIAMwQ (ORCPT + 99 others); Wed, 1 Sep 2021 08:52:16 -0400 Received: from mx20.baidu.com ([111.202.115.85]:43616 "EHLO baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1345514AbhIAMrz (ORCPT ); Wed, 1 Sep 2021 08:47:55 -0400 Received: from BC-Mail-Ex22.internal.baidu.com (unknown [172.31.51.16]) by Forcepoint Email with ESMTPS id 9975EBDFBB94475CD40E; Wed, 1 Sep 2021 20:46:56 +0800 (CST) Received: from BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) by BC-Mail-Ex22.internal.baidu.com (172.31.51.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.12; Wed, 1 Sep 2021 20:46:56 +0800 Received: from LAPTOP-UKSR4ENP.internal.baidu.com (172.31.63.8) by BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Wed, 1 Sep 2021 20:46:56 +0800 From: Cai Huoqing To: CC: Mauro Carvalho Chehab , , Subject: [PATCH v3] usb: stkwebcam: Update the reference count of the usb device structure Date: Wed, 1 Sep 2021 20:46:49 +0800 Message-ID: <20210901124650.31653-1-caihuoqing@baidu.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.31.63.8] X-ClientProxiedBy: BJHW-Mail-Ex07.internal.baidu.com (10.127.64.17) To BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use usb_get_dev() to increment the reference count of the usb device structure in order to avoid releasing the structure while it is still in use. And use usb_put_dev() to decrement the reference count and thus, when it will be equal to 0 the structure will be released. Signed-off-by: Cai Huoqing --- v2->v3: *call usb_put_dev() in the error path of stk_camera_probe *move v4l2_ctrl_handler_free/v4l2_device_unregister/kfree(dev) from stk_camera_disconnect() to stk_v4l_dev_release() drivers/media/usb/stkwebcam/stk-webcam.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c index 0e231e576dc3..9f445e6ab5fa 100644 --- a/drivers/media/usb/stkwebcam/stk-webcam.c +++ b/drivers/media/usb/stkwebcam/stk-webcam.c @@ -1234,6 +1234,11 @@ static void stk_v4l_dev_release(struct video_device *vd) if (dev->sio_bufs != NULL || dev->isobufs != NULL) pr_err("We are leaking memory\n"); usb_put_intf(dev->interface); + usb_put_dev(dev->udev); + + v4l2_ctrl_handler_free(&dev->hdl); + v4l2_device_unregister(&dev->v4l2_dev); + kfree(dev); } static const struct video_device stk_v4l_data = { @@ -1309,7 +1314,7 @@ static int stk_camera_probe(struct usb_interface *interface, init_waitqueue_head(&dev->wait_frame); dev->first_init = 1; /* webcam LED management */ - dev->udev = udev; + dev->udev = usb_get_dev(udev); dev->interface = interface; usb_get_intf(interface); @@ -1365,6 +1370,7 @@ static int stk_camera_probe(struct usb_interface *interface, error_put: usb_put_intf(interface); + usb_put_dev(dev->udev); error: v4l2_ctrl_handler_free(hdl); v4l2_device_unregister(&dev->v4l2_dev); @@ -1385,9 +1391,6 @@ static void stk_camera_disconnect(struct usb_interface *interface) video_device_node_name(&dev->vdev)); video_unregister_device(&dev->vdev); - v4l2_ctrl_handler_free(&dev->hdl); - v4l2_device_unregister(&dev->v4l2_dev); - kfree(dev); } #ifdef CONFIG_PM -- 2.25.1