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: 7319311 Return-Path: X-Original-To: patchwork-linux-media@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 65B309F32B for ; Fri, 2 Oct 2015 22:09:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 95E10208AC for ; Fri, 2 Oct 2015 22:09:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B529C208AA for ; Fri, 2 Oct 2015 22:09:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751668AbbJBWJP (ORCPT ); Fri, 2 Oct 2015 18:09:15 -0400 Received: from resqmta-po-06v.sys.comcast.net ([96.114.154.165]:58984 "EHLO resqmta-po-06v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751429AbbJBWJO (ORCPT ); Fri, 2 Oct 2015 18:09:14 -0400 Received: from resomta-po-09v.sys.comcast.net ([96.114.154.233]) by resqmta-po-06v.sys.comcast.net with comcast id QN9D1r00652QWKC01N9DLK; 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 Cc: Shuah Khan , linux-media@vger.kernel.org, alsa-devel@alsa-project.org Subject: [PATCH MC Next Gen 04/20] media: Media Controller fix to not let stream_count go negative 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=NzzBoGGVi49PbMXHQKUTvsEf1qp74hUqqusBoEfA88BfKPPSNPrdadTpc7+JRjYRn upzfKPBARcvBpBsThzrIR9HKGOBZZ3hDLjOUPN80mH5y8eMq965FluERTWbDiQRZl2 zjtOagsITV3BVIRoprGitZD1TSx76QM+WZP7dNodn6xVdd0NtFCcYJ/qYDRNc+AQyo 6b/rX0dU5HEiz3WhQbdw5OnP4LlDBL/+SoqPhacdEpF8EXP6W2j3+UrcuceQuyECs1 bPruKDXVBtx2BKOeJZmndpWrM9p5ig6HB8yjZ/MMjFbr3/j58lRHHYn3Ckbe5xtVUy zLsLWZcHTxAwg== 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,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable 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 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);