From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07282C433DF for ; Fri, 15 May 2020 16:02:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF047206C0 for ; Fri, 15 May 2020 16:02:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726293AbgEOQC4 (ORCPT ); Fri, 15 May 2020 12:02:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726183AbgEOQC4 (ORCPT ); Fri, 15 May 2020 12:02:56 -0400 Received: from mailout2.hostsharing.net (mailout2.hostsharing.net [IPv6:2a01:37:3000::53df:4ee9:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32B26C061A0C for ; Fri, 15 May 2020 09:02:56 -0700 (PDT) Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout2.hostsharing.net (Postfix) with ESMTPS id 16052101712C1; Fri, 15 May 2020 18:02:54 +0200 (CEST) Received: from localhost (unknown [89.246.108.87]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id CE8AD6029E64; Fri, 15 May 2020 18:02:53 +0200 (CEST) X-Mailbox-Line: From d0dcbd098401b5d2a486eee7cf2f9dcabacf9605 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Lukas Wunner Date: Fri, 15 May 2020 17:58:05 +0200 Subject: [PATCH 5/5] spi: Document devm_spi_register_controller() gotcha To: Mark Brown Cc: "Nicolas Saenz Julienne" , Martin Sperl , linux-spi@vger.kernel.org, linux-rpi-kernel@lists.infradead.org Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org As a rule, devm_spi_register_controller() must not be used if the driver's ->remove() hook performs teardown steps which shall be performed after unbinding of slaves. Dozens of drivers are doing it wrong. Document this gotcha to hopefully prevent further misuse. Signed-off-by: Lukas Wunner --- drivers/spi/spi.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index d32bdc6cbf66..e1a35aa7eeb8 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2714,6 +2714,13 @@ static void devm_spi_unregister(struct device *dev, void *res) * Register a SPI device as with spi_register_controller() which will * automatically be unregistered and freed. * + * Be aware that a managed SPI controller and the attached slaves are + * unregistered after the driver's ->remove() callback has been executed. + * So the SPI slaves may still access the bus during and after ->remove(). + * Thus, devm_spi_register_controller() may only be used if there is no + * ->remove() callback at all or if it does not perform teardown steps + * which render the bus inaccessible. + * * Return: zero on success, else a negative error code. */ int devm_spi_register_controller(struct device *dev, -- 2.26.2