From patchwork Tue Jan 29 21:47:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 10787273 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4030A91E for ; Tue, 29 Jan 2019 21:47:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F6082CDEC for ; Tue, 29 Jan 2019 21:47:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21E132D4E4; Tue, 29 Jan 2019 21:47:27 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FA112CDEC for ; Tue, 29 Jan 2019 21:47:25 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 1FA962674EF; Tue, 29 Jan 2019 22:47:24 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 3DF6A267595; Tue, 29 Jan 2019 22:47:22 +0100 (CET) Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by alsa0.perex.cz (Postfix) with ESMTP id 4FFDD2674B9 for ; Tue, 29 Jan 2019 22:47:20 +0100 (CET) Received: by mail-oi1-f197.google.com with SMTP id e185so11266130oih.18 for ; Tue, 29 Jan 2019 13:47:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:message-id:mime-version:subject:from:to:cc; bh=XjOuq+ACt5mKVpdcmLbYAKbsDRHyoR0euxZxBMwiRxM=; b=IHtjwIMerh5/cGAA+UgjS1M5UjpbRu+5C6bHd9+6auKRVIK9Q167TnP9c63631ylKs icWOOImPGIgwTpvPntEhF6kyw9NA82GeLYwKkk2Zecnj/tt1dMcwzbWxamvgNDU+YbBA UCDLWwpCcdU8yrl70NmnpwX1FHYaNl3x1TX0I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=XjOuq+ACt5mKVpdcmLbYAKbsDRHyoR0euxZxBMwiRxM=; b=VNoc8VuEcCW01LIgDIazbqMvXXdIAITHKRSesIAPdbYg43ktGbPIpHBMiGQ5Ix7w0U kT4Mp/z6zGqk6FPz+lXtss5VuIknF2C3T0L5Djf9YC27ePrPWC5oFgLTW4PidWwyZIAZ xYFfJg9bhFBWpY4nOCr6jggZmWnZcsqNeauATcC0CPkhWBF3vmAWAn99+aceA7PgCSsk 7UP1tHG9krZk0VbUP/PxkPh0muVqtGJXmYo3ALJnHrY6A0m60USMlS7xRKOnZ0AH5TTY 42vifHQ7YLdyYIevQT2102L+2iCVSRT3zHp7jYqkYmh2isXjHzAKhyTU/0Io6etKqc4C RQOw== X-Gm-Message-State: AHQUAuZEb8IWt9mqyBrGwRsdrCYtAFDe9wgJXedMxPi7rHR7CYvevF53 b8W7Xmaj+/v8VLyWAWiWY+9bjKWs2146RU4= X-Google-Smtp-Source: AHgI3IZwq1joQLnADnY+dQS9mYWxaVM48uL7WDM5SY9hhjdIa7Aatun+tNaxNrLDitjprKJPaUn9uWlrblqM2mUp X-Received: by 2002:aca:1709:: with SMTP id j9mr4279454oii.43.1548798438566; Tue, 29 Jan 2019 13:47:18 -0800 (PST) Date: Tue, 29 Jan 2019 13:47:09 -0800 Message-Id: <20190129214710.135124-1-cujomalainey@chromium.org> Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1.495.gaa96b0ce6b-goog From: Curtis Malainey To: alsa-devel@alsa-project.org Cc: Curtis Malainey , Mark Brown , Takashi Iwai , Liam Girdwood Subject: [alsa-devel] [PATCH] ASoC: soc-core: clear platform pointers on error X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Originally snd_soc_init_platform was not cleaning up its pointers, this was fixed to always reallocate dynamic memory but created a memory leak when snd_soc_init_platform was called multiple times during the same probe attempt and also threw away any changes made to the struct between calls. In order to avoid reallocating memory that is still valid, the behaviour will be changed to clear the dynamically set pointers on a probe error and a unregister event and snd_soc_init_platform will go back to its original behaviour of only allocating null pointers so it will stop throwing away valid changes. Signed-off-by: Curtis Malainey --- sound/soc/soc-core.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index d6b5edba8d2d..9431dd605103 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1053,7 +1053,7 @@ static int snd_soc_init_platform(struct snd_soc_card *card, * soc.h :: struct snd_soc_dai_link */ /* convert Legacy platform link */ - if (!platform || dai_link->legacy_platform) { + if (!platform) { platform = devm_kzalloc(card->dev, sizeof(struct snd_soc_dai_link_component), GFP_KERNEL); @@ -1076,6 +1076,24 @@ static int snd_soc_init_platform(struct snd_soc_card *card, return 0; } +static void soc_cleanup_platform(struct snd_soc_card *card) +{ + struct snd_soc_dai_link *link; + int i; + /* + * FIXME + * + * this function should be removed with snd_soc_init_platform + */ + + for_each_card_prelinks(card, i, link) { + if (link->legacy_platform) { + link->legacy_platform = 0; + link->platforms = NULL; + } + } +} + static int snd_soc_init_multicodec(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link) { @@ -2020,6 +2038,7 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card) /* remove and free each DAI */ soc_remove_dai_links(card); soc_remove_pcm_runtimes(card); + soc_cleanup_platform(card); /* remove auxiliary devices */ soc_remove_aux_devices(card);