From patchwork Tue Sep 22 17:19:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 7241851 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 20F0C9F443 for ; Tue, 22 Sep 2015 17:29:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D89E209EA for ; Tue, 22 Sep 2015 17:29:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DFBD209CF for ; Tue, 22 Sep 2015 17:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758790AbbIVR3X (ORCPT ); Tue, 22 Sep 2015 13:29:23 -0400 Received: from resqmta-po-04v.sys.comcast.net ([96.114.154.163]:43543 "EHLO resqmta-po-04v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758763AbbIVR2C (ORCPT ); Tue, 22 Sep 2015 13:28:02 -0400 Received: from resomta-po-18v.sys.comcast.net ([96.114.154.242]) by resqmta-po-04v.sys.comcast.net with comcast id LHKq1r0095E3ZMc01HKqpm; Tue, 22 Sep 2015 17:19:50 +0000 Received: from mail.gonehiking.org ([73.181.52.62]) by resomta-po-18v.sys.comcast.net with comcast id LHKp1r00M1LXgTt01HKpR2; Tue, 22 Sep 2015 17:19:50 +0000 Received: from lorien.internal (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id 34D2CA1545; Tue, 22 Sep 2015 11:19:48 -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, stefanr@s5r6.in-berlin.de, crope@iki.fi, dan.carpenter@oracle.com, tskd08@gmail.com, ruchandani.tina@gmail.com, arnd@arndb.de, chehabrafael@gmail.com, prabhakar.csengg@gmail.com, Julia.Lawall@lip6.fr, elfring@users.sourceforge.net, ricardo.ribalda@gmail.com, chris.j.arges@canonical.com, pierre-louis.bossart@linux.intel.com, gtmkramer@xs4all.nl, clemens@ladisch.de, misterpib@gmail.com, takamichiho@gmail.com, pmatilai@laiskiainen.org, damien@zamaudio.com, daniel@zonque.org, vladcatoi@gmail.com, normalperson@yhbt.net, joe@oampo.co.uk, bugzilla.frnkcg@spamgourmet.com, jussi@sonarnerd.net Cc: Shuah Khan , linux-media@vger.kernel.org, alsa-devel@alsa-project.org Subject: [PATCH v3 05/21] media: Media Controller fix to not let stream_count go negative Date: Tue, 22 Sep 2015 11:19:24 -0600 Message-Id: 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=1442942390; bh=i/olyl/IbYbOiyIoN7IA+8TzCRNdaCxrh44uQGIw2Wo=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=XxeDwjZgW8ZiOBoVr8GlEwj9kFHJa6jKdsqOCDkChrWbzZCLF5BWvGZB8CD9do4pO MGaga1cPKTfm3mq5Lt7RgpSYl3JACHgrZldD1+rI/nfogkNAPIwc92E9vUbo+IaLC4 xdCh7D1/y6uDrdJ+Z9tPuk7k8axttjAez2g+Te59+myXnYwkyj/QgX2p2pLLNHHpcd q8O1zPWw2Xwnm0BBGTeEXMn4WrI7YA/ZZ/JI2Tw9YtDDfMfFbVLJKwLG5apYbJCXIC INS7fPYeCy7+cmwLKekst9fRzs5l0hvH1LwquerX7BjzrX08UCRmoIX0/bSNlbrPtH o5HjygHfp5MmA== 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=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 4d8e01c..68d5ec2 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c @@ -315,9 +315,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 @@ -355,9 +358,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);