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: 9978765 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 BAE4660375 for ; Fri, 29 Sep 2017 22:04:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD75A2766D for ; Fri, 29 Sep 2017 22:04:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1D4728458; Fri, 29 Sep 2017 22:04:10 +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=-1.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 829902766D for ; Fri, 29 Sep 2017 22:04:08 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 45439267479; Sat, 30 Sep 2017 00:04:05 +0200 (CEST) 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 EBAD2267482; Sat, 30 Sep 2017 00:04:04 +0200 (CEST) Received: from mail-pf0-f182.google.com (mail-pf0-f182.google.com [209.85.192.182]) by alsa0.perex.cz (Postfix) with ESMTP id C5D1B266CE8 for ; Sat, 30 Sep 2017 00:04:02 +0200 (CEST) Received: by mail-pf0-f182.google.com with SMTP id n24so449432pfk.5 for ; Fri, 29 Sep 2017 15:04:02 -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=ZdEfbdcAqwtn3N59vzOhpTFpJ+GBmERQVnwHzdJ1FkYjpYD5jUr+X6P9zPOTmwwwop zb8gsSsU+scj1lMao8H5kFdFxyV8l1syIl8DkT2LDsiXPUoSiWwR8msasEh47ZWVXwfr tbiRbTMWA2f/V7muJ/2BKarGuabWxWtiz+E/B3Ojd8rKo6Fn3EkcTKjYhRCDYE1qdFe3 j8UYZe9QpBJpVGi9Mfmp7h4hMkhCCR2W6on2S+6n5wimpYAxns17QTku2tYUucTKdmaz v+VOLbgprN4yWqrcVtaVoqmR3YHRxh8erdCcIphyFej2xo9knQsUl7SLR9GYs6fqLWqs Mm9w== X-Gm-Message-State: AHPjjUhMQg3xlY3z+F2K2oCi7BnQrSgdMoWcepX9lJ74sGOQXX4hqz2n wsCMsxUaYS+o6rSlMTMqejWEmg== 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 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 Cc: alsa-devel@alsa-project.org, Heiko Stuebner , Liam Girdwood , linux-kernel@vger.kernel.org, briannorris@chromium.org, Douglas Anderson , linux-rockchip@lists.infradead.org, Takashi Iwai , linux-arm-kernel@lists.infradead.org Subject: [alsa-devel] [PATCH] ASoC: rockchip: Allocate enough memory so we don't overflow routes 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 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));