From patchwork Wed Dec 7 18:30:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 38490 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cEgzL-0004U6-BM; Wed, 07 Dec 2016 18:30:43 +0000 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.84_2/mailfrontend-8) with esmtp id 1cEgzI-00009h-mL; Wed, 07 Dec 2016 19:30:43 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932546AbcLGSaf (ORCPT + 1 other); Wed, 7 Dec 2016 13:30:35 -0500 Received: from mail-pg0-f44.google.com ([74.125.83.44]:35688 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932502AbcLGSab (ORCPT ); Wed, 7 Dec 2016 13:30:31 -0500 Received: by mail-pg0-f44.google.com with SMTP id p66so164614698pga.2 for ; Wed, 07 Dec 2016 10:30:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+NbSPbx079VyYoo07GcALM1wMftuQGsVBqCFCxdB6+A=; b=NTyXuC9GkuHx3wpM0ZALq7dCk7ZztCeI08aCgmY2RsBPzUpj19mZYo2cqbmYMAD0mZ gidyoVf6yRta06wNknU0+a74JOVsL2csqEVABCgG1o8rLcq7r2Z6cHdDwXtfJtWz6Xgc NrLtBHhXpWd6ig2lzOswEqfcgQfCu3dDOR4LoNbUffI+aMQHrSVq8QAcApio49i2A4QJ 7Uh5RjTF8LYwsiHQw5R13TQc9rYI32/QHHeAbZ5N2ST2yiyFh8CFiKCTSqlHDTcF36qM X7YHsGFnHP85MzwOlOPejLTIXq4gYRY2JDWjuVv0zo8mY7s5i0ObhKwS2vVrqA5J0kfJ llNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+NbSPbx079VyYoo07GcALM1wMftuQGsVBqCFCxdB6+A=; b=dKdSqX1pFooYcHk4UbYRPHndwBWQiwvJTI6rBAyRb7f9k8sq/LGCu9E+NsDlmCmtQg 98lrgDFLPLGrDsXbA9JOjfhO3GnKTsl8lOALuRa5KwRt0iV2EXQgkTmBU7Cvl2i7OrG2 k5wpk3r+ImWwY9V6XTEgrLyCrw/psqqC9QWQJ4pc6IsaGMzcMeg/cjjhRir6U5a/FBbC 0N5ACEfKXFFpvMgWOwLHTZ7+KEcavHXbeYIOvsrtt3MOxSwhmPcr0PtiKy2XN7vMmeqj Mhoem7etUlCx0+kMZayJcscRmzMTNYuDmIjv2PQaGFL4yRBkLLY/xfZrT2/PS1CJdPW5 dKCA== X-Gm-Message-State: AKaTC00+TSld6CIDC8XNfH/joOGoF86bfnAzw46Trs56jvfQPnjgY44IB+s6xLfNrdHOcfDf X-Received: by 10.99.62.13 with SMTP id l13mr123512936pga.112.1481135430773; Wed, 07 Dec 2016 10:30:30 -0800 (PST) Received: from localhost (c-98-203-232-209.hsd1.wa.comcast.net. [98.203.232.209]) by smtp.gmail.com with ESMTPSA id x4sm44507097pgc.14.2016.12.07.10.30.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 10:30:30 -0800 (PST) From: Kevin Hilman To: Hans Verkuil , Laurent Pinchart , Sakari Ailus , linux-media@vger.kernel.org Cc: Sekhar Nori , Axel Haslam , =?UTF-8?q?Bartosz=20Go=C5=82aszewski?= , Alexandre Bailon , David Lechner , Patrick Titiano , linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 3/5] [media] davinci: vpif_capture: fix start/stop streaming locking Date: Wed, 7 Dec 2016 10:30:23 -0800 Message-Id: <20161207183025.20684-4-khilman@baylibre.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161207183025.20684-1-khilman@baylibre.com> References: <20161207183025.20684-1-khilman@baylibre.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-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2016.12.7.182416 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DATE_TZ_NA 0, DKIM_SIGNATURE 0, IN_REP_TO 0, LEGITIMATE_NEGATE 0, LEGITIMATE_SIGNS 0, MSG_THREAD 0, MULTIPLE_REAL_RCPTS 0, NO_URI_HTTPS 0, REFERENCES 0, SINGLE_URI_IN_BODY 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CC_NAME 0, __CC_NAME_DIFF_FROM_ACC 0, __CC_REAL_NAMES 0, __CP_MEDIA_BODY 0, __CP_URI_IN_BODY 0, __CTE 0, __FROM_DOMAIN_IN_ANY_CC2 0, __FROM_DOMAIN_IN_RCPT 0, __HAS_CC_HDR 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __NO_HTML_TAG_RAW 0, __REFERENCES 0, __SANE_MSGID 0, __SINGLE_URI_TEXT 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NAME 0, __TO_NAME_DIFF_FROM_ACC 0, __TO_REAL_NAMES 0, __URI_IN_BODY 0, __URI_NO_WWW 0, __URI_NS , __URI_WITH_PATH 0, __YOUTUBE_RCVD 0' Video capture subdevs may be over I2C and may sleep during xfer, so we cannot do IRQ-disabled locking when calling the subdev. The IRQ-disabled locking is meant to protect the DMA queue list throughout the rest of the driver, so update the locking in [start|stop]_streaming to protect just this list, and update the irqlock comment to reflect what it actually protects. Suggested-by: Laurent Pinchart Reviewed-by: Laurent Pinchart Signed-off-by: Kevin Hilman --- drivers/media/platform/davinci/vpif_capture.c | 6 +++--- drivers/media/platform/davinci/vpif_capture.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c index c24049acd40a..f72a719efb3d 100644 --- a/drivers/media/platform/davinci/vpif_capture.c +++ b/drivers/media/platform/davinci/vpif_capture.c @@ -179,8 +179,6 @@ static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count) unsigned long addr, flags; int ret; - spin_lock_irqsave(&common->irqlock, flags); - /* Initialize field_id */ ch->field_id = 0; @@ -211,6 +209,7 @@ static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count) vpif_config_addr(ch, ret); /* Get the next frame from the buffer queue */ + spin_lock_irqsave(&common->irqlock, flags); common->cur_frm = common->next_frm = list_entry(common->dma_queue.next, struct vpif_cap_buffer, list); /* Remove buffer from the buffer queue */ @@ -244,6 +243,7 @@ static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count) return 0; err: + spin_lock_irqsave(&common->irqlock, flags); list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) { list_del(&buf->list); vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED); @@ -287,7 +287,6 @@ static void vpif_stop_streaming(struct vb2_queue *vq) vpif_dbg(1, debug, "stream off failed in subdev\n"); /* release all active buffers */ - spin_lock_irqsave(&common->irqlock, flags); if (common->cur_frm == common->next_frm) { vb2_buffer_done(&common->cur_frm->vb.vb2_buf, VB2_BUF_STATE_ERROR); @@ -300,6 +299,7 @@ static void vpif_stop_streaming(struct vb2_queue *vq) VB2_BUF_STATE_ERROR); } + spin_lock_irqsave(&common->irqlock, flags); while (!list_empty(&common->dma_queue)) { common->next_frm = list_entry(common->dma_queue.next, struct vpif_cap_buffer, list); diff --git a/drivers/media/platform/davinci/vpif_capture.h b/drivers/media/platform/davinci/vpif_capture.h index 9e35b6771d22..1d2c052deedf 100644 --- a/drivers/media/platform/davinci/vpif_capture.h +++ b/drivers/media/platform/davinci/vpif_capture.h @@ -67,7 +67,7 @@ struct common_obj { struct vb2_queue buffer_queue; /* Queue of filled frames */ struct list_head dma_queue; - /* Used in video-buf */ + /* Protects the dma_queue field */ spinlock_t irqlock; /* lock used to access this structure */ struct mutex lock;