Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4715200pxj; Wed, 12 May 2021 11:32:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoZL8g98vb2Ng9uLSeB0bmF1b4J3siCGADIjD11O663fJNr8bMVq5iUDoxlHIOP5gn/Pch X-Received: by 2002:aca:348b:: with SMTP id b133mr8340710oia.116.1620844364333; Wed, 12 May 2021 11:32:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620844364; cv=none; d=google.com; s=arc-20160816; b=LPdC78y3q0LLn9DnqpGeyNq8r7ZoiUur5xtgYLdsG2W3i9iigHXUfpbfl/n94IsFXb CL+MZOn6nH/cPeuC61Sv08T6wHvIB5cxNvw6s6im+nr76gVU5tvPE9IIfIxo5Ee5vPEK 1r8IlAARM+qbSkvFhhVIkbn/iOmFx4M5O/epe1hfk6zUL4APeyXXHjpmhBtglVfERcwY yxm8Np6uhtrzTZWHHbrPWPigoslLIJTdey8vXiWoocsq/rG9CUfBaYTNempjsOYGvAce xJrslnuaXe5qFczSfFHtdvkD9VKUiDEP04m821gMXq7DZO7VM/5l8RxZE+2ANuruzZuu gdDQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D+Vp24EraVogNEnhw4BBkd+uSL8cTfJap48q76I9Myg=; b=Z+7NvaDpRuYTrDvbaF9fTAOs74/fZ8akVaUsdXZmq03m5rO5cLNcdiiHbX0txQLot6 TXfQYby/nnK/7pRmh0GuKXPr5IwxE6qFCDL+o71NfIQPRF/xVRFakXXDUdThh+UtDz4o djr7zuwJ2XmFaiev/+BgAMqArh1Pgq2bNNmhNbZWJrXPhuNglbHEr+U3gKGGB6aNJTkc M0tPbCQWC0bnf6Nr+xojyGgga16TuLPKeSXfnxxCX3KsD1saa74HNJ6z88eEL+YQa8Bp LZ0ah1I4DBOos1C5oKR/xwhwGE+0SYj8OEA31v+hV9RgQ9fv8gz2dCG9E89NH1ck9Aon 9VsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lVuF5siq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x22si645250oif.184.2021.05.12.11.32.31; Wed, 12 May 2021 11:32:44 -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=@linuxfoundation.org header.s=korg header.b=lVuF5siq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350558AbhELSZB (ORCPT + 99 others); Wed, 12 May 2021 14:25:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:51024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241965AbhELQbV (ORCPT ); Wed, 12 May 2021 12:31:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6865D61C2A; Wed, 12 May 2021 15:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835082; bh=29vxBOA37F/Wn2IniIE8nHzEItpJmw1oVRRo2OsptGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lVuF5siqLVGm5rVSO47g2uvpIJDCfR/IQgdeyPbEckOfstPrwY67Qnozl4/JSjoBs OGDVIZFp535MtSFjLa3CsnduSlwjBSW+ygM3udaeqFiVs+Utk+rLt1fljyJwjF+efD YLKmHQIvg3kMEJRX7f9uEVF0LG6UtmrjmOD8dgv0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Antonio Borneo , Alain Volmat , Mark Brown , Sasha Levin Subject: [PATCH 5.12 202/677] spi: stm32: drop devres version of spi_register_master Date: Wed, 12 May 2021 16:44:08 +0200 Message-Id: <20210512144843.960706379@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Antonio Borneo [ Upstream commit 8d559a64f00b59af9cc02b803ff52f6e6880a651 ] A call to spi_unregister_master() triggers calling remove() for all the spi devices binded to the spi master. Some spi device driver requires to "talk" with the spi device during the remove(), e.g.: - a LCD panel like drivers/gpu/drm/panel/panel-lg-lg4573.c will turn off the backlighting sending a command over spi. This implies that the spi master must be fully functional when spi_unregister_master() is called, either if it is called explicitly in the master's remove() code or implicitly by the devres framework. Devres calls devres_release_all() to release all the resources "after" the remove() of the spi master driver (check code of __device_release_driver() in drivers/base/dd.c). If the spi master driver has an empty remove() then there would be no issue; the devres_release_all() will release everything in reverse order w.r.t. probe(). But if code in spi master driver remove() disables the spi or makes it not functional (like in this spi-stm32), then devres cannot be used safely for unregistering the spi master and the binded spi devices. Replace devm_spi_register_master() with spi_register_master() and add spi_unregister_master() as first action in remove(). Fixes: dcbe0d84dfa5 ("spi: add driver for STM32 SPI controller") Signed-off-by: Antonio Borneo Signed-off-by: Alain Volmat Link: https://lore.kernel.org/r/1615545286-5395-1-git-send-email-alain.volmat@foss.st.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-stm32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c index 25c076461011..97cf3a2d4180 100644 --- a/drivers/spi/spi-stm32.c +++ b/drivers/spi/spi-stm32.c @@ -1929,7 +1929,7 @@ static int stm32_spi_probe(struct platform_device *pdev) pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); - ret = devm_spi_register_master(&pdev->dev, master); + ret = spi_register_master(master); if (ret) { dev_err(&pdev->dev, "spi master registration failed: %d\n", ret); @@ -1960,6 +1960,7 @@ static int stm32_spi_remove(struct platform_device *pdev) struct spi_master *master = platform_get_drvdata(pdev); struct stm32_spi *spi = spi_master_get_devdata(master); + spi_unregister_master(master); spi->cfg->disable(spi); if (master->dma_tx) -- 2.30.2