From patchwork Fri Dec 18 22:21:10 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefani Seibold X-Patchwork-Id: 2335 Return-path: Envelope-to: mchehab@infradead.org Delivery-date: Fri, 18 Dec 2009 22:21:27 +0000 Received: from bombadil.infradead.org [18.85.46.34] by pedra with IMAP (fetchmail-6.3.6) for (single-drop); Fri, 18 Dec 2009 20:21:30 -0200 (BRST) Received: from vger.kernel.org ([209.132.180.67]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NLlCR-00044f-Jl; Fri, 18 Dec 2009 22:21:27 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753903AbZLRWVO (ORCPT + 1 other); Fri, 18 Dec 2009 17:21:14 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753786AbZLRWVN (ORCPT ); Fri, 18 Dec 2009 17:21:13 -0500 Received: from www84.your-server.de ([213.133.104.84]:41995 "EHLO www84.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753257AbZLRWVM (ORCPT ); Fri, 18 Dec 2009 17:21:12 -0500 Received: from [88.65.40.68] (helo=[192.168.0.4]) by www84.your-server.de with esmtpsa (SSLv3:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1NLlC9-0006mc-8n; Fri, 18 Dec 2009 23:21:09 +0100 Subject: [patch] media video cx23888 driver: fix possible races using new kfifo_API kfifo_reset() From: Stefani Seibold To: linux-kernel@vger.kernel.org, Andrew Morton , Mauro Carvalho Chehab , Andy Walls , Linux Media Mailing List Date: Fri, 18 Dec 2009 23:21:10 +0100 Message-ID: <1261174870.13019.24.camel@wall-e> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 X-Authenticated-Sender: stefani@seibold.net X-Virus-Scanned: Clear (ClamAV 0.95.1/10200/Fri Dec 18 21:51:54 2009) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Fix the cx23888 driver to use the new kfifo API. Using kfifo_reset() may result in a possible race conditions. This patch fix it by using spinlock around the kfifo_reset() function. The patch-set is against mm tree from 11-Dec-2009 Greetings, Stefani Signed-off-by: Stefani Seibold Reviewed-by: Andy Walls Acked-by: Andy Walls Acked-by: Mauro Carvalho Chehab --- cx23888-ir.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- mmotm.orig/drivers/media/video/cx23885/cx23888-ir.c 2009-12-18 22:57:13.588337402 +0100 +++ mmotm/drivers/media/video/cx23885/cx23888-ir.c 2009-12-18 23:15:14.651365720 +0100 @@ -519,6 +519,7 @@ static int cx23888_ir_irq_handler(struct { struct cx23888_ir_state *state = to_state(sd); struct cx23885_dev *dev = state->dev; + unsigned long flags; u32 cntrl = cx23888_ir_read4(dev, CX23888_IR_CNTRL_REG); u32 irqen = cx23888_ir_read4(dev, CX23888_IR_IRQEN_REG); @@ -629,8 +630,11 @@ static int cx23888_ir_irq_handler(struct cx23888_ir_write4(dev, CX23888_IR_CNTRL_REG, cntrl); *handled = true; } + + spin_lock_irqsave(&state->rx_kfifo_lock, flags); if (kfifo_len(&state->rx_kfifo) >= CX23888_IR_RX_KFIFO_SIZE / 2) events |= V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ; + spin_unlock_irqrestore(&state->rx_kfifo_lock, flags); if (events) v4l2_subdev_notify(sd, V4L2_SUBDEV_IR_RX_NOTIFY, &events); @@ -783,7 +787,12 @@ static int cx23888_ir_rx_s_parameters(st o->interrupt_enable = p->interrupt_enable; o->enable = p->enable; if (p->enable) { + unsigned long flags; + + spin_lock_irqsave(&state->rx_kfifo_lock, flags); kfifo_reset(&state->rx_kfifo); + /* reset tx_fifo too if there is one... */ + spin_unlock_irqrestore(&state->rx_kfifo_lock, flags); if (p->interrupt_enable) irqenable_rx(dev, IRQEN_RSE | IRQEN_RTE | IRQEN_ROE); control_rx_enable(dev, p->enable);