From patchwork Fri Jul 25 17:48:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Frank_Sch=C3=A4fer?= X-Patchwork-Id: 4625121 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 61B91C0338 for ; Fri, 25 Jul 2014 17:48:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 81ECE20136 for ; Fri, 25 Jul 2014 17:48:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 95A4B20123 for ; Fri, 25 Jul 2014 17:48:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935090AbaGYRsM (ORCPT ); Fri, 25 Jul 2014 13:48:12 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:43741 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935085AbaGYRsL (ORCPT ); Fri, 25 Jul 2014 13:48:11 -0400 Received: by mail-wi0-f180.google.com with SMTP id n3so1408841wiv.1 for ; Fri, 25 Jul 2014 10:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=s8IeJJc90KgysK/V0bjSJejv0nNS/eEfwF36SMa0yxw=; b=q3x12Izt58+kK+jo6hga87ZUnXk9Ctu5ZQ3YA8BHdHl2+TF5IwsTCpOqZB82FtYU1P QLf8Lo2u26FmD0d34dCa55TcIXrP9Uh2h6pBi6oXtrqNh4mEFj6T2NcHrCQV33dpkYhg paxPAvD7hD3CNDupzjYBOj1wHrCE9Ek1GEaalhZhtvQsQ2NGjuytODoXIZjH9f6aGHnU Auvi2tmENZsg2GIrNvVjWEly0uSepRTc38pvNwVsVVGdCG6K63nhKmvb2UO/E1VkyS9Z RFeAh+eK5yUx20TX7vdzG9x7SN0+ZQGOzm4KTQntQiBx107L7r1dsiCOwhaWHm2uNukQ XYgg== X-Received: by 10.194.92.177 with SMTP id cn17mr24324115wjb.71.1406310490485; Fri, 25 Jul 2014 10:48:10 -0700 (PDT) Received: from Athlon64X2-5000.lan (ip-178-201-166-251.hsi08.unitymediagroup.de. [178.201.166.251]) by mx.google.com with ESMTPSA id w5sm8480640wif.3.2014.07.25.10.48.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jul 2014 10:48:09 -0700 (PDT) From: =?UTF-8?q?Frank=20Sch=C3=A4fer?= To: m.chehab@samsung.com Cc: hverkuil@xs4all.nl, linux-media@vger.kernel.org, =?UTF-8?q?Frank=20Sch=C3=A4fer?= Subject: [PATCH 4/4] em28xx-v4l: get rid of field "users" in struct em28xx_v4l2 Date: Fri, 25 Jul 2014 19:48:58 +0200 Message-Id: <1406310538-5001-5-git-send-email-fschaefer.oss@googlemail.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1406310538-5001-1-git-send-email-fschaefer.oss@googlemail.com> References: <1406310538-5001-1-git-send-email-fschaefer.oss@googlemail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of counting the number of opened file handles, use function v4l2_fh_is_singular_file() in em28xx_v4l2_open() and em28xx_v4l2_close() to determine if the file handle is the first/last opened one. Signed-off-by: Frank Schäfer --- drivers/media/usb/em28xx/em28xx-video.c | 23 +++++++++++++---------- drivers/media/usb/em28xx/em28xx.h | 1 - 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c index 3a7ec3b..087ccf9 100644 --- a/drivers/media/usb/em28xx/em28xx-video.c +++ b/drivers/media/usb/em28xx/em28xx-video.c @@ -1883,9 +1883,8 @@ static int em28xx_v4l2_open(struct file *filp) return -EINVAL; } - em28xx_videodbg("open dev=%s type=%s users=%d\n", - video_device_node_name(vdev), v4l2_type_names[fh_type], - v4l2->users); + em28xx_videodbg("open dev=%s type=%s\n", + video_device_node_name(vdev), v4l2_type_names[fh_type]); if (mutex_lock_interruptible(&dev->lock)) return -ERESTARTSYS; @@ -1898,7 +1897,9 @@ static int em28xx_v4l2_open(struct file *filp) return ret; } - if (v4l2->users == 0) { + if (v4l2_fh_is_singular_file(filp)) { + em28xx_videodbg("first opened filehandle, initializing device\n"); + em28xx_set_mode(dev, EM28XX_ANALOG_MODE); if (vdev->vfl_type != VFL_TYPE_RADIO) @@ -1909,6 +1910,8 @@ static int em28xx_v4l2_open(struct file *filp) * of some i2c devices */ em28xx_wake_i2c(dev); + } else { + em28xx_videodbg("further filehandles are already opened\n"); } if (vdev->vfl_type == VFL_TYPE_RADIO) { @@ -1918,7 +1921,6 @@ static int em28xx_v4l2_open(struct file *filp) kref_get(&dev->ref); kref_get(&v4l2->ref); - v4l2->users++; mutex_unlock(&dev->lock); @@ -2025,12 +2027,11 @@ static int em28xx_v4l2_close(struct file *filp) struct em28xx_v4l2 *v4l2 = dev->v4l2; int errCode; - em28xx_videodbg("users=%d\n", v4l2->users); - - vb2_fop_release(filp); mutex_lock(&dev->lock); - if (v4l2->users == 1) { + if (v4l2_fh_is_singular_file(filp)) { + em28xx_videodbg("last opened filehandle, shutting down device\n"); + /* No sense to try to write to the device */ if (dev->disconnected) goto exit; @@ -2049,10 +2050,12 @@ static int em28xx_v4l2_close(struct file *filp) em28xx_errdev("cannot change alternate number to " "0 (error=%i)\n", errCode); } + } else { + em28xx_videodbg("further opened filehandles left\n"); } exit: - v4l2->users--; + vb2_fop_release(filp); kref_put(&v4l2->ref, em28xx_free_v4l2); mutex_unlock(&dev->lock); kref_put(&dev->ref, em28xx_free_device); diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h index 4360338..84ef8ef 100644 --- a/drivers/media/usb/em28xx/em28xx.h +++ b/drivers/media/usb/em28xx/em28xx.h @@ -524,7 +524,6 @@ struct em28xx_v4l2 { int sensor_yres; int sensor_xtal; - int users; /* user count for exclusive use */ int streaming_users; /* number of actively streaming users */ u32 frequency; /* selected tuner frequency */