From patchwork Wed Oct 9 23:49:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Sheu X-Patchwork-Id: 3013241 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 98119BF924 for ; Wed, 9 Oct 2013 23:50:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C0FFF202A7 for ; Wed, 9 Oct 2013 23:50:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E5F6C202A1 for ; Wed, 9 Oct 2013 23:50:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755826Ab3JIXuh (ORCPT ); Wed, 9 Oct 2013 19:50:37 -0400 Received: from mail-pa0-f73.google.com ([209.85.220.73]:51039 "EHLO mail-pa0-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754764Ab3JIXuh (ORCPT ); Wed, 9 Oct 2013 19:50:37 -0400 Received: by mail-pa0-f73.google.com with SMTP id kp14so141635pab.4 for ; Wed, 09 Oct 2013 16:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dT+PpjvyaAp4gYoYMRWGR7cVKxLogPAB0G/SsNSynXs=; b=Z/r0Uw02QVJtP6gx32hINkEbiWYtLvbMbJRlBiXy9JZtpQki35JDOke1Kbls2o59cm tZQJL7WRFiO1NVCvNxHmCHuLOSwbTzpBctKixL+xFdLvAMk511Nk8c7kdX/liTkMJlv7 NVouRyWqkkhjXO3+lD0K6ejgGCEkUPI2gPhJWLVkpqMk3G+eHF529qYQ9Mkz7X2uixdj mb3XkPYKFwUi7ExyK9Hmk89S6tpqFvjXTvDsnHjMZr5KKkUqdCkDxJqhpnM75cu9zvmH R3vKF5I/+rvMUK/LtaVPVftWGpmts4stZc20bXBvDyACue/xqgP5aXafwnjEoC9dr7g4 7ydg== 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; bh=dT+PpjvyaAp4gYoYMRWGR7cVKxLogPAB0G/SsNSynXs=; b=ayLS/Nz70YCSUSTzrOabl5GNmCo2Trfi4CZ5n7CSYIFiICxEAOXs8DbYxDK1YqnZjN dv713YFfhSudjgnzuR95FkqNNA3U/7hxHbOYW/yeA0rkYE0w9s+IYjYT0qSityvWMtkj LU5riBglUcluqJITRXEJZmv1Wiso3gu0kGAJwy915echhF/NfD7LLURhTg4++lywIDyk vH7MSODsubrtoVKB6mRetQT/lVGnS5Z7q8fbBrV8RQ/o1SV2QehlIoapPy6mhSAOk00N V34OKW9K69veXhaxjwPVn0V7F/XZjqr+FNSmu4qMsy9San5HagY3cvIqowRGc+MRe5WR VW2g== X-Gm-Message-State: ALoCoQkfEYHsX/CfWNNzflGjLOfbBxF8QiKre2u6ca0eYr0TwoLRlV21QZxOreGR/8Td0GC9dyHmyksUfcamatv5oh6nvSRpETzYTVmk3Vn3F2AbU2hHfdjaKooVTCvbSEz5ij0pDfOiBuCUsd0NxlBb5QUotkzlghXbKNFoYJSGqHRaOAnBUPZ+fD6LXR/SK+JonXweIt8lAaaHkPIUlt++NtBNWaQpkA== X-Received: by 10.66.240.4 with SMTP id vw4mr3273972pac.10.1381362636383; Wed, 09 Oct 2013 16:50:36 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id k45si2383951yhn.4.1969.12.31.16.00.00 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Wed, 09 Oct 2013 16:50:36 -0700 (PDT) Received: from shortskirt.mtv.corp.google.com (shortskirt.mtv.corp.google.com [172.22.70.255]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 343B65A4208; Wed, 9 Oct 2013 16:50:36 -0700 (PDT) Received: by shortskirt.mtv.corp.google.com (Postfix, from userid 157237) id DE6EDC04AA; Wed, 9 Oct 2013 16:50:35 -0700 (PDT) From: John Sheu To: linux-media@vger.kernel.org Cc: John Sheu , m.chehab@samsung.com, k.debski@samsung.com, pawel@osciak.com Subject: [PATCH 2/6] [media] s5p-mfc: fix encoder crash after VIDIOC_STREAMOFF Date: Wed, 9 Oct 2013 16:49:45 -0700 Message-Id: <1381362589-32237-3-git-send-email-sheu@google.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1381362589-32237-1-git-send-email-sheu@google.com> References: <1381362589-32237-1-git-send-email-sheu@google.com> 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.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, 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 VIDIOC_STREAMOFF clears the encoder's destination queue -- routines run from the interrupt handler cannot assume that the queue is non-empty. Signed-off-by: John Sheu --- drivers/media/platform/s5p-mfc/s5p_mfc_enc.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c index 41f5a3c..8b24829 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c @@ -714,13 +714,16 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx) if (p->seq_hdr_mode == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) { spin_lock_irqsave(&dev->irqlock, flags); - dst_mb = list_entry(ctx->dst_queue.next, - struct s5p_mfc_buf, list); - list_del(&dst_mb->list); - ctx->dst_queue_cnt--; - vb2_set_plane_payload(dst_mb->b, 0, - s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev)); - vb2_buffer_done(dst_mb->b, VB2_BUF_STATE_DONE); + if (!list_empty(&ctx->dst_queue)) { + dst_mb = list_entry(ctx->dst_queue.next, + struct s5p_mfc_buf, list); + list_del(&dst_mb->list); + ctx->dst_queue_cnt--; + vb2_set_plane_payload(dst_mb->b, 0, + s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, + dev)); + vb2_buffer_done(dst_mb->b, VB2_BUF_STATE_DONE); + } spin_unlock_irqrestore(&dev->irqlock, flags); } @@ -825,8 +828,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx) mfc_debug(2, "enc src count: %d, enc ref count: %d\n", ctx->src_queue_cnt, ctx->ref_queue_cnt); } - if (strm_size > 0) { - /* at least one more dest. buffers exist always */ + if ((ctx->dst_queue_cnt > 0) && (strm_size > 0)) { mb_entry = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list); list_del(&mb_entry->list);