Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1461119ybg; Thu, 4 Jun 2020 10:15:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+p2PlK7kdJMl3UvX2LeMlokoW2pbKkQHojrf1sFmmLcaEKymzocik+P08DieJSnk9Rr9O X-Received: by 2002:a17:906:7e5a:: with SMTP id z26mr3200235ejr.263.1591290925574; Thu, 04 Jun 2020 10:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591290925; cv=none; d=google.com; s=arc-20160816; b=KYka0U6zDiGg2m4mjUPBEyaL9U2HRLWTMaylU6n2CEQp+hdje8JAqkY2mrL7luOcNJ b5dKtaDchJ+BVryu6m77P8N6z6jrcVdq8DCjh+rLV+36GeWK/mDCdAv3+ELEw9PA+pPd Z4/eggbHLDOysjKW2nZf/v4gshp6htwOOikW1BjOmpDk1EwRnJoCkxFcoPnfqgiCntYo 3IiPyAFDQxspbeu1+P0k4S4ogK8ZKWdGawKu1j4y4FsnFAuIUKAQbU9AlsnoXTsiz/o3 KgfxyP5Ky+64y/z9zNEjSrttgAiOOA0J2BwRTRQRynbZZBslK1snDfIeLh84FfrOOHHz V0fQ== 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 :message-id:date:subject:cc:to:from; bh=vGBcyluxilXHXeqZLgNIS+u5aM+1kTOT59R2JhN1me8=; b=fjkiBkFxK9STjAp7lhmVSiopaoagvdnbJzsI0Xz1H6GLj5Y+yd9500CJHm+2N/5BQT id8Y5Ls1x/IDS1KgZJJHfadM60aCqPAuKH6XVWaNeYWVBO8by05wcnVb0hCaM5m1a0ug 8qp/fBvhXAjJI6TSlRyy01RA9/oIpkCxSzKB6UyHkgR0BZSCSAVBcrketkpSHbJnKO8p fGiukMB852i7OFWxvo5n/pcTrw3bO61nsMpVnOobL6r1rDapQPt/+aeBcbpMW4orkDJb qFMLkPr+22SVSvcfrHYQKqYY7Fh3R0azD84pYZov8K85ac9Vd939RwfhMXemk616Ka7q Pk4w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u5si1857930ejz.120.2020.06.04.10.15.01; Thu, 04 Jun 2020 10:15:25 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730023AbgFDRMe (ORCPT + 99 others); Thu, 4 Jun 2020 13:12:34 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:44797 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729866AbgFDRMe (ORCPT ); Thu, 4 Jun 2020 13:12:34 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jgtPc-0003GT-NF; Thu, 04 Jun 2020 17:12:16 +0000 From: Colin King To: Jerome Brunet , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Kevin Hilman , alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: meson: fix memory leak of links if allocation of ldata fails Date: Thu, 4 Jun 2020 18:12:16 +0100 Message-Id: <20200604171216.60043-1-colin.king@canonical.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 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. Addresses-Coverity: ("Resource leak") Fixes: 7864a79f37b5 ("ASoC: meson: add axg sound card support") Signed-off-by: Colin Ian King --- 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