From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA0E4C433E1 for ; Tue, 23 Jun 2020 21:42:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FEA52078A for ; Tue, 23 Jun 2020 21:42:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592948558; bh=tT/PXHaRQ8O76+29X1ggI+b7E1cA3ew3/FHpIhduOTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Y9X4Xz1V20Zo6/an3HbcM9hqfXxhXt3V7CmdCa5Wu7oEMPgWJftBkMW3h+BBGAFru DKVNx2uiX1FtlQqQeaV2f6oTtWRvmDgev8z7ERuMyckZMfq5O1YnpLBD/8k4RKDmsE 8Tbeyfc6oRhpygJzcuvcs0MA91JArPWDaiazXioI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388243AbgFWUEm (ORCPT ); Tue, 23 Jun 2020 16:04:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:43390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388239AbgFWUEl (ORCPT ); Tue, 23 Jun 2020 16:04:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 64C38206C3; Tue, 23 Jun 2020 20:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592942680; bh=tT/PXHaRQ8O76+29X1ggI+b7E1cA3ew3/FHpIhduOTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Idsc29hQPmDsdR+BdEx3h4X8VQDUDk5iJE392eQAUxoobXKChcsTot/jMvec9ai4h oSI85QehNAXLBZaOYXhXycyScqILnsqqD6Izn1Rg40uEk9R2CVfa+s5jnFGZCnrU8V PscwKE9xi8a+UOg1F1wmmezaLSk/+LLnMzBdwXbk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Mark Brown , Sasha Levin Subject: [PATCH 5.7 093/477] ASoC: meson: fix memory leak of links if allocation of ldata fails Date: Tue, 23 Jun 2020 21:51:30 +0200 Message-Id: <20200623195412.002476182@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195407.572062007@linuxfoundation.org> References: <20200623195407.572062007@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Colin Ian King [ Upstream commit 6e801dc411329aff592fbd48fb116183d0acdb00 ] Currently if the allocation of ldata fails the error return path does not kfree the allocated links object. Fix this by adding an error exit return path that performs the necessary kfree'ing. Fixes: 7864a79f37b5 ("ASoC: meson: add axg sound card support") Signed-off-by: Colin Ian King Addresses-Coverity: ("Resource leak") Link: https://lore.kernel.org/r/20200604171216.60043-1-colin.king@canonical.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/meson/meson-card-utils.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sound/soc/meson/meson-card-utils.c b/sound/soc/meson/meson-card-utils.c index 2ca8c98e204f2..5a4a91c887347 100644 --- a/sound/soc/meson/meson-card-utils.c +++ b/sound/soc/meson/meson-card-utils.c @@ -49,19 +49,26 @@ int meson_card_reallocate_links(struct snd_soc_card *card, links = krealloc(priv->card.dai_link, num_links * sizeof(*priv->card.dai_link), GFP_KERNEL | __GFP_ZERO); + if (!links) + goto err_links; + ldata = krealloc(priv->link_data, num_links * sizeof(*priv->link_data), GFP_KERNEL | __GFP_ZERO); - - if (!links || !ldata) { - dev_err(priv->card.dev, "failed to allocate links\n"); - return -ENOMEM; - } + if (!ldata) + goto err_ldata; priv->card.dai_link = links; priv->link_data = ldata; priv->card.num_links = num_links; return 0; + +err_ldata: + kfree(links); +err_links: + dev_err(priv->card.dev, "failed to allocate links\n"); + return -ENOMEM; + } EXPORT_SYMBOL_GPL(meson_card_reallocate_links); -- 2.25.1