Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp765528ybt; Fri, 19 Jun 2020 13:11:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLDQ2GLDNfNEIz4cO9tSmmatBV4kX+1T2dAJcqQMG0LTphRC46NNXm04CEBk6F/IcMIF+u X-Received: by 2002:aa7:c486:: with SMTP id m6mr5220732edq.234.1592597485123; Fri, 19 Jun 2020 13:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592597485; cv=none; d=google.com; s=arc-20160816; b=wgeYeN+Hxy6v9SU8x9IWLoqCwrmDUfbegBlRhuvLO/ZQmdguGSOxGRjp2M+xApIGwm zvWoeUQyb/kgfy2upBfRLkz2uoU0OA9q55wrAyU+X4zUtXsGivvQU0plz+6pfelwcLVh 6mDYqHkan/xfDo1s3GPg4/1Gq7+j9MnRVNSMCDwugRovJxQG4NtSp+ZEx4inNIaqvZQH fjg2XTaR6TuwiiIIAx7cDjjXzDc71ztSEI1EWq1vvgMgLV5Jb0ECcEpQTE0Bh/wAku6w JTMUUz3lB3kdKIGIMUbq2/3o7YOjWIJQT/6vXawM3dSBvuaHWqXuti2K1m2njKDYntqo AmFg== 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=iih0oN3HSjWDFDPW7B6afwOACOTnsM5eP6c/6pY6SqY=; b=H3ZQ/i22MIHf4YwzUV3VmsjangZb7f2auA6I4j0pgWc65GI8MxwaB+FVM24ayuTQ2w 1WigIsdLomwUAzV4MXoZVcv5NVU2tDk5/rS39w4mxMIgBD/ynE8YQ5d6krIFeZHdNhXT rpIzCAOo/uDjmxVTwmBiW72CHTZ1o4duHhxNwBtf1eIo031QWAOQJwX5MqVCZcBabyZ5 d0rE5fN6Sbtfs3YC0uSpFyYVfugwDvUSveG0YX5IvlNSVkGvtAfwemqUJkBKQkeZEdLD 2DdOE2nonH/ZT3Ml9cLjXuRQMcuvAs7HuLn+80UgvtxYyDXbBHQnNvi7fNBs+jot6ADi LODw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GmNNTnKO; 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 17si5246785edw.300.2020.06.19.13.11.03; Fri, 19 Jun 2020 13:11:25 -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=GmNNTnKO; 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 S2390215AbgFSO5S (ORCPT + 99 others); Fri, 19 Jun 2020 10:57:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:52160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390167AbgFSO47 (ORCPT ); Fri, 19 Jun 2020 10:56:59 -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 29401218AC; Fri, 19 Jun 2020 14:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578619; bh=zl0ACyDj7vFcEaBdi95zIaIux1rc3z6IveIFcj/66R8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GmNNTnKOfbRpwdqi4i7A9dHHGUGrbIivUSl3LaW92dbZHlpJk2h0S6vBaiXDu+dxk PE67Htdua00T0h0cPFsEJMomyvErGgWnbi+ni+rGTv9EQCT1apfRZSvj5qpFpsok8R J9jgt6d9+SmXboD/iz+sUWQRZLlyUN46h6HrmmlM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Mark Brown , Sasha Levin Subject: [PATCH 4.19 061/267] spi: bcm2835: Fix controller unregister order Date: Fri, 19 Jun 2020 16:30:46 +0200 Message-Id: <20200619141651.799401937@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141648.840376470@linuxfoundation.org> References: <20200619141648.840376470@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 9dd277ff92d06f6aa95b39936ad83981d781f49b ] The BCM2835 SPI driver uses devm_spi_register_controller() on bind. As a consequence, on unbind, __device_release_driver() first invokes bcm2835_spi_remove() before unregistering the SPI controller via devres_release_all(). This order is incorrect: bcm2835_spi_remove() tears down the DMA channels and turns off the SPI controller, including its interrupts and clock. The SPI controller is thus no longer usable. When the SPI controller is subsequently unregistered, it unbinds all its slave devices. If their drivers need to access the SPI bus, e.g. to quiesce their interrupts, unbinding will fail. As a rule, devm_spi_register_controller() must not be used if the ->remove() hook performs teardown steps which shall be performed after unbinding of slaves. Fix by using the non-devm variant spi_register_controller(). Note that the struct spi_controller as well as the driver-private data are not freed until after bcm2835_spi_remove() has finished, so accessing them is safe. Fixes: 247263dba208 ("spi: bcm2835: use devm_spi_register_master()") Signed-off-by: Lukas Wunner Cc: stable@vger.kernel.org # v3.13+ Link: https://lore.kernel.org/r/2397dd70cdbe95e0bc4da2b9fca0f31cb94e5aed.1589557526.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-bcm2835.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index eab27d41ba83..df6abc75bc16 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -793,7 +793,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) goto out_clk_disable; } - err = devm_spi_register_master(&pdev->dev, master); + err = spi_register_master(master); if (err) { dev_err(&pdev->dev, "could not register SPI master: %d\n", err); goto out_clk_disable; @@ -813,6 +813,8 @@ static int bcm2835_spi_remove(struct platform_device *pdev) struct spi_master *master = platform_get_drvdata(pdev); struct bcm2835_spi *bs = spi_master_get_devdata(master); + spi_unregister_master(master); + /* Clear FIFOs, and disable the HW block */ bcm2835_wr(bs, BCM2835_SPI_CS, BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX); -- 2.25.1