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: 9978769 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 CA5FA60375 for ; Fri, 29 Sep 2017 22:04:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC75B298CB for ; Fri, 29 Sep 2017 22:04:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B110F298CE; Fri, 29 Sep 2017 22:04:42 +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 6B5AD298CB for ; Fri, 29 Sep 2017 22:04:42 +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=9/36j+kQSVPvvjyV1I5txejmO9E7J5YHef5JF2BctQk=; b=n1z uA1YqYEh3BVJsanh8jTf3yvPIHDFJRKch5pYZ0UTWwk4ovZryje/9DTaqpnwu/ZmyGCzONM1lSXN4 aAPNGrKfFBb6rLiH0GB30blNp2yCGuhPR4yLigZcnvO6m7lkyxkYg6CEixExGDNRBTG3dsyBgmT8o xP2T4suY5E6aEjdTgeGfQFtYbFQgpj3s9xABtWDH1YsfZaOZ+FRXSIGWK/cMZGzkVp5sChUmtvykE cKCUMgwJt5yB/MvqSwmhoCPifvAwO2sapTh45EfZ8baBStqOqc5oxTq/aM1y1naHF2i5EwTWV65HX W3kqPQRhxvnZZVvP5PmvjAF86q2klMQ==; 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 1dy3Oi-0001Pp-KP; Fri, 29 Sep 2017 22:04:40 +0000 Received: from mail-pf0-x233.google.com ([2607:f8b0:400e:c00::233]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dy3OR-00019A-2p for linux-rockchip@lists.infradead.org; Fri, 29 Sep 2017 22:04:24 +0000 Received: by mail-pf0-x233.google.com with SMTP id y29so454449pff.0 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=a3quqK0EnTyteXTrTalAci4pi3hBfc16Q23D4o75omvrWmz98/YQqvIPSVdQF1us4F 8WXzcrKnmGwJhWPmtUzWfpJ7EdhYx+QNywVuC2IToybrU7eBw2JdYatT3QMTgC1hPzMo f1BWEemz2IHqcgivF2ZoheDSv5g+nIP8R22ZuUm4+a1qlim6EGScFCubOROEocQwW1Ca qTbUSww6/d8eCQeCgZIxXDyeHCTX4t/7eKAsBL7GJlm3vlkxihAYAHQ+ygWh2uWfOzF9 Xuka+o0LlxUrJ1Um0zxBoQ3jWD19QvJYu4zzLRVzS+3KxnVa5bl/YvEuG2y1R8JcBX4K +BVQ== X-Gm-Message-State: AHPjjUhJzLActQYIo5nxpjbnpj2RrqDMFt8uALxUpFQbdCbXHR6nbWnW NwbVJeGObsuR54P6Ely4cntH9Q== 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_155121_24425EA0 X-CRM114-Status: GOOD ( 11.88 ) 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, 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-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=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));