Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp580750imu; Wed, 9 Jan 2019 02:55:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN7/eznskujmRng0aWwNcTh2oIMLsC7geBaOJ1O0FUFOY74YbfrWxxm5T8nyntARBB797O5u X-Received: by 2002:a17:902:3383:: with SMTP id b3mr5443638plc.170.1547031305955; Wed, 09 Jan 2019 02:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547031305; cv=none; d=google.com; s=arc-20160816; b=g5RnXbk9M13VIoD7E5xMRT2cPC6Bptj4MX+BwqBPG2PDKv5uKdVJfN0BHBX+CnYE0M t8a2DGmp+FPHqWB9k1w+uh+emxU+pHhD/OOKoM/ECxfsdxEr/jOxVfwBt21o+Mt3WjFf 4qHzkdTbnB9cv3/mcLyPyqw+fi71D3EzYL/5W5lUrlIPrE+XzSec4AUYzLjy1h+nbuRD YyEZRKcD9zJeI8EAVk950NaX9ewvMUeu8u9zOgtW9F4UlhlgiUOnXNoyaMZ2zUSI/lAF HG+lueNjurpdZaYzvPUV52UNfL8KHSkdVvP7khxc9BLwkU9qBpl3Ne6z2sLESDQBTSVm 7dgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=dAmxDhh7Q8FzJXKbAU4ucWRj3zWeVxD8NORT/Z4W3dE=; b=JCFpdX98ivy6fg6y68dxWY3totOoSIO/gIwvbkMG0ptVhi+rqbgVRXo5Oa8lXJbGMQ ZG2h1WDbMq2Fkq2NIaTIAYlt5QCkHvxSasHLWma4xC4Pbvjg/Ey/0tU/5q6edwyuPdUK T8vu3MixFVjssgsRHfTmocvWinv9t/JG/oHhHfprB878dw2Xk/A6jmKUC0em0PQ+68n+ RModTLYs5eKnn3ZR6KB1vUnPuiqkrhvkJcyYeoRK8jI6VNjnOuPv+HL+imnwCu8sHZk1 Cn4GJvJAAVXWRrUilJlk1ApiBCbE8UrUmfA40xOFzXgVZOBulM/lQEPbZ6ufw0QhqnWx h1pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=GwcYdXst; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u28si32791636pgn.436.2019.01.09.02.54.49; Wed, 09 Jan 2019 02:55:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=GwcYdXst; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730452AbfAIKw7 (ORCPT + 99 others); Wed, 9 Jan 2019 05:52:59 -0500 Received: from hqemgate14.nvidia.com ([216.228.121.143]:3912 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729798AbfAIKw6 (ORCPT ); Wed, 9 Jan 2019 05:52:58 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 09 Jan 2019 02:52:44 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Wed, 09 Jan 2019 02:52:56 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Wed, 09 Jan 2019 02:52:56 -0800 Received: from [10.21.132.148] (10.124.1.5) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 9 Jan 2019 10:52:54 +0000 Subject: Re: [PATCH] ASoC: core: Fix deferral of machine drivers To: Kuninori Morimoto CC: Liam Girdwood , Mark Brown , , , , Marcel Ziswiler , Matthias Reichl References: <1546968494-22993-1-git-send-email-jonathanh@nvidia.com> <87imyy382r.wl-kuninori.morimoto.gx@renesas.com> From: Jon Hunter Message-ID: Date: Wed, 9 Jan 2019 10:52:52 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <87imyy382r.wl-kuninori.morimoto.gx@renesas.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL108.nvidia.com (172.18.146.13) To HQMAIL101.nvidia.com (172.20.187.10) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1547031164; bh=dAmxDhh7Q8FzJXKbAU4ucWRj3zWeVxD8NORT/Z4W3dE=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=GwcYdXstfxmhAh90suhb8T8+n1ral0naNOuVzdrk2ZNHjgiE+W4PsG9T5GOX9xWUX Tey7I6kVzgbN96JKCk+bM7MajXq2MYRhkHjot5KNho6zhw3p7luFj0pGSBJPVjLWUV C0DoiFdAlSpYsRcyAB12zKiqBOvGMeUjrkK4iLiGK0IxvKPi6cZSpSS+rW6bLOX6pG uhGeARvdIwJngmngutFI9GUMRHEerJAu2+oyVzbbnrc6Unl3ybfK3S/xn8lCBFuHCT VN+6q8XaGwiECl8K158jnwMeLSOL9sHuIDMjD9ZASFgBztXW1EUFOOBlZ45L00YmPs fRqhi/pwZgbFg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/01/2019 02:09, Kuninori Morimoto wrote: > > Hi Jon > >> Commit daecf46ee0e5 ("ASoC: soc-core: use snd_soc_dai_link_component for >> platform") added a new member to the snd_soc_dai_link structure for >> storing a pointer for a platform link component. The pointer for this >> platform link component was allocated, if not already populated by the >> machine driver, using devm_kzalloc() such that the memory would be >> automatically freed on error or removal of the soundcard. However, this >> introduced a new problem, because if the probing of the soundcard is >> deferred, then although the memory allocated for the platform link >> component is freed, if the snd_soc_dai_link structure is declared >> statically by the machine driver, then the pointer in the DAI link >> structure will never be clearer. This means that when the soundcard is >> probed again, memory for the platform link component will not be >> allocated again because the address of the pointer was not cleared >> and this causes sound core to access memory that is no longer valid. >> >> In most cases this causes the following error condition to be triggered >> and causes probing the soundcard to fail. >> >> tegra-snd-sgtl5000 sound: ASoC: Both platform name/of_node are set for >> sgtl5000 >> >> Unfortunately, because this platform link component is allocated before >> the DAI links are added to the soundcard, there is no easy way to clear >> this pointer on teardown if an error occurs. >> >> The pointer for this platform link component was added for future >> proofing and communalising the structures for storing various data. >> Although a machine driver maybe used by more than one platform and so >> this platform data may vary from platform to platform, there is only >> ever a single instance for a given platform. Therefore, rather than >> dynamically allocate the platform link component structure, make it a >> static member of the snd_soc_dai_link to fix the problem. >> >> It should be noted that if the platform_name of platform_of_node members >> of the snd_soc_dai_link structure are populated, these will always be >> used regardless of if the new platform.name or platform.of_node members >> are populated. >> >> Fixes: daecf46ee0e5 ("ASoC: soc-core: use snd_soc_dai_link_component for platform") >> >> Reported-by: Marcel Ziswiler >> Signed-off-by: Jon Hunter >> --- > > Thank you for your patch. > The reason why it is allocating memory is it is for glue Legacy vs Modern style. > This means, this allocation style will be removed if ALSA SoC become modern style. > The missing part so far is CPU. > Only CPU is not yet supporting snd_soc_dai_link_component style. > If all CPU/Codec/Platform supports snd_soc_dai_link_component style, > all driver can switch to it, and then, all will be static style. > Currently, simple card series is only(?) using this style. > > The reason why platform is using pointer style is that > someone (not me ;P) will support multi platform style in the future. Can you elaborate a bit more, I still not not understand what you mean here by 'support multi-platform style' and why this is needed in the future? Furthermore, even if the CPU is not supporting the snd_soc_dai_link_component, I don't understand why this prevents us from making this change now other than it is not consistent. Jon -- nvpublic