Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp930799ybt; Wed, 17 Jun 2020 18:13:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoOJ8V2uMeiSn6hoR9H6ZxEBxmm4Ok9n+y96H8m/fs3GFqST+xMjuyDB++F/l5oW24bOWm X-Received: by 2002:a17:906:f155:: with SMTP id gw21mr1727433ejb.388.1592442787120; Wed, 17 Jun 2020 18:13:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592442787; cv=none; d=google.com; s=arc-20160816; b=EsB8KTd1U3jthxNoKFjIrztHT22V833SZ2wo85KX4Kaerc8ZmUYBfazw/RlWfMAk5T PIuRihcHtU3dliK5uxpkeX+4OuFmD4WlFqakT2viSte3DRzcx2NSKh5claMpv+9pZbTG A+6cKTJSsWNhjE+BFzMlMDxvVZiSVFjdly95JXDMGdciXIPKb6azzoygrSdHc55WjVCp dCyrOKg3MBJFMRkmUeOtG4ZVi83To24nFFL8gV1gfoNe17d7B84tXW3V4E3epcGa5MVP 8qDgyTc50Y9ov8Vu1cyq8SrqTZwYNpqSU7ax59hv8jBlf5euRdm2n5J4K1MVRjcj668+ RjkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/+9HJPh3oohNfWCIGXxoptNU5gFYtJ1xb4hIUxMp/VE=; b=Yb0aWydSTAS2DoapxU4GZiI28sv9OgXkPM4ecAPpbAZe1x0r8LXG2WD3OZnyyRkrhf bzNkBMqJKJy3XSLY56qN+bePd6Qy03CN0JnBHeQ5x9ZS1EoAm9S/HW2T1kayw6H1jz97 BH6ixx34YnrRlbMsNjD6ZFCaNSVBahnt78xwBGkKz8CAnlbdREhZiSQ4Ob7umDkY5tnX /ALHOF/egZVQYkQawyMSPr3BJZ2WWjAdtBFPy2L/mJo6+eNkay/Swp4mbgUZXpaQLpbf y9/vbJUWe+Lzd0zm06g9zAtAdnMZgtFEJVlDdM1NNucYNHAae4Kx4f9iI3/6uea3jN5K P05w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aCZxilbw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u20si1029592eda.569.2020.06.17.18.12.44; Wed, 17 Jun 2020 18:13:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aCZxilbw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728437AbgFRBKP (ORCPT + 99 others); Wed, 17 Jun 2020 21:10:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:37262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728428AbgFRBKN (ORCPT ); Wed, 17 Jun 2020 21:10:13 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 937F321974; Thu, 18 Jun 2020 01:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592442613; bh=ZeP8K0zOh9XWf/M6ZeyFsdFt9/ZjTz/WXT7NJMGHJ0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aCZxilbwtxz18Z/u+R/SCS+fnsOc4+WeUA3Fe94ursURI6skcMPYo0e5I9PnThSoF 4MzTalCn66s7PnSPQtbSUtprrZVPkrBEJ5cPEJo9WpokznXFtLnxWwaXzYxrFsGQrp fsOTBW9ML/GODNtnzuEPay0uq2FO2kplNUhZWMSo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Colin Ian King , Mark Brown , Sasha Levin , alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org Subject: [PATCH AUTOSEL 5.7 094/388] ASoC: meson: fix memory leak of links if allocation of ldata fails Date: Wed, 17 Jun 2020 21:03:11 -0400 Message-Id: <20200618010805.600873-94-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200618010805.600873-1-sashal@kernel.org> References: <20200618010805.600873-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 2ca8c98e204f..5a4a91c88734 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