From patchwork Wed Oct 4 11:28:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 9984385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9868D60237 for ; Wed, 4 Oct 2017 11:46:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8772E2883D for ; Wed, 4 Oct 2017 11:46:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C21328ADD; Wed, 4 Oct 2017 11:46:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 079C52883D for ; Wed, 4 Oct 2017 11:46:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Date:Message-Id: In-Reply-To:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: References:List-Owner; bh=SI4wMoiYUtVyZrwAWrhrIrBfhw6ATiTx+C6uci5JfN0=; b=kQo wTGGFzwtZyHs7ex/ixLBheOJkWkd9RjjCnT/6inLyqy+BlxOgqbviiXP9YlgHkzpZyV3q9v2I44aI eYYh1b8rQ8GP3KqOQCZ9B4pXXAVpzesDs3omSfOCvjdeaIvTUsOXtaL0Ya126fACXtTb5HhVjjdu8 av9t5ID7BHG4N2rqUtoyYxn+8/uBW2xk/kbSpcebdd3QJun23LACgRXd59qbDyOHfEwJunAOyuP0H ZpDS1SxgwT0Upktf9rjXkt9qPRWmI4kU55G8Q2QoHGzAQ9uf7nE4wj0ZkkzhPU3euplrgztRHSn+8 NfG5jMiphwB6VIAtciFd62NVXA/RQ1w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dzi8M-0002tM-Pp; Wed, 04 Oct 2017 11:46:38 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dzi6z-0000bL-9Y; Wed, 04 Oct 2017 11:45:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Date:Message-Id:In-Reply-To:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:References:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=KOD98TTrHUb16rxNfEMdGR4OzB0z75rjxGV/1ZV5DnY=; b=YLSrI2ZBJQZP+0c7psp+r42RH5 uLv5Pdql6oAWR38FUtgPNp9bbWp0DVfBOjBrYbtA8lkhBN63n4wxcgouWAad8R4ECY9mD47dSdNBo go4EgG0x0NSOXj6jtWtrYHFU0/AkW2iXb8D6PVGpl/YNkSLBF1BDg4j46FnH202y3a7YURTvd1TLU rsZ/XcGv7qtmbsr0VouCpaXztUpeDDwfkJqENFpPPm9kIKLH2GDdp5QMT7/hdT1l7KxSwQkHnIYWM 8BMiaBmomuPcZS1bTPkAAH41JdNUc+ZGeDT6PibG3bIz+Neutf1Lu0UzflEIFadpvvIx2fARA0vhe QOydit6A==; Received: from heliosphere.sirena.org.uk ([2a01:7e01::f03c:91ff:fed4:a3b6]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dzhsL-00079c-17; Wed, 04 Oct 2017 11:30:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Date:Message-Id:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=KOD98TTrHUb16rxNfEMdGR4OzB0z75rjxGV/1ZV5DnY=; b=oH3u5L0TxWcy jVBvQE0Sg7j9ajTNSzBHGHBD7Lguwdp1pJV5yXTwitYHhmfL7HV8ArMPenoHWFmWywSiA7vvI9uGa 3xo7Yi440QKWWG5rXIvB8JulPpiVozPyO6kdnzYP7LDvJuW5qS3p6fvY/jISSCEPkPSStRayJWLTs hT7wQ=; Received: from debutante.sirena.org.uk ([2001:470:1f1d:6b5::3] helo=debutante) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1dzhr3-0006ZE-RG; Wed, 04 Oct 2017 11:28:45 +0000 Received: from broonie by debutante with local (Exim 4.89) (envelope-from ) id 1dzhr3-0004Qh-D0; Wed, 04 Oct 2017 12:28:45 +0100 From: Mark Brown To: Douglas Anderson Subject: Applied "ASoC: rockchip: Allocate enough memory so we don't overflow routes" to the asoc tree In-Reply-To: <20170929220324.16413-1-dianders@chromium.org> Message-Id: Date: Wed, 04 Oct 2017 12:28:45 +0100 X-Bad-Reply: In-Reply-To but no 'Re:' in Subject. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171004_123005_109512_189000EE X-CRM114-Status: GOOD ( 20.94 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, briannorris@chromium.org, Heiko Stuebner , jeffy.chen@rock-chips.com, Liam Girdwood , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, broonie@kernel.org, Takashi Iwai , mka@chromium.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The patch ASoC: rockchip: Allocate enough memory so we don't overflow routes has been applied to the asoc tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From 8eae6c2585b0455f0e7200495d5e513020ca2fa2 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Fri, 29 Sep 2017 15:03:24 -0700 Subject: [PATCH] ASoC: rockchip: Allocate enough memory so we don't overflow routes In the recent commit d9f9c167edae ("ASoC: rockchip: Init dapm routes dynamically") we improperly allocated memory for the card->dapm_routes causing us to overflow the allocation on every boot. Oops. Let's allocate the correct amount of memory. We'll also add a check to make sure that we don't overrun memory even if we encounter some sort of weird device tree. Fixes: d9f9c167edae ("ASoC: rockchip: Init dapm routes dynamically") Signed-off-by: Douglas Anderson Signed-off-by: Mark Brown --- sound/soc/rockchip/rk3399_gru_sound.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c index 30eed83e8a13..d64fbbd50544 100644 --- a/sound/soc/rockchip/rk3399_gru_sound.c +++ b/sound/soc/rockchip/rk3399_gru_sound.c @@ -494,13 +494,17 @@ static int rockchip_sound_of_parse_dais(struct device *dev, struct snd_soc_dai_link *dai; struct snd_soc_dapm_route *routes; int i, index; + int num_routes; card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais), GFP_KERNEL); if (!card->dai_link) return -ENOMEM; - routes = devm_kzalloc(dev, sizeof(rockchip_routes), + num_routes = 0; + for (i = 0; i < ARRAY_SIZE(rockchip_routes); i++) + num_routes += rockchip_routes[i].num_routes; + routes = devm_kzalloc(dev, num_routes * sizeof(*routes), GFP_KERNEL); if (!routes) return -ENOMEM; @@ -538,6 +542,12 @@ static int rockchip_sound_of_parse_dais(struct device *dev, dai->platform_of_node = np_cpu; dai->cpu_of_node = np_cpu; + if (card->num_dapm_routes + rockchip_routes[index].num_routes > + num_routes) { + dev_err(dev, "Too many routes\n"); + return -EINVAL; + } + memcpy(routes + card->num_dapm_routes, rockchip_routes[index].routes, rockchip_routes[index].num_routes * sizeof(*routes));