Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp757109ybt; Fri, 19 Jun 2020 12:59:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJye4S7pOGMsfCgN6YrrtqPgUdj9Px5oQSecLdKNUcR+pFwkW4RSt/giNZ/bHebBrusw3Rjz X-Received: by 2002:a17:907:207b:: with SMTP id qp27mr5569686ejb.532.1592596748296; Fri, 19 Jun 2020 12:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592596748; cv=none; d=google.com; s=arc-20160816; b=BOrEf5c/oQABatofaEzSa0/s552dofVdaq5Qm1C9Fi5X9GY3UwPKz73kDX1zKT0D3E /62ku6BF3UdFdVzjoUBkFEl2tsEKkTN9YoDxSENyryQajlORQx7AFBd7mJOtP+2iMnl1 aDrapXoAXCIMc46q0pUWEHJDDD0SYhuUBhjDQzB4yoShzySCTrcDtwBy72n9N6sq5Mbs EFgQvFBb/8QkNs8AlAJtldCgbjAPZXs1iyGvhHb4g6VOLdVbFN67vbogXqdkopHW1DUc GkLP+VPujgPaQpq1pOAUoDrRvAuVpdSksYrZ1bGLRDgbd+a7XnTiwyRxCnM2OPG/4hnI pWZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pKF4/854GNSI62FjLozUbzYEOKj8n3MfSng3mQ7iOM0=; b=SdX60Gz1WjIGow8lvOPHy3gKLFFXCqTICNzcjYOXyTXyWjCi6DBuYCyHMYIuqtCWCI YGH3lf2o2KpQjNRZMLHyFyElEtHHpCfuXaKhiXOeesPr/G/OrSrKInA7qrXXXYkbGYVL kg9+F1Y+z8NQlFEQNcYK3aO4iQTVYwn4shyKX+X2l8RkwWPkGFoN2vBI+ySFO/8CwymL XR7etQYDgHosBVJZzGlr86PCrMQah+ae0ceSJ9DITwc1WDyQPofM72yeyBtu4l9DjC4F cXj8l7B6q4hCrYbv2frt6ykJ5HoTa3Iex48TXdRV4dCGZUSsXYZkJnCqhqJUCg/n7iOT pmMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I08jbRvc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si4692888ejs.229.2020.06.19.12.58.45; Fri, 19 Jun 2020 12:59:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I08jbRvc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388325AbgFSOmD (ORCPT + 99 others); Fri, 19 Jun 2020 10:42:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:60718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388308AbgFSOl4 (ORCPT ); Fri, 19 Jun 2020 10:41:56 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0654A2168B; Fri, 19 Jun 2020 14:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592577716; bh=mbjPA0vpnyyIxg4/8Es+eXbQrMCkQST/G/1Tj/K+HEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I08jbRvc7FtjKzY3N3xHQeje/Ksy3FwjR4SMvsngu8dgGu0npgm3XNNy9P/TBT7+I XatvXF/kKfa/7bWBMmtOBLsl68WxF+cixmoN/p5ymwvbzmZTs+dT9oG2rgxVRixVDF RXjvuWUAiDtWWd6pVBm6nnwzF3zx/HVAczKkDWpU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Andy Shevchenko , Baruch Siach , Mark Brown , Sasha Levin Subject: [PATCH 4.9 030/128] spi: dw: Fix controller unregister order Date: Fri, 19 Jun 2020 16:32:04 +0200 Message-Id: <20200619141621.757406874@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141620.148019466@linuxfoundation.org> References: <20200619141620.148019466@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner [ Upstream commit ca8b19d61e3fce5d2d7790cde27a0b57bcb3f341 ] The Designware SPI driver uses devm_spi_register_controller() on bind. As a consequence, on unbind, __device_release_driver() first invokes dw_spi_remove_host() before unregistering the SPI controller via devres_release_all(). This order is incorrect: dw_spi_remove_host() shuts down the chip, rendering the SPI bus inaccessible even though the SPI controller is still registered. When the SPI controller is subsequently unregistered, it unbinds all its slave devices. Because their drivers cannot access the SPI bus, e.g. to quiesce interrupts, the slave devices may be left in an improper state. As a rule, devm_spi_register_controller() must not be used if the ->remove() hook performs teardown steps which shall be performed after unregistering the controller and specifically after unbinding of slaves. Fix by reverting to the non-devm variant of spi_register_controller(). An alternative approach would be to use device-managed functions for all steps in dw_spi_remove_host(), e.g. by calling devm_add_action_or_reset() on probe. However that approach would add more LoC to the driver and it wouldn't lend itself as well to backporting to stable. Fixes: 04f421e7b0b1 ("spi: dw: use managed resources") Signed-off-by: Lukas Wunner Reviewed-by: Andy Shevchenko Cc: stable@vger.kernel.org # v3.14+ Cc: Baruch Siach Link: https://lore.kernel.org/r/3fff8cb8ae44a9893840d0688be15bb88c090a14.1590408496.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-dw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index be3ab4006313..c5a2f369941c 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c @@ -533,7 +533,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws) } } - ret = devm_spi_register_master(dev, master); + ret = spi_register_master(master); if (ret) { dev_err(&master->dev, "problem registering spi master\n"); goto err_dma_exit; @@ -557,6 +557,8 @@ void dw_spi_remove_host(struct dw_spi *dws) { dw_spi_debugfs_remove(dws); + spi_unregister_master(dws->master); + if (dws->dma_ops && dws->dma_ops->dma_exit) dws->dma_ops->dma_exit(dws); -- 2.25.1