From patchwork Thu Dec 24 07:02:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 7915431 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 32D709F1AF for ; Thu, 24 Dec 2015 07:04:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5598620425 for ; Thu, 24 Dec 2015 07:04:36 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 363EC203ED for ; Thu, 24 Dec 2015 07:04:34 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id A1CCD2665C0; Thu, 24 Dec 2015 08:04:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 5ADD02665C0; Thu, 24 Dec 2015 08:04:22 +0100 (CET) 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 849622665CB; Thu, 24 Dec 2015 08:04:21 +0100 (CET) Received: from mailout4.w1.samsung.com (mailout4.w1.samsung.com [210.118.77.14]) by alsa0.perex.cz (Postfix) with ESMTP id 63CDE2665BB for ; Thu, 24 Dec 2015 08:04:15 +0100 (CET) Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NZU009R4OYUPO10@mailout4.w1.samsung.com> for alsa-devel@alsa-project.org; Thu, 24 Dec 2015 07:04:06 +0000 (GMT) X-AuditID: cbfec7f4-f79026d00000418a-27-567b98e5cf93 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 8F.57.16778.5E89B765; Thu, 24 Dec 2015 07:04:05 +0000 (GMT) Received: from AMDC1061.digital.local ([106.116.147.88]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NZU000J6OYQT850@eusync1.samsung.com>; Thu, 24 Dec 2015 07:04:05 +0000 (GMT) From: Andrzej Hajda To: Liam Girdwood , Mark Brown , Kuninori Morimoto Date: Thu, 24 Dec 2015 08:02:39 +0100 Message-id: <1450940559-16516-1-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <87k2o4fkad.wl%kuninori.morimoto.gx@renesas.com> References: <87k2o4fkad.wl%kuninori.morimoto.gx@renesas.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPLMWRmVeSWpSXmKPExsVy+t/xy7pPZ1SHGay5a2lxa905VosrFw8x WWycsZ7VYurDJ2wWrw7vYrT4dqWDyeLyrjlsFmuP3GW36NzVz2qx4ftaRgcujw2fm9g8ds66 y+6xaVUnm8e+t8vYPL6dmcji0bdlFaPH+i1XWTw+b5IL4IjisklJzcksSy3St0vgyrjTYlmw l69ixl/dBsan3F2MHBwSAiYSG17xdzFyApliEhfurWcDsYUEljJKLNvo0MXIBWQ3MUk86NvJ DpJgE9CU+Lv5JhtIQkSggVHiyNs+FhCHWeABk8TS9gesIFOFBawlNk7zB2lgEVCVOLrgIROI zSvgLNHw7T4LxDY5iZPHJrOC2JwCthKf7z+A2mwj0X11G9sERt4FjAyrGEVTS5MLipPScw31 ihNzi0vz0vWS83M3MUKC8csOxsXHrA4xCnAwKvHwFtypChNiTSwrrsw9xCjBwawkwrt0WnWY EG9KYmVValF+fFFpTmrxIUZpDhYlcd65u96HCAmkJ5akZqemFqQWwWSZODilGhj9+Mx1ZX64 vj+8LXOz1cHisy4XfPSft7geOLJhqw/jR49jfVwH9oSHfw+at/7vc7W0lheRgSuf73afH94v WDkr+vSpeVs8+z38YpdsLj3hstbn6s4dfIabOjYqhV5ufKmQlfosRma90UW3u+t4k1ucH6+Z nBd17Rt/sd3mXSt/seavjJe/aNOuxFKckWioxVxUnAgAD6Rc6EICAAA= Cc: "moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM..." , Bartlomiej Zolnierkiewicz , open list , Takashi Iwai , Andrzej Hajda , Marek Szyprowski Subject: [alsa-devel] [PATCH v2] ASoC: rsnd: fix usrcnt decrementing bug 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 Field usrcnt is unsigned so it cannot be lesser than zero. The patch fixes the check, moves it to the beginning of the function and changes return value to -EIO in case of usercnt error. The problem has been detected using proposed semantic patch scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1]. [1]: http://permalink.gmane.org/gmane.linux.kernel/2038576 Signed-off-by: Andrzej Hajda Acked-by: Kuninori Morimoto --- v2: changed according to Kuninori Morimoto advice --- sound/soc/sh/rcar/ssi.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index 0b91692..f23c921 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -364,29 +364,30 @@ static int rsnd_ssi_quit(struct rsnd_mod *mod, struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct device *dev = rsnd_priv_to_dev(priv); - if (rsnd_ssi_is_parent(mod, io)) - goto rsnd_ssi_quit_end; + if (!ssi->usrcnt) { + dev_err(dev, "%s[%d] usrcnt error\n", + rsnd_mod_name(mod), rsnd_mod_id(mod)); + return -EIO; + } - if (ssi->err > 0) - dev_warn(dev, "%s[%d] under/over flow err = %d\n", - rsnd_mod_name(mod), rsnd_mod_id(mod), ssi->err); + if (!rsnd_ssi_is_parent(mod, io)) { + if (ssi->err > 0) + dev_warn(dev, "%s[%d] under/over flow err = %d\n", + rsnd_mod_name(mod), rsnd_mod_id(mod), + ssi->err); - ssi->cr_own = 0; - ssi->err = 0; + ssi->cr_own = 0; + ssi->err = 0; - rsnd_ssi_irq_disable(mod); + rsnd_ssi_irq_disable(mod); + } -rsnd_ssi_quit_end: rsnd_ssi_master_clk_stop(ssi, io); rsnd_mod_power_off(mod); ssi->usrcnt--; - if (ssi->usrcnt < 0) - dev_err(dev, "%s[%d] usrcnt error\n", - rsnd_mod_name(mod), rsnd_mod_id(mod)); - return 0; }