From patchwork Fri Sep 29 22:03:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 9978767 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 DA0B360375 for ; Fri, 29 Sep 2017 22:04:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB9F9298CD for ; Fri, 29 Sep 2017 22:04:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFCFB298CF; Fri, 29 Sep 2017 22:04:36 +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=ham 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 57C1F298CD for ; Fri, 29 Sep 2017 22:04:36 +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:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=yrFYt8001c2f7fT1E0lp/ApwGbkjUMPIMfUVKqugN0M=; b=pCW 9diD8KFlU2lt9Fr5fAICKszRfdy+obFW+GmCbEnLpuY0rywTsNOn5V4rzEFnVryjvdSf9OILA4E1l NDvVijMap0xicFhW+ZaJoy/KS5ebvv1EFYAKg1wiIwLiNq2IIHbKQG1x9Ba/Y+hc2ND61zrty/Dws FK2Zb4M1c85XM27etcGFlrBJ3Qzs6FvdtmpNV9UpZS221ulll0msByfw8PswE5g2JrLbThRrnasO8 fsVBY6qQ9H483/FTBw+YQWG9QsLVedEDfksOkLjxoPWI5YURiO5D++6Y7ggIZz0gZ1Mr2OgqyS6da 485Pv4MoyjMAosWRQBUyCfSarYR8iJQ==; 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 1dy3OU-0001BG-Qt; Fri, 29 Sep 2017 22:04:26 +0000 Received: from mail-pf0-x22d.google.com ([2607:f8b0:400e:c00::22d]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dy3OR-00019B-6P for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2017 22:04:24 +0000 Received: by mail-pf0-x22d.google.com with SMTP id d187so440078pfg.11 for ; Fri, 29 Sep 2017 15:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=JJ0KbIacxvbqsxtQH5i/steVGowLl/68Y/7Q/qv1668=; b=jD0mu1Gmzrmp5u6R1ixr9m1jshpI+/OLI5JT25QLK5FVtE8eOnnVk9IsHs+1AdODms +penzXGOZnVOmY/L2sJoPOWe/Yit4r9x+cJOEroBi3xNbC4KiRihH81O5WdPMAWIg1Ph sGZRTZmeelGtgeOOShdmxS+uFcJ+LS1VbmA3E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JJ0KbIacxvbqsxtQH5i/steVGowLl/68Y/7Q/qv1668=; b=itjMxWRoLogjDe1vrjc/QX4zq0iaqRz0mSXDyOz3T2B77AdcwsuklWnOkQqRaka8YV NL+TmHDyNNbKJnSBRs4q0eb7w3PmlJqnBieT0QbOo52VoUYgnU/Jd/X1iaF48O1KJxWh OQM0OOYQyMBcm6olPGGs/JA9QZg+PBoy+dctJJXYnOTbVnhVXYatHSCvXtlF/tHRyCBk CxPzSyVIRp2PkzbtcoZ7c+YiNfmSqYRLncCS1Pu9A5tCpDhR9Nl7pfFMlmhVTpQVPQjn p37ap41BUN7CI3/MMH0zj6kBj8uDFClNaGpVpmwMvMCbv1DJOmTo0ZJujANgN63CsSw3 1XdQ== X-Gm-Message-State: AHPjjUhu2QTXNQBNE9uUM9VYKyZ1Vm8HP4jG3ZsqESPhQkINENEUr3Ti ZGRnUXgMGMsxKHsouHfYxUIpkg== X-Google-Smtp-Source: AOwi7QC2RiqMwUScTV5nEBnkMp2gY3V0DDdqdUxGg+cDuHPPKOAUw1oB0RtBbTCLmwpF9H+prLpGww== X-Received: by 10.101.81.135 with SMTP id h7mr7157297pgq.48.1506722640549; Fri, 29 Sep 2017 15:04:00 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.112.154]) by smtp.gmail.com with ESMTPSA id q67sm10006182pfg.160.2017.09.29.15.03.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Sep 2017 15:03:58 -0700 (PDT) From: Douglas Anderson To: broonie@kernel.org, jeffy.chen@rock-chips.com, mka@chromium.org Subject: [PATCH] ASoC: rockchip: Allocate enough memory so we don't overflow routes Date: Fri, 29 Sep 2017 15:03:24 -0700 Message-Id: <20170929220324.16413-1-dianders@chromium.org> X-Mailer: git-send-email 2.14.2.822.g60be5d43e6-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170929_150423_267892_FE81DA5E X-CRM114-Status: GOOD ( 13.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, Heiko Stuebner , Liam Girdwood , linux-kernel@vger.kernel.org, briannorris@chromium.org, Douglas Anderson , Jaroslav Kysela , linux-rockchip@lists.infradead.org, Takashi Iwai , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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));