Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp822640lqb; Wed, 17 Apr 2024 11:42:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWEF7oP5sLXhhJWgxLRaJllQjj5uqkimCj1mgesGii4oViiMW5Etq4P0vS1P72fUpCJs/APG+loHyOjlQ/k8ETO2w5pmRRJXL6gAg8YZQ== X-Google-Smtp-Source: AGHT+IHPIZqFs4ZncRD9gQBHOzlHMkfTTEaJoW0gnuOYWiREurQnentH7UE7vdQk2aBKNGZJxpsl X-Received: by 2002:a17:906:f358:b0:a52:1b82:9948 with SMTP id hg24-20020a170906f35800b00a521b829948mr6185249ejb.8.1713379339932; Wed, 17 Apr 2024 11:42:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713379339; cv=pass; d=google.com; s=arc-20160816; b=XLy8ZAMtbGTtdu9aWfdbsqjNeuZouzfPSoNw+V5KLOLJVdXYZ6arZs124LWKFWEcA9 LHocgVYhhB/2Vq13Kj1ffeHag52N2tLVLCIHkdM6AICfQwC0x1g+2raPbWdQ7q+ZLl+c kPFUjTQkpIDhYAheqgaFaKrSukpUvI6CHiDDvyEGTjbbts2CTv7YJ+3EeE75RFwuL+VY jAyo0ga01HjLh5BDj8iRQ3bfAgdtkSkOB5qi2+fWFeVLzQoArzNXj94c5oh8R+M6CwA1 xd52cwUm3MtNZaEO/9nVkI6Bmkh4A7LlkuO8tWpnaOaZOnBCtmVdWbzG11fSSdQHsN0+ d6uA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=p6icFNRiHIPy7y0oehBoYWRS/JN2fyumo7JjrGWSgTc=; fh=AOM4EiVdCfl9M1n/JTurdDBDEogsePXOG/Xk0Q7Ume4=; b=FXDguQiedcmSF3ougrXo5JMRZgMgtk/oKzII6YM2NWvcE5/izXhgk5vzrlUYFjiTPK Xzwqic6c/Nbkt8KoNhgqYACL8M98bqX02Id2yUy3rQyaJzGxWlrEfqe5mVUjn3G1KKZK a74urRU06arbyoKcnIM2qhpVNWYk2s5kjc7SFXtuu+xlQr1LMVvQQclyQP6dHizWqT52 ToYqxNc5v1eBSaMm1Fx3/MMRZmFFL25EJ5P9TWFfWKow+q5UqBMYaYpAB+xj1yVniFMf WrVy5umFVPKLxLh4yfbJlObus16Alz5pU6+bxhvvyefG1kuimYtNmJGJHZfPyqra6Ui3 90uA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WkIhKoj6; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-149064-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149064-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lx16-20020a170906af1000b00a51c9692fc1si7423241ejb.474.2024.04.17.11.42.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 11:42:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149064-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WkIhKoj6; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-149064-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149064-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A657C1F2512A for ; Wed, 17 Apr 2024 18:42:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3ACD614273; Wed, 17 Apr 2024 18:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WkIhKoj6" Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10191847B; Wed, 17 Apr 2024 18:42:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713379331; cv=none; b=NkxFhdW5O9DXDHhY83hIvfvBZLZNSfNjzyV7Shj4QPapqE5J3fN4Uu3frQ011Wmv4RyP8/sRN15a0Ma+cUpO3MSko0JQhmS+h7DepgUkfBAKXhxn9cOWT9aTs8Lv15fbnOP42BGzokPiJF3mQkUgh9i/4qMFwSy2CjA3AIelCIM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713379331; c=relaxed/simple; bh=8WkGnONM8NyXHIZlC0inPFTNaIF8xV/m3ME04BID7B0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=W3X0U/eVXOmEN1ac76Fc4tH63KmOGrHnMxIu4mxXVDLqNbPspjHuz8DMXHw8vVTFMm8F/37g0LKzCsqNK71X7KJ0EIivAOYveFyHiy6clbDQSpulT8JAHGqQ82T7xtjo0J2Q/PJdz2xLwP/ZEF9TFKoueUjesDWzM+ERPKdUGBE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WkIhKoj6; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1e65a1370b7so686035ad.3; Wed, 17 Apr 2024 11:42:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713379329; x=1713984129; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p6icFNRiHIPy7y0oehBoYWRS/JN2fyumo7JjrGWSgTc=; b=WkIhKoj6yVp9YczycO1yb8Iq3kqnYLQlkX3r0/iz2fFc/jrwgd76f8+WOJ+aufkV5R N0sVOFgKA1eZM8fmPikUsD6shscrNKjhxF9F9PePJJ5BU7qGiciiRDheffEWuOn1yyj/ dp0WPVM3PU2QUu73phxtckwxyZzVQtvnJhhE5j9BsYOfOXWJDX2EhRM5cukj+A5kjf9G wEhsy0enT9KVfT634fnMEMjrlvEuNBIU8IJfRb3FBZf+Z5f5HHFtBO7kJSkOnEsZq0Ov TIYbc4HPA0jEWWSc7ImCcIzHItVN6T2VqBPHAmtkv1yqjZxG0NmE7Ak67jZp4jOElpM4 lXLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713379329; x=1713984129; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p6icFNRiHIPy7y0oehBoYWRS/JN2fyumo7JjrGWSgTc=; b=gesMoHHOH4puY8RrEaK/o0AqGHqa2JAonqUNQBYX5sJuDdhXq+mg647BV7wCsyE6QI EcHyN1HxhgCGYxzDV2A2MfEyp0DftiCy9/dVKiCLepmGTnOCb4J75s5TmTfWsTGQijYD 79jc8a4/VavfsGwIvt5Qqq3sZU9aF5NrxultsPRU2LDigIDclOiqd2eNglKQANsrsS1W lbE7ML21r9sY31Fy8B+LM9kVtStt8CeX1wrlirFNpUC2/pkdJSlplPIVGEv9oc95YGnq SF3kFFC7te5SAH024hkTgtcjHGSH+5tAv2zpWOKEKR+qGZaky/JT69OKjAO05SAj3ue6 sDJA== X-Forwarded-Encrypted: i=1; AJvYcCVasLu+cWct5Z4nmvUJ2EpEnRy8PsJ7OUKJkNRaKGromLlTjZ0pDgFPY3Ouij8BcMnVhfJSlreyMOGwQ4qUtsi7BGLjNIMKW+dgj5QN0MI5+i5AO+hmOd1RMR5t2EyBKUfiPwGVCPwEeyrPQQ9/FHpGOfe1vFNfdUMSdic0rhPbnjI= X-Gm-Message-State: AOJu0Ywt2Ua7x2VWamJB4FVAY/oLGbHtMDc3EKT+0AGRZMlRqGsBFacX IGN0VFpJCX8LUAUrQJdreLryI2vBEFcd+CCxVvH/asrKe1ouYr/dppRmwM0H X-Received: by 2002:a17:902:d4ce:b0:1e6:3494:61fc with SMTP id o14-20020a170902d4ce00b001e6349461fcmr570341plg.0.1713379329167; Wed, 17 Apr 2024 11:42:09 -0700 (PDT) Received: from joaog-nb.corp.toradex.com ([201.82.41.210]) by smtp.gmail.com with ESMTPSA id c17-20020a170902d49100b001e0d6cd042bsm11873501plg.303.2024.04.17.11.42.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 11:42:08 -0700 (PDT) From: Joao Paulo Goncalves To: Peter Ujfalusi , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Joao Paulo Goncalves , Jai Luthra , alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] ASoC: ti: davinci-mcasp: Fix race condition during probe Date: Wed, 17 Apr 2024 15:41:38 -0300 Message-Id: <20240417184138.1104774-1-jpaulo.silvagoncalves@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Joao Paulo Goncalves When using davinci-mcasp as CPU DAI with simple-card, there are some conditions that cause simple-card to finish registering a sound card before davinci-mcasp finishes registering all sound components. This creates a non-working sound card from userspace with no problem indication apart from not being able to play/record audio on a PCM stream. The issue arises during simultaneous probe execution of both drivers. Specifically, the simple-card driver, awaiting a CPU DAI, proceeds as soon as davinci-mcasp registers its DAI. However, this process can lead to the client mutex lock (client_mutex in soc-core.c) being held or davinci-mcasp being preempted before PCM DMA registration on davinci-mcasp finishes. This situation occurs when the probes of both drivers run concurrently. Below is the code path for this condition. To solve the issue, defer davinci-mcasp CPU DAI registration to the last step in the audio part of it. This way, simple-card CPU DAI parsing will be deferred until all audio components are registered. Fail Code Path: simple-card.c: probe starts simple-card.c: simple_dai_link_of: simple_parse_node(..,cpu,..) returns EPROBE_DEFER, no CPU DAI yet davinci-mcasp.c: probe starts davinci-mcasp.c: devm_snd_soc_register_component() register CPU DAI simple-card.c: probes again, finish CPU DAI parsing and call devm_snd_soc_register_card() simple-card.c: finish probe davinci-mcasp.c: *dma_pcm_platform_register() register PCM DMA davinci-mcasp.c: probe finish Cc: stable@vger.kernel.org Fixes: 9fbd58cf4ab0 ("ASoC: davinci-mcasp: Choose PCM driver based on configured DMA controller") Signed-off-by: Joao Paulo Goncalves --- sound/soc/ti/davinci-mcasp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c index b892d66f78470..1e760c3155213 100644 --- a/sound/soc/ti/davinci-mcasp.c +++ b/sound/soc/ti/davinci-mcasp.c @@ -2417,12 +2417,6 @@ static int davinci_mcasp_probe(struct platform_device *pdev) mcasp_reparent_fck(pdev); - ret = devm_snd_soc_register_component(&pdev->dev, &davinci_mcasp_component, - &davinci_mcasp_dai[mcasp->op_mode], 1); - - if (ret != 0) - goto err; - ret = davinci_mcasp_get_dma_type(mcasp); switch (ret) { case PCM_EDMA: @@ -2449,6 +2443,12 @@ static int davinci_mcasp_probe(struct platform_device *pdev) goto err; } + ret = devm_snd_soc_register_component(&pdev->dev, &davinci_mcasp_component, + &davinci_mcasp_dai[mcasp->op_mode], 1); + + if (ret != 0) + goto err; + no_audio: ret = davinci_mcasp_init_gpiochip(mcasp); if (ret) { -- 2.34.1