From patchwork Wed Jan 6 20:26:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 7970531 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E8058BEEE5 for ; Wed, 6 Jan 2016 20:27:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 18A3020154 for ; Wed, 6 Jan 2016 20:27:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3020C20155 for ; Wed, 6 Jan 2016 20:27:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752243AbcAFU1k (ORCPT ); Wed, 6 Jan 2016 15:27:40 -0500 Received: from resqmta-po-05v.sys.comcast.net ([96.114.154.164]:36819 "EHLO resqmta-po-05v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752073AbcAFU1b (ORCPT ); Wed, 6 Jan 2016 15:27:31 -0500 Received: from resomta-po-06v.sys.comcast.net ([96.114.154.230]) by resqmta-po-05v.sys.comcast.net with comcast id 2kTW1s00A4yXVJQ01kTWEE; Wed, 06 Jan 2016 20:27:30 +0000 Received: from mail.gonehiking.org ([73.181.52.62]) by resomta-po-06v.sys.comcast.net with comcast id 2kTU1s0081LXgTt01kTUGD; Wed, 06 Jan 2016 20:27:30 +0000 Received: from lorien.internal (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id CAA219F431; Wed, 6 Jan 2016 13:27:24 -0700 (MST) From: Shuah Khan To: mchehab@osg.samsung.com, tiwai@suse.com, clemens@ladisch.de, hans.verkuil@cisco.com, laurent.pinchart@ideasonboard.com, sakari.ailus@linux.intel.com, javier@osg.samsung.com Cc: Shuah Khan , pawel@osciak.com, m.szyprowski@samsung.com, kyungmin.park@samsung.com, perex@perex.cz, arnd@arndb.de, dan.carpenter@oracle.com, tvboxspy@gmail.com, crope@iki.fi, ruchandani.tina@gmail.com, corbet@lwn.net, chehabrafael@gmail.com, k.kozlowski@samsung.com, stefanr@s5r6.in-berlin.de, inki.dae@samsung.com, jh1009.sung@samsung.com, elfring@users.sourceforge.net, prabhakar.csengg@gmail.com, sw0312.kim@samsung.com, p.zabel@pengutronix.de, ricardo.ribalda@gmail.com, labbott@fedoraproject.org, pierre-louis.bossart@linux.intel.com, ricard.wanderlof@axis.com, julian@jusst.de, takamichiho@gmail.com, dominic.sacre@gmx.de, misterpib@gmail.com, daniel@zonque.org, gtmkramer@xs4all.nl, normalperson@yhbt.net, joe@oampo.co.uk, linuxbugs@vittgam.net, johan@oljud.se, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-api@vger.kernel.org, alsa-devel@alsa-project.org Subject: [PATCH 05/31] media: Media Controller fix to not let stream_count go negative Date: Wed, 6 Jan 2016 13:26:54 -0700 Message-Id: <7496533e9a84110d4c5862cbcc7afdf72215f0ac.1452105878.git.shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1452112050; bh=/VNetrqcoPzyivVus6MYC/2Y52VepaOHAi4abbOsUlM=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=m7L95eBnqqMoQ6XjsFlrbiOinPCoFHPXynwpyw62H2I/QccYg72bXisoEuzXT7MdW kb9oEL5Kc7tEeltwjSI0iIK0nzWfSde8pSOP1ZpG4Cea8sTTM24Dw8El9v+Lf/VepO maN+cloE5VWFHss+ChYT7ifc22VVJp1cI/XuBHGHZE8JcfQYxSHEtaBFIEMBYRK5Wo QsQW+kcSko/6/IDN9aPYLVM7GGrAFBpTZXZl+HQpMcSVKy3lo+u0hbIXn7WL1FW815 pydR/v6Zi7OtYLydo7owoaQqNU0J93XE5YKoHW/ztZ22GUE+JOFQ3XXs9hYXjlYVFK 6lwZtJYqNNptA== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,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 Add a range check to not let the stream_count become negative. Wthout this check, calls to stop pipeline when there is no active pipeline will result in stream_count < 0 condition and lock and preventing link state (activate/deactivate) changes. This will happen from error leg in start pipeline interface. Signed-off-by: Shuah Khan --- drivers/media/media-entity.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c index 6e02d19..78486a9 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c @@ -464,9 +464,12 @@ error: media_entity_graph_walk_start(graph, entity_err); while ((entity_err = media_entity_graph_walk_next(graph))) { - entity_err->stream_count--; - if (entity_err->stream_count == 0) - entity_err->pipe = NULL; + /* don't let the stream_count go negative */ + if (entity->stream_count > 0) { + entity_err->stream_count--; + if (entity_err->stream_count == 0) + entity_err->pipe = NULL; + } /* * We haven't increased stream_count further than this @@ -498,9 +501,12 @@ void media_entity_pipeline_stop(struct media_entity *entity) media_entity_graph_walk_start(graph, entity); while ((entity = media_entity_graph_walk_next(graph))) { - entity->stream_count--; - if (entity->stream_count == 0) - entity->pipe = NULL; + /* don't let the stream_count go negative */ + if (entity->stream_count > 0) { + entity->stream_count--; + if (entity->stream_count == 0) + entity->pipe = NULL; + } } if (!--pipe->streaming_count)