From patchwork Fri Nov 19 23:43:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?RGF2aWQgSMODwqRyZGVtYW4=?= X-Patchwork-Id: 343731 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAJNikee022891 for ; Fri, 19 Nov 2010 23:44:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757622Ab0KSXop (ORCPT ); Fri, 19 Nov 2010 18:44:45 -0500 Received: from 1-1-12-13a.han.sth.bostream.se ([82.182.30.168]:33751 "EHLO palpatine.hardeman.nu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757201Ab0KSXon (ORCPT ); Fri, 19 Nov 2010 18:44:43 -0500 Received: from basil.haag.hardeman.nu (host-88-217-225-61.customer.m-online.net [88.217.225.61]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by palpatine.hardeman.nu (Postfix) with ESMTPSA id C4A0D1A87; Sat, 20 Nov 2010 00:44:41 +0100 (CET) Received: by basil.haag.hardeman.nu (Postfix, from userid 1000) id 25AD61A0408; Sat, 20 Nov 2010 00:43:02 +0100 (CET) Subject: [PATCH 05/10] saa7134: protect the ir user count To: linux-media@vger.kernel.org From: David =?utf-8?b?SMOkcmRlbWFu?= Cc: jarod@wilsonet.com, mchehab@infradead.org Date: Sat, 20 Nov 2010 00:43:02 +0100 Message-ID: <20101119234302.3511.97440.stgit@localhost.localdomain> In-Reply-To: <20101119233959.3511.91287.stgit@localhost.localdomain> References: <20101119233959.3511.91287.stgit@localhost.localdomain> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 19 Nov 2010 23:44:47 +0000 (UTC) diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c index 98678d9..8b80efb 100644 --- a/drivers/media/video/saa7134/saa7134-input.c +++ b/drivers/media/video/saa7134/saa7134-input.c @@ -402,17 +402,12 @@ static void ir_raw_decode_timer_end(unsigned long data) ir->active = false; } -static int __saa7134_ir_start(void *priv) +static void __saa7134_ir_start(struct saa7134_dev *dev) { - struct saa7134_dev *dev = priv; - struct saa7134_card_ir *ir; - - if (!dev || !dev->remote) - return -EINVAL; + struct saa7134_card_ir *ir = dev->remote; - ir = dev->remote; if (ir->running) - return 0; + return; ir->running = true; ir->active = false; @@ -427,19 +422,12 @@ static int __saa7134_ir_start(void *priv) setup_timer(&ir->timer, ir_raw_decode_timer_end, (unsigned long)dev); } - - return 0; } -static void __saa7134_ir_stop(void *priv) +static void __saa7134_ir_stop(struct saa7134_dev *dev) { - struct saa7134_dev *dev = priv; - struct saa7134_card_ir *ir; - - if (!dev || !dev->remote) - return; + struct saa7134_card_ir *ir = dev->remote; - ir = dev->remote; if (!ir->running) return; @@ -448,39 +436,60 @@ static void __saa7134_ir_stop(void *priv) ir->active = false; ir->running = false; - - return; } int saa7134_ir_start(struct saa7134_dev *dev) { + if (!dev || !dev->remote) + return -EINVAL; + + spin_lock(&dev->remote->lock); if (dev->remote->users) - return __saa7134_ir_start(dev); + __saa7134_ir_start(dev); + spin_unlock(&dev->remote->lock); return 0; } void saa7134_ir_stop(struct saa7134_dev *dev) { + if (!dev || !dev->remote) + return; + + spin_lock(&dev->remote->lock); if (dev->remote->users) __saa7134_ir_stop(dev); + spin_unlock(&dev->remote->lock); } static int saa7134_ir_open(struct rc_dev *rc) { struct saa7134_dev *dev = rc->priv; + if (!dev || !dev->remote) + return -EINVAL; + + spin_lock(&dev->remote->lock); + if (dev->remote->users == 0) + __saa7134_ir_start(dev); dev->remote->users++; - return __saa7134_ir_start(dev); + spin_unlock(&dev->remote->lock); + + return 0; } static void saa7134_ir_close(struct rc_dev *rc) { struct saa7134_dev *dev = rc->priv; + if (!dev || !dev->remote) + return; + + spin_lock(&dev->remote->lock); dev->remote->users--; - if (!dev->remote->users) + if (dev->remote->users == 0) __saa7134_ir_stop(dev); + spin_unlock(&dev->remote->lock); } int saa7134_input_init1(struct saa7134_dev *dev) @@ -744,6 +753,7 @@ int saa7134_input_init1(struct saa7134_dev *dev) ir->mask_keyup = mask_keyup; ir->polling = polling; ir->raw_decode = raw_decode; + spin_lock_init(&ir->lock); /* init input device */ snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)", diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h index babfbe7..7c836c3 100644 --- a/drivers/media/video/saa7134/saa7134.h +++ b/drivers/media/video/saa7134/saa7134.h @@ -125,6 +125,7 @@ struct saa7134_card_ir { char name[32]; char phys[32]; unsigned users; + spinlock_t lock; u32 polling; u32 last_gpio;