Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7819461imu; Tue, 22 Jan 2019 12:13:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN5HvUEPo8J0zMbtVuadE43W1QFoMR8Wj3L8HMGkyuQaxjizhPvVrKqxAJ9PQxGShIXkYNod X-Received: by 2002:a63:cd11:: with SMTP id i17mr21922795pgg.345.1548187999370; Tue, 22 Jan 2019 12:13:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548187999; cv=none; d=google.com; s=arc-20160816; b=KG25R2QsbA1QOxp1ghIcrG6aW6ejkh5PZyJIbq5eTdXAzYgfXj5kWbhORA+ha/AYlK /1RV8twIUeWQ7Uj1GVQmlv/cMFe2LtBwNiMqB7r1fWQaAngVsXA3a+3tXZRjnNwCg5Vn yCvwxeyDwQ6xynJ4Oh2o+jX9GNUfiaM7qYvxof1/dfi5Cx/+5R7rR7YEoAdqU1M6eoqR oobfk0+dkOHCDdkqqyzjnLlzdEuMd8ghxxdNbnEnJxrPkIUg6kONMwVs8GszKVoDSRCT 1rU4tz/LUz7AR0FQXvEZdLbnrkUEbRY53C79BrgD0SajKC75vdtTKa0J3z4R/3w3akS2 BbAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=w5q907t4OZw1SBADV8hgFm0ts0nEWCgXMcysM/VIj00=; b=teX+LW4gud6stcAsnNAIAFKveYpZjyE6pI8H7N686lqlki98zWjscJ2ShFI5teExf4 4jB/rBh0MlptkpVRppMeSrwu7j3w5+AxFPBo3+KnDfEWrI0QyJpkfX0lWEwc3nYvE9JM 4/c7E5zKeRq8DQvLtWYBmbVrRxXRUMFIFCwTOfaPrxYg44N7GcOBd7tSl6kb7vHCbPoB AIQsC3E9s+uR+1zKpOqUix6wdP2rsELGwXfNAmiek8mYqStK8KQfpTW5rfuVW9iXY/CV 9JpsRY3OhgaT413k9+pe43VNt0lUfs880a/JGKLcbMiGo5Blrsrtrz828tOdSOcg5WP1 xFQA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 86si18547986pfl.46.2019.01.22.12.13.04; Tue, 22 Jan 2019 12:13:19 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbfAVULu (ORCPT + 99 others); Tue, 22 Jan 2019 15:11:50 -0500 Received: from mga09.intel.com ([134.134.136.24]:62902 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726630AbfAVULs (ORCPT ); Tue, 22 Jan 2019 15:11:48 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jan 2019 12:11:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,508,1539673200"; d="scan'208";a="312508837" Received: from djbetows-mobl.amr.corp.intel.com (HELO [10.254.50.13]) ([10.254.50.13]) by fmsmga006.fm.intel.com with ESMTP; 22 Jan 2019 12:11:46 -0800 Subject: Re: [alsa-devel] [PATCH] ASoC: soc-core: Fix null pointer dereference in soc_find_component To: Curtis Malainey Cc: rohkumar@qti.qualcomm.com, alsa-devel@alsa-project.org, bgoswami@codeaurora.org, vinod.koul@linaro.org, plai@codeaurora.org, tiwai@suse.com, lgirdwood@gmail.com, Ajit Pandey , linux-kernel@vger.kernel.org, Liam Girdwood , Matthias Reichl , Mark Brown , srinivas.kandagatla@linaro.org, asishb@codeaurora.org, Rohit kumar , Curtis Malainey , Dylan Reid References: <1547194442-1487-1-git-send-email-rohitkr@codeaurora.org> <4886ed21-65d2-159d-afcd-bb26dcde636e@linux.intel.com> <20190115000610.GM11073@sirena.org.uk> <796a856c-a9a6-022d-da63-947279090198@linux.intel.com> <20190115211137.rhdyjadu7fppp3p4@lenny.lan> <044d59ba-094e-727d-14a9-6ebfc54cbbf4@linux.intel.com> From: Pierre-Louis Bossart Message-ID: Date: Tue, 22 Jan 2019 14:11:45 -0600 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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > The issue was that we were seeing a memory corruption bug on an AMD > chromebooks with that function already (not observed on Intel). I was > testing some SOF integrations and was seeing this in the kernel logs. > I had Dylan verify my logic before I sent the patch because it took so > long to identify the bug and it was traced to the patch that introduce > soc_init_platform. > > [ 10.922112] cz-da7219-max98357a AMD7219:00: ASoC: CPU DAI > designware-i2s.1.auto not registered > [ 10.922122] cz-da7219-max98357a AMD7219:00: > devm_snd_soc_register_card(acpd7219m98357) failed: -517 > [ 11.001411] cz-da7219-max98357a AMD7219:00: ASoC: Both platform > name/of_node are set for amd-max98357-play > [ 11.001423] cz-da7219-max98357a AMD7219:00: ASoC: failed to init > link amd-max98357-play > [ 11.001431] cz-da7219-max98357a AMD7219:00: > devm_snd_soc_register_card(acpd7219m98357) failed: -22 > [ 11.001577] cz-da7219-max98357a: probe of AMD7219:00 failed with error -22 > > of_node was never getting set but the pointer was becoming populated > (outside of the probe call) which traced to soc_init_platform function > which was not reallocating memory on a EPROBE_DEFER even though it was > getting freed by devm. I am not very familiar with devm but my local > maintainers say that it should be freeing the memory even on a > PROBE_DEFER. > The patch should mirror the memory behaviour in > snd_soc_init_multicodec which also reallocates its memory on every > probe. I'm not sure how the patch is causing you to defer, is your > component list corrupt? > > Sorry for the duplicate spam, forgot to send via plain text mode, > re-sending for the mailing list so it gets accepted. There is no defer issue with the intel stuff, but we call this routine multiple times snd_soc_register_card --soc_init_dai_link ----snd_soc_init_platform -- soc_soc_bind_card ----snd_soc_instantiate_card ------ soc_check_tplg_fes -------- snd_soc_init_platform << ALLOC1 --------soc_init_dai_link ----------snd_soc_init_platform << ALLOC2 Initially dai_link->legacy_platform is 0, so gets set after the first first devm_kzalloc (ALLOC1) and after that we always allocate new memory (ALLOC2). The end result is that whatever we set in soc_check_tplg_fes is lost with the new/unnecessary alloc. I would guess your solution is also a work-around, if devm_ effectively freed the memory then the pointer would become NULL. Or may that's the issue is that no one actually resets it.