From patchwork Fri Oct 2 22:07:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 7320301 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 43F239F32B for ; Sat, 3 Oct 2015 07:34:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6FB1E20857 for ; Sat, 3 Oct 2015 07:34:40 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 4806120851 for ; Sat, 3 Oct 2015 07:34:39 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 43A65266D71; Sat, 3 Oct 2015 09:34:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id A6483266A5D; Sat, 3 Oct 2015 09:23:14 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 202342669C6; Sat, 3 Oct 2015 00:09:22 +0200 (CEST) Received: from resqmta-po-05v.sys.comcast.net (resqmta-po-05v.sys.comcast.net [96.114.154.164]) by alsa0.perex.cz (Postfix) with ESMTP id ACB7A2669BD for ; Sat, 3 Oct 2015 00:09:14 +0200 (CEST) Received: from resomta-po-09v.sys.comcast.net ([96.114.154.233]) by resqmta-po-05v.sys.comcast.net with comcast id QN9D1r00752QWKC01N9DAw; Fri, 02 Oct 2015 22:09:13 +0000 Received: from mail.gonehiking.org ([73.181.52.62]) by resomta-po-09v.sys.comcast.net with comcast id QN9C1r00R1LXgTt01N9DeY; Fri, 02 Oct 2015 22:09:13 +0000 Received: from lorien.internal (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id E324EA1556; Fri, 2 Oct 2015 16:07:36 -0600 (MDT) From: Shuah Khan To: mchehab@osg.samsung.com, hans.verkuil@cisco.com, laurent.pinchart@ideasonboard.com, sakari.ailus@linux.intel.com, tiwai@suse.de, pawel@osciak.com, m.szyprowski@samsung.com, kyungmin.park@samsung.com, perex@perex.cz, dan.carpenter@oracle.com, tskd08@gmail.com, arnd@arndb.de, ruchandani.tina@gmail.com, corbet@lwn.net, k.kozlowski@samsung.com, chehabrafael@gmail.com, prabhakar.csengg@gmail.com, elfring@users.sourceforge.net, Julia.Lawall@lip6.fr, p.zabel@pengutronix.de, ricardo.ribalda@gmail.com, labbott@fedoraproject.org, chris.j.arges@canonical.com, pierre-louis.bossart@linux.intel.com, johan@oljud.se, wsa@the-dreams.de, jcragg@gmail.com, clemens@ladisch.de, daniel@zonque.org, gtmkramer@xs4all.nl, misterpib@gmail.com, takamichiho@gmail.com, pmatilai@laiskiainen.org, vladcatoi@gmail.com, damien@zamaudio.com, normalperson@yhbt.net, joe@oampo.co.uk, jussi@sonarnerd.net, calcprogrammer1@gmail.com Date: Fri, 2 Oct 2015 16:07:16 -0600 Message-Id: <28bf43b07b9ffbd90e6fae27b6a95ca07288b81b.1443822799.git.shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1443823753; bh=2b7Gz3KkGpInQU3yUQtwCBvCeN3fhmmRBh5NAdJkhjo=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=HoMqlD5+yY0OknTcZXbw6EFcKmssFz+ZE630H/ftG9kMGkGp2x1mtDQHZuVEC/sJh bm474Lxs+30CNbqRn7yegPiMK7iJjX4sGA6tiUbjaMbNQofVr9a9hso3C+3ptqHIZ4 5Vg48Fy+EOGt6SHUnvD65bDrcGloCZPUx/uUIInwXlGjHfVfN6LxDR2kVmoALo/m25 RoKJzkg39y0BVVtCZuiMWTaOGJrU7wdE0BUrNulW2bX+CMqk35Zq8PtAealwhnVYyF sbMZCyic+LDQAJ73tuKga+zCg/EF2qmq2D7C6/ed9ZAADXJ1CEFZL91rjF8X0zqfXn Xjti9ifQw9Nzg== X-Mailman-Approved-At: Sat, 03 Oct 2015 09:23:02 +0200 Cc: alsa-devel@alsa-project.org, Shuah Khan , linux-media@vger.kernel.org Subject: [alsa-devel] [PATCH MC Next Gen 04/20] media: Media Controller fix to not let stream_count go negative X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.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 eaeda25..797b7b3 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c @@ -502,9 +502,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 @@ -542,9 +545,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; + } } mutex_unlock(&mdev->graph_mutex);