From patchwork Tue Jan 9 21:08:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 10153471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8679B60223 for ; Tue, 9 Jan 2018 21:09:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7978C24B48 for ; Tue, 9 Jan 2018 21:09:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E1BD24BFE; Tue, 9 Jan 2018 21:09:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A01EF24B5B for ; Tue, 9 Jan 2018 21:09:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To: Subject:To:From:Date:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4dL4ZPSKfrP/HQYNM3FageNJksLYg57c5v2tauXqA7I=; b=H66vEeDqhTKiVi CLZ5Kbe388vjYWH1Qhq0CJ/FExvj+cpIpn7sI+2egS8WFWFod58VxALvR/suvpEY8ANQAB4bFAR2M 8DiLqbuTjWRk5XW/sR+VktTe4S0BPnWn7Vy10VaJGneaNJZJFd2+vFoyqgjtkMCDRohD32pFPVcqY coJEIKtTNQank3UkFYIJoceyyXpUm/z16zu7ILc/8TlCj9aPvVHydAXEmTW1a9Apmt+Zh1/jR1qx1 GILyeMcIxRl04kMafQIcJMAxNo9wfZ/E5GQY+sZGeiVwMCutY1k2hZqkzYl74PWCCR70anZJXWOpN SFXz9IZzW3xglMDunEDQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eZ18w-0007xj-Ax; Tue, 09 Jan 2018 21:09:10 +0000 Received: from mail.kmu-office.ch ([2a02:418:6a02::a2]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZ18s-0007wp-1f for linux-arm-kernel@lists.infradead.org; Tue, 09 Jan 2018 21:09:08 +0000 Received: from webmail.kmu-office.ch (unknown [178.209.48.103]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 528735C3BC7; Tue, 9 Jan 2018 22:02:08 +0100 (CET) MIME-Version: 1.0 Date: Tue, 09 Jan 2018 22:08:31 +0100 From: Stefan Agner To: Lucas Stach Subject: Re: soc: imx: gpcv2: removing and probing fails In-Reply-To: <1515509738.12538.35.camel@pengutronix.de> References: <3f836677c6e98aaf01bc1ac8c3410083@agner.ch> <1515507886.12538.33.camel@pengutronix.de> <1515509738.12538.35.camel@pengutronix.de> Message-ID: <0a0c556cedc3b6448919748081445780@agner.ch> X-Sender: stefan@agner.ch User-Agent: Roundcube Webmail/1.2.5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1515531728; bh=5pJfh00RXlxETDJgUlrPiLgbtH19ijcVMj1wh5RHBPw=; h=MIME-Version:Content-Type:Content-Transfer-Encoding:Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID; b=fULMYMhbHdXtlHyNhcGTo7kksCsxSn0vHsE8hLExlPO2D+ifkV+WNsdra9CmZ5zYrVioLI0E/eBexn8E0BLaF9meiWHyqzHLl8+bAFObKFNd+RU/1hTkmhPDTu0OJp1FTQtDDLly2nCmHXc6LiLxYfrZiIzTKFxA5NUC3R5C7Z0= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180109_130906_976901_ED23438E X-CRM114-Status: GOOD ( 22.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: andrew.smirnov@gmail.com, Shawn Guo , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On 2018-01-09 15:55, Lucas Stach wrote: > Am Dienstag, den 09.01.2018, 15:44 +0100 schrieb Stefan Agner: >> On 2018-01-09 15:24, Lucas Stach wrote: >> > Am Sonntag, den 07.01.2018, 11:48 +0100 schrieb Stefan Agner: >> > > Hi Andrew, >> > > >> > > I noticed that the driver fails when removing and probing again. >> > > As far >> > > as I can see due to duplicate add of the platform devices. >> > > >> > > As far as I can tell the driver should register the remove >> > > callback and >> > > do a platform_device_unregister on the newly created platform >> > > devices. >> > > However, as far as I can tell we don't hold on to a reference to >> > > them... >> > > I guess we could keep references in imx_gpcv2_probe, but maybe >> > > there is >> > > an easier way? >> > >> > The GPC v1 driver adds the necessary device dependency between the >> > power domain devices and the GPC parent device. See the >> > device_link_add() in imx_pgc_power_domain_probe(). >> >> Note that despite device_link_add, GPC v1 seems to cause issue with >> CONFIG_DEBUG_TEST_DRIVER_REMOVE=y: >> https://marc.info/?l=linux-arm-kernel&m=151544599904423&w=4 >> >> (sorry, I made it confusing, by adding a stack trace when using GPC >> v1 >> in the gpcv2 thread...) > > IMHO this is an issue with the CONFIG_DEBUG_TEST_DRIVER_REMOVE option, > as it just blindly calls the remove callback instead of doing a proper > __device_release_driver(). All the regular driver/device unbind paths > will properly unbind the consumer devices before removing the driver. They do unbind the consumer device, but do not unregister the platform device. I tried to fix it by calling platform_device_unregister, e.g. with this changes unbind seems to work: @@ -470,7 +475,7 @@ static int imx_gpc_probe(struct platform_device *pdev) static int imx_gpc_remove(struct platform_device *pdev) { - int ret; + int i, ret; /* * If the old DT binding is used the toplevel driver needs to @@ -489,6 +494,21 @@ static int imx_gpc_remove(struct platform_device *pdev) return ret; } + + for (i = 0; i < ARRAY_SIZE(imx_gpc_domains); i++) { + struct imx_pm_domain *domain = &imx_gpc_domains[i]; + + if (domain->pdev) { + /* + * Unlink platform_data to prevent + * platform_device_unregister to kfree it. + */ + domain->pdev->dev.platform_data = NULL; + platform_device_unregister(domain->pdev); + domain->pdev = NULL; + } + } + return 0; } However, it still leads to a stacktrace on next bind: root@colibri-imx6:~# echo 20dc000.gpc > /sys/bus/platform/drivers/imx-gpc/bind [ 24.741624] imx-pgc-pd imx-pgc-power-domain.0: Linked as a consumer to 20dc000.gpc [ 24.749219] ------------[ cut here ]------------ [ 24.753934] WARNING: CPU: 0 PID: 430 at drivers/base/core.c:417 device_links_driver_bound+0xd8/0xe0 ... --- Stefan --- a/drivers/soc/imx/gpc.c +++ b/drivers/soc/imx/gpc.c @@ -40,6 +40,7 @@ struct imx_pm_domain { struct generic_pm_domain base; + struct platform_device *pdev; struct regmap *regmap; struct regulator *supply; struct clk *clk[GPC_CLK_MAX]; @@ -462,6 +465,8 @@ static int imx_gpc_probe(struct platform_device *pdev) of_node_put(np); return ret; } + + domain->pdev = pd_pdev; } }