From patchwork Fri Jan 17 17:18:42 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: 3506371 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 3EE35C02DC for ; Fri, 17 Jan 2014 17:17:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 30D552015E for ; Fri, 17 Jan 2014 17:17:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 312C02015D for ; Fri, 17 Jan 2014 17:17:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752225AbaAQRRr (ORCPT ); Fri, 17 Jan 2014 12:17:47 -0500 Received: from mail-ee0-f47.google.com ([74.125.83.47]:55753 "EHLO mail-ee0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750937AbaAQRRq (ORCPT ); Fri, 17 Jan 2014 12:17:46 -0500 Received: by mail-ee0-f47.google.com with SMTP id d49so1480321eek.6 for ; Fri, 17 Jan 2014 09:17:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=7VRHIkkx1n99KZP0J2d6MAYts1K8BKKbH/dhe+vlcfw=; b=qLCjKK6AFHfvxJZb/VyyvMaWScAryh11boTSUVvniiV9Y8AlAKx0YhmRHmVGULS4I7 yzxR6Vzjf+7le3HM1g37zZDwrDZ9HSXhSJcj39BYXlseI4rdY7JC3gac7C3SbmgF5Cdc y9296Jxj+bXA9zgUijPl5ExH5TxAJjVrVr6B1NLnolQurdpVv6bXQNECWS0EnoiAVbov AEOUK4NnBD0MMCCzU6cuKhpIDb6CCRFuUTNKA2tCYJFjuKREOE5YkAvg3s+sCdFqkjng 0zWCG0zttck6+GbZAPXOi2be/a0g3VkC2ncU+jj0hv/BoHD0Z/+rF07Py5BkwjZNSq9M NO2w== X-Received: by 10.15.110.8 with SMTP id cg8mr3887183eeb.42.1389979065677; Fri, 17 Jan 2014 09:17:45 -0800 (PST) Received: from Athlon64X2-5000.site (ip-178-200-115-160.unitymediagroup.de. [178.200.115.160]) by mx.google.com with ESMTPSA id l41sm28495313eep.17.2014.01.17.09.17.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jan 2014 09:17:45 -0800 (PST) From: =?UTF-8?q?Frank=20Sch=C3=A4fer?= To: m.chehab@samsung.com Cc: linux-media@vger.kernel.org, =?UTF-8?q?Frank=20Sch=C3=A4fer?= Subject: [PATCH 1/2] em28xx-audio: fix user counting in snd_em28xx_capture_open() Date: Fri, 17 Jan 2014 18:18:42 +0100 Message-Id: <1389979123-6919-1-git-send-email-fschaefer.oss@googlemail.com> X-Mailer: git-send-email 1.7.10.4 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=-7.1 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 dev->adev.users always needs to be increased when snd_em28xx_capture_open() is called and succeeds. Signed-off-by: Frank Schäfer --- drivers/media/usb/em28xx/em28xx-audio.c | 22 +++++++++++----------- 1 Datei geändert, 11 Zeilen hinzugefügt(+), 11 Zeilen entfernt(-) diff --git a/drivers/media/usb/em28xx/em28xx-audio.c b/drivers/media/usb/em28xx/em28xx-audio.c index 05e9bd1..dfdfa77 100644 --- a/drivers/media/usb/em28xx/em28xx-audio.c +++ b/drivers/media/usb/em28xx/em28xx-audio.c @@ -252,7 +252,7 @@ static int snd_em28xx_capture_open(struct snd_pcm_substream *substream) { struct em28xx *dev = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; - int ret = 0; + int nonblock, ret = 0; if (!dev) { em28xx_err("BUG: em28xx can't find device struct." @@ -265,15 +265,15 @@ static int snd_em28xx_capture_open(struct snd_pcm_substream *substream) dprintk("opening device and trying to acquire exclusive lock\n"); + nonblock = !!(substream->f_flags & O_NONBLOCK); + if (nonblock) { + if (!mutex_trylock(&dev->lock)) + return -EAGAIN; + } else + mutex_lock(&dev->lock); + runtime->hw = snd_em28xx_hw_capture; if ((dev->alt == 0 || dev->is_audio_only) && dev->adev.users == 0) { - int nonblock = !!(substream->f_flags & O_NONBLOCK); - - if (nonblock) { - if (!mutex_trylock(&dev->lock)) - return -EAGAIN; - } else - mutex_lock(&dev->lock); if (dev->is_audio_only) /* vendor audio is on a separate interface */ dev->alt = 1; @@ -299,11 +299,11 @@ static int snd_em28xx_capture_open(struct snd_pcm_substream *substream) ret = em28xx_audio_analog_set(dev); if (ret < 0) goto err; - - dev->adev.users++; - mutex_unlock(&dev->lock); } + dev->adev.users++; + mutex_unlock(&dev->lock); + /* Dynamically adjust the period size */ snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,