Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp3881520ybg; Sun, 7 Jun 2020 13:43:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHcT12c0NfhzsvF4X6TZvIG3AaJzK0UcOkctu4UoZgBxhB/Yk56RILzyHrmLO0PoymL/v5 X-Received: by 2002:a17:906:5243:: with SMTP id y3mr19286043ejm.193.1591562638913; Sun, 07 Jun 2020 13:43:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591562638; cv=none; d=google.com; s=arc-20160816; b=rPmcnhZn52g4cS0Yp4z+YzG626Rq3dzrHzznJseHHc4jnocy9G9MEJNI7NUF8ckFSI 03EpQPyvxValndmZwUyOPZ6JQOYOlAhn2338uE8UvFjJNJr4OV1EpeoRCfnsUCEDuCZ0 CDvOk4/4tPyhCjQbhVl2l9btPZo75E5ZqMgPT266lgGdDaVUo6+A1AJnsvitRHiNs8aj IAISewbl6TgL9i4pCmw3ULWsPv3ojzkuAW8nL6gfnaw8+ZbtMa7sh1zGz14qWiGGD+Ee eZD74xEsAsgaMpp6lk+jkCqxGb2AMHbP9sICXDUiuDKMzPhBe4uw93f8CbOKY9hwxWmG JhLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:dkim-signature; bh=cxAlOko9t8uVXP+cvSgKgh4pcthYDznq/xdMjGJwWF8=; b=ufjUlcNE7KgV0OZphjoL09ba7nV0Ma6AMhpo6MZBEd6HMZBjLewH7nNevhzBlwEo9x 36oORs/9jNGktKDV/rU6e9gr+KrkXxGJpZ4zrGFNUFAEWUj8ig29EMJSr7iEGDeC6YgV A/s5vF9ZPzqKHJgEilr+0GhnSfdNEAcac1tGKc7lMU6krBUFSYqvxFKV+IdDkD6P3zbe x2y9X+DfHsvdgdf3fHywVmUYV6cUOkXzdvow1uZbdpVkOamue2zSR2btHtL3jIetoL+J v7pc8J+LUAh01btm0RAc5m5U+w1uKPH02kYmnVP1b82V59i6eknvesvzuMz8ATm1pmrH kD/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=KdOyqU9N; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si7800806edn.503.2020.06.07.13.43.35; Sun, 07 Jun 2020 13:43:58 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=KdOyqU9N; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727966AbgFGUjw (ORCPT + 99 others); Sun, 7 Jun 2020 16:39:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726823AbgFGUjv (ORCPT ); Sun, 7 Jun 2020 16:39:51 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16B04C08C5C4 for ; Sun, 7 Jun 2020 13:39:51 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id gl26so15978933ejb.11 for ; Sun, 07 Jun 2020 13:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=cxAlOko9t8uVXP+cvSgKgh4pcthYDznq/xdMjGJwWF8=; b=KdOyqU9ND3HG5d87XzvYCfQ2uByF1009R35nYXeDDMLn3vhVJNmlnwuNBXc0HasUMj LyKvjV0OHT0/GFgDE/03M8ppq31jNA/14gxV99DDyqL8qAre2/OHH5LtP6yQKvfznyX2 LROlH2K/f/dx1Vn/5b4xOX0oA7ArWmNxLbjZ1JVMq+Vnt/1ms3tCRN/hGC71MCrsqjUd GIPFEFAU/eZqHJivwmZWwKWtr3PRkJqQ1obBpY+x+MD2ytvfqSzxenTN/wm1iaf4iXcG kNiefj+tDTqhRm+1eJYp0/rg7yaWUj0T9E5B1oGeYm2hbTCHEqv2buK6/vOkL0BGK6WX fsQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=cxAlOko9t8uVXP+cvSgKgh4pcthYDznq/xdMjGJwWF8=; b=oRyx+Rlx7otKRbr9zTAqgodfSL2HHJ3lnZ5+J0TsVcI1G2gQxk9mOVP/80fcxoGfIw caT57Brgi26P+SJfOvyxzCt3Xyi3uq1xp0RtM3bd2Az5FprK7ZX6C/aCgh8+mxxUXQ1v cNX3/Cdtcw8qHBjyQrRXapmH5tzAABsevw1WRGenntKArIolDL0dxABNiYNWhcjaJ4EG w8oKZllmQsVNkhIxQOU0gqtx2Tay8XBd5F+XeyQ636CRHEMoi3sbAnJ6/CPljFRhs9SL NtzqBYtkAKZxmb0fZ7WbcfmOSJkrgGJ6wU4+zBe+CEZn9w8SMfex61nFE/KvEWlXXchq uSEQ== X-Gm-Message-State: AOAM531vAg55U6JM0jOAEyL/TdIhEygIW/lBURaA508MEfjVKEVl8Oe7 iJQNew3+7g3ho85NMb/m3NSQ/w== X-Received: by 2002:a17:906:a387:: with SMTP id k7mr19195332ejz.408.1591562389607; Sun, 07 Jun 2020 13:39:49 -0700 (PDT) Received: from localhost (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.gmail.com with ESMTPSA id v29sm10754839edb.62.2020.06.07.13.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2020 13:39:48 -0700 (PDT) References: <20200604171216.60043-1-colin.king@canonical.com> User-agent: mu4e 1.3.3; emacs 26.3 From: Jerome Brunet To: Colin King , 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: Re: [PATCH] ASoC: meson: fix memory leak of links if allocation of ldata fails In-reply-to: <20200604171216.60043-1-colin.king@canonical.com> Date: Sun, 07 Jun 2020 22:39:47 +0200 Message-ID: <1j7dwik3u4.fsf@starbuckisacylon.baylibre.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 04 Jun 2020 at 19:12, Colin King wrote: > 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 Looks good, Thx Acked-by: Jerome Brunet > --- > 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);