From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751001AbdISIX7 (ORCPT ); Tue, 19 Sep 2017 04:23:59 -0400 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:48235 "EHLO metis.ext.4.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750713AbdISIX6 (ORCPT ); Tue, 19 Sep 2017 04:23:58 -0400 Message-ID: <1505809435.20966.7.camel@pengutronix.de> Subject: Re: [PATCH v2 2/2] mfd: fsl-imx25: clean up irq settings during removal From: Lucas Stach To: Martin Kaiser Cc: Lee Jones , kernel@pengutronix.de, linux-kernel@vger.kernel.org Date: Tue, 19 Sep 2017 10:23:55 +0200 In-Reply-To: <1505802181-27650-2-git-send-email-martin@kaiser.cx> References: <1505205256-6828-1-git-send-email-martin@kaiser.cx> <1505802181-27650-1-git-send-email-martin@kaiser.cx> <1505802181-27650-2-git-send-email-martin@kaiser.cx> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.9-1+b1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:100:fa0f:41ff:fe58:4010 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Dienstag, den 19.09.2017, 08:23 +0200 schrieb Martin Kaiser: > When fsl-imx25-tsadc is compiled as a module, loading, unloading and > reloading the module will lead to a crash. > > Unable to handle kernel paging request at virtual address bf005430 > [] (irq_find_matching_fwspec) > from [] (of_irq_get+0x58/0x74) > [] (of_irq_get) > from [] (platform_get_irq+0x48/0xc8) > [] (platform_get_irq) > from [] (mx25_tsadc_probe+0x220/0x2f4 [fsl_imx25_tsadc]) > > irq_find_matching_fwspec() loops over all registered irq domains. The > irq domain is still registered from last time the module was loaded but > the pointer to its operations is invalid after the module was unloaded. > > Add a removal function which clears the irq handler and removes the irq > domain. With this cleanup in place, it's possible to unload and reload > the module. > > Signed-off-by: Martin Kaiser > --- > changes in v2: > add more details about the crash to the commit message > > drivers/mfd/fsl-imx25-tsadc.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/drivers/mfd/fsl-imx25-tsadc.c b/drivers/mfd/fsl-imx25-tsadc.c > index 14189ef..a6423bd 100644 > --- a/drivers/mfd/fsl-imx25-tsadc.c > +++ b/drivers/mfd/fsl-imx25-tsadc.c > @@ -179,6 +179,19 @@ static int mx25_tsadc_probe(struct platform_device *pdev) > return devm_of_platform_populate(dev); > } > > +static int __exit mx25_tsadc_remove(struct platform_device *pdev) I don't think the __exit annotation makes sense. You can also unbind the device by using sysfs, in which case you want to do the same IRQ cleanup. > +{ > + struct mx25_tsadc *tsadc = platform_get_drvdata(pdev); > + int irq = platform_get_irq(pdev, 0); > + > + if (irq) { > + irq_set_chained_handler_and_data(irq, NULL, NULL); > + irq_domain_remove(tsadc->domain); > + } > + > + return 0; > +} > + > static const struct of_device_id mx25_tsadc_ids[] = { > { .compatible = "fsl,imx25-tsadc" }, > { /* Sentinel */ } > @@ -191,6 +204,7 @@ static struct platform_driver mx25_tsadc_driver = { > .of_match_table = of_match_ptr(mx25_tsadc_ids), > }, > .probe = mx25_tsadc_probe, > + .remove = __exit_p(mx25_tsadc_remove), > }; > module_platform_driver(mx25_tsadc_driver); >