Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp29010921rwd; Wed, 5 Jul 2023 06:06:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlHGGHP7SAf6EkKuA+rH9pUKRN9eR57DO6IXCta5LYu0beK11upyZqT5vM+FPM6PWy9uHAJJ X-Received: by 2002:a17:902:e5c1:b0:1b8:5ab2:49a4 with SMTP id u1-20020a170902e5c100b001b85ab249a4mr14060983plf.53.1688562391836; Wed, 05 Jul 2023 06:06:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688562391; cv=none; d=google.com; s=arc-20160816; b=bsOYi7moSZCqBow9W70Vu7LomOnFJ7k92XkOWRQ08z80gEp/ywtSz6cuMPlSdA+j0B mhrWGrh9kkIYCZV8CWaVKCFOCBsHWTHPZknyorYdQ1QI+mIFWOn+OKjUfcP+MzguZJLE O0uTIvDAOBQ2lIMfsumwalvmmkDnOv/CGhvrfb9tgrJCrpklvUzM3Iz0EqjF9HAm8STp guIJwA4SJfxf/C1ojJYLYRDicu8Uaw/ddxYCRb1M8nts5TKrtquAsaEcXw2qkdllnE+p rIqnOJGXpl41xCXxiXOMMC/Pn5l5S6LOiLPWKmYAwWpTNeMBzSJDMevpMdv/++qw/y48 78yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KqSBwE7BQr9lNwMcCs1LL8WiQVG4n1/jQzSi1ZMENW0=; fh=XKNopzo9Dap4S70gl2ZbkKSseUmtTmPvDd0RQ04DZiw=; b=r/eSP0nhCSyiqweRWRxVByJGt3ajl0IVD6SZZGSDPtQDtqheRnXw6HU9Ej2JT7mmkJ ip4N+lhtkPP+Q4UjdRsD0oTdVq6C8Y8ifH1dgWZ46u5xNZMgxuWLaSTFCn+JvaXO90qP rUhkUnAtBO1jAgJjRXsVg86Mu4mr7zFxqftUF6ypOZoUIx3cDDEKhlfweQOxHsxWcfGC fCDmOSILLYTCZFBtae3ez2MNMbMSvE9Uz1veFbWHRCww+5icZAd6euBqNsq7pIPXDOZP oUaG6sGrPISfja8APVu6Fy/kkR3xdDH7KMVDtkfnMS8eS8/RZfym1sBQ9fXdVgTtweov Ijvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L0Dgj5tm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t9-20020a170902e84900b001a1e0fd406csi24075214plg.217.2023.07.05.06.06.18; Wed, 05 Jul 2023 06:06:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L0Dgj5tm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231846AbjGEMdT (ORCPT + 99 others); Wed, 5 Jul 2023 08:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbjGEMdM (ORCPT ); Wed, 5 Jul 2023 08:33:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C613E11D; Wed, 5 Jul 2023 05:33:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3073E6155D; Wed, 5 Jul 2023 12:33:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83AA8C433CA; Wed, 5 Jul 2023 12:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688560389; bh=CMTp5PjcrdGB1YgiokfJfbw4f+gtghxZ4pFtHuNvMII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L0Dgj5tmXqHoyyYmXI4/RmaTjUN4wyzU/xOCwCBvvGoE39qgLwvw+J1h106R3nsDs Sef6fGSlgU22yQq+WQMbyo9fpKjJiBIMrTbYCxBXWou4lKdL5kFZ6b4IBLSP0/T2A3 uqoVQUKZd6PlWEPqZE+n6mw0SJbDbCbssW5sgI3z9/5jwEDHeQIto4znL7GBKASZgW FAhE0hSZ0ngFp3V44O8SMuKy+rHr743Uz5Ci4GeaIhkMbTCXU3Nl/w0MvM7SRsFbST KxcuBFBhR9Lfvz0mvlhZGOBNNNv6ojq8fZzldhjMt9Y1u1t89wnokWr25IGUghR+7M 21ZSaShu23tpg== Received: from johan by xi.lan with local (Exim 4.96) (envelope-from ) id 1qH1hK-000848-0Q; Wed, 05 Jul 2023 14:33:30 +0200 From: Johan Hovold To: Mark Brown , Vinod Koul Cc: Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Rander Wang Subject: [PATCH 1/8] soundwire: fix enumeration completion Date: Wed, 5 Jul 2023 14:30:11 +0200 Message-Id: <20230705123018.30903-2-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230705123018.30903-1-johan+linaro@kernel.org> References: <20230705123018.30903-1-johan+linaro@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The soundwire subsystem uses two completion structures that allow drivers to wait for soundwire device to become enumerated on the bus and initialised by their drivers, respectively. The code implementing the signalling is currently broken as it does not signal all current and future waiters and also uses the wrong reinitialisation function, which can potentially lead to memory corruption if there are still waiters on the queue. Not signalling future waiters specifically breaks sound card probe deferrals as codec drivers can not tell that the soundwire device is already attached when being reprobed. Some codec runtime PM implementations suffer from similar problems as waiting for enumeration during resume can also timeout despite the device already having been enumerated. Fixes: fb9469e54fa7 ("soundwire: bus: fix race condition with enumeration_complete signaling") Fixes: a90def068127 ("soundwire: bus: fix race condition with initialization_complete signaling") Cc: stable@vger.kernel.org # 5.7 Cc: Pierre-Louis Bossart Cc: Rander Wang Signed-off-by: Johan Hovold --- drivers/soundwire/bus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 1ea6a64f8c4a..66e5dba919fa 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -908,8 +908,8 @@ static void sdw_modify_slave_status(struct sdw_slave *slave, "initializing enumeration and init completion for Slave %d\n", slave->dev_num); - init_completion(&slave->enumeration_complete); - init_completion(&slave->initialization_complete); + reinit_completion(&slave->enumeration_complete); + reinit_completion(&slave->initialization_complete); } else if ((status == SDW_SLAVE_ATTACHED) && (slave->status == SDW_SLAVE_UNATTACHED)) { @@ -917,7 +917,7 @@ static void sdw_modify_slave_status(struct sdw_slave *slave, "signaling enumeration completion for Slave %d\n", slave->dev_num); - complete(&slave->enumeration_complete); + complete_all(&slave->enumeration_complete); } slave->status = status; mutex_unlock(&bus->bus_lock); @@ -1941,7 +1941,7 @@ int sdw_handle_slave_status(struct sdw_bus *bus, "signaling initialization completion for Slave %d\n", slave->dev_num); - complete(&slave->initialization_complete); + complete_all(&slave->initialization_complete); /* * If the manager became pm_runtime active, the peripherals will be -- 2.39.3