From patchwork Thu Feb 22 15:15:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Nuno_S=C3=A1?= X-Patchwork-Id: 13567448 Received: from mx0b-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0A65134CDC for ; Thu, 22 Feb 2024 15:13:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708614787; cv=none; b=jeAHK7rXfDhMyeuaNu25BpZQ/c/MMLi1v3KyreKnaQqbYmVby+C3Yqf67iardDimNF6hB0eEYFRTvnPVDgXUoveDbyXEnyPhuZQzFEUQb24JN8Lu/WPSvRR9jtFKMUvZAeGqEJe01vB9GXceP+3yrbDW00qYXO9tcjwxBeHkgFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708614787; c=relaxed/simple; bh=IqaZTUrMX2tYCpSL8GczWZo+4JMHB0T0+RhmFbYahpk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=cXihHFYntiPHuOLsRfqJGDrFGLQof1U1nqlu4p90ffY7lwc4o50aUd/x79hVitBCL8UiNN7BW1/MO+IRjLoUTAoeihZiP4TPzjIjlgJSUjt9KD2chrFEodsgVTRRu25mH7Sum9DuT4+hWw40l5/LtG9H6jvEblr9to23nhm1A6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=LJR0UJm2; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="LJR0UJm2" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MExCXe031451; Thu, 22 Feb 2024 10:12:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=DKIM; bh=gXoMmKoTg5SHhvcph0HrcxlwYVfwpuLgRQ1ZnXR/Txc=; b= LJR0UJm2uHMUXPdiCJxjh0P1ZnmA+YXox93Ai7bTuiZ3RFYz1D2Wg+cQTL7mBjDd xWaDI5SiLvmXN9rleD6oBHbfDTbVA0Iu7CEY5/VtzgiGzEknvQtQ+vmJHq5s3CXU va06hzpq/lMyixTHr+lfOZgqmWaXrf29VI75XK8QaGGlhmCtGb/PJgRh/6zCx4eE 4gKMtqOVJmpbtWZWoljGpxlQSx1HrlCXrREM2hfaAj+C/zVHp4TGb16kc7hTphjP fKVXEDah1FGb0KL+fU0iSDs+1bu4BWRNTrPaFpwfa7bXV7n2wMwx0Wf0yBXkSkJ9 fDbPbA31lexc0/z39Dm8Sg== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 3we8gu82as-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 10:12:52 -0500 (EST) Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 41MFCpBh060154 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 22 Feb 2024 10:12:51 -0500 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 22 Feb 2024 10:12:50 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 22 Feb 2024 10:12:50 -0500 Received: from [127.0.0.1] ([10.44.3.55]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 41MFCe41017151; Thu, 22 Feb 2024 10:12:45 -0500 From: Nuno Sa Date: Thu, 22 Feb 2024 16:15:50 +0100 Subject: [PATCH v3 1/2] dmaengine: axi-dmac: fix possible race in remove() Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <20240222-axi-dmac-devm-probe-v3-1-16bdca9e64d6@analog.com> References: <20240222-axi-dmac-devm-probe-v3-0-16bdca9e64d6@analog.com> In-Reply-To: <20240222-axi-dmac-devm-probe-v3-0-16bdca9e64d6@analog.com> To: CC: Lars-Peter Clausen , Vinod Koul , X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1708614963; l=1011; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=IqaZTUrMX2tYCpSL8GczWZo+4JMHB0T0+RhmFbYahpk=; b=gJq1v1Ro8TB9vllxWSv+WhWRR7nLp9zWGAHor0y76/FkVMv6hUdmpKBcnWVWPBIay1TKwwOvC 9tzv7qrbD2eDHMkk5drC/58s/Z+ql/vnIDArkIgWDQrjv6pkl6EOoYv X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: 7NIX9JzkJ4RPlqcu2G4K6SXABQsx5Gcu X-Proofpoint-GUID: 7NIX9JzkJ4RPlqcu2G4K6SXABQsx5Gcu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_11,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 adultscore=0 spamscore=0 impostorscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 clxscore=1015 mlxlogscore=608 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220121 We need to first free the IRQ before calling of_dma_controller_free(). Otherwise we could get an interrupt and schedule a tasklet while removing the DMA controller. Fixes: 0e3b67b348b8 ("dmaengine: Add support for the Analog Devices AXI-DMAC DMA controller") Cc: Signed-off-by: Nuno Sa --- drivers/dma/dma-axi-dmac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c index 4e339c04fc1e..d5a33e4a91b1 100644 --- a/drivers/dma/dma-axi-dmac.c +++ b/drivers/dma/dma-axi-dmac.c @@ -1134,8 +1134,8 @@ static void axi_dmac_remove(struct platform_device *pdev) { struct axi_dmac *dmac = platform_get_drvdata(pdev); - of_dma_controller_free(pdev->dev.of_node); free_irq(dmac->irq, dmac); + of_dma_controller_free(pdev->dev.of_node); tasklet_kill(&dmac->chan.vchan.task); dma_async_device_unregister(&dmac->dma_dev); clk_disable_unprepare(dmac->clk); From patchwork Thu Feb 22 15:15:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Nuno_S=C3=A1?= X-Patchwork-Id: 13567449 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 563D439857 for ; Thu, 22 Feb 2024 15:13:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708614787; cv=none; b=bgWyOT+vaqzG2GFq8ESUhZN9SbkFr5fWf52G4jSWPvWTpRdHjkYcQOHCooCxo+r8RFFrFHmsGQSUrzcueeMmHuEmfQh4ey+mtGK37RlJmSQ4fim9oNhD90jKv22g1KdxElaQqx2rHx+rBIKL9tKBrEGe4uUnLiLqC6M75Df/ljk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708614787; c=relaxed/simple; bh=YBIk0u7w8OELblFX210hc91bGmi6J//OvQtYO7Bs1cA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=TqFmyAs77hGe5KaX66tCUGiYp7OAZIMou6lBgL2yhFNZC9+ofERIgFyjQ5DaAJxBLTX3nPugM+Gewx1DXi2Bd/lojiC36UQhcf1Nj9l7+DvPfCgjiZEDx/h/THpvPH+kno/eZemZrUg3Fmcqk9sWtKGH0wpvTE3FSdX6UbcWGuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=s89vj0QY; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="s89vj0QY" Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MErRQW030381; Thu, 22 Feb 2024 10:12:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=DKIM; bh=4PgCRLTR6JKLx2dAFclMpTz9HEFE6ccSFBLFein7fQI=; b= s89vj0QYojVxi8x6WsT2ZACqpD+g9PYbBBdeLc9imUBpiVwKJXWRM1jLHtUhYcbf b6Cg9s5w1Zsinc9yyX/bKf94b/NWkN+oqx39Ar4ojPVmbL46WDXWcNr8dNZzSz1/ FQxVGBOlUVRi/SP0tePSCDpnZEBcd4mT+GiKCDESYmfrtC4xdFohWYqiVBo4k+w/ tttzlhJIyfxeOYJWdMZ8p4hJ1vbn+8+OVntWJMZDOgjOZSJzqDJBg8D85BTeO4xj bNf5O0tB/jJ6Yo6vzXPQX5e9b5CdjblN8io459cV4XvDvXpRfLM1qQPrJA0/x2IE tc/jPTdsroyxEjzAjWsIJg== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3wd21gh7u9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 10:12:53 -0500 (EST) Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 41MFCqiu060158 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 22 Feb 2024 10:12:52 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 22 Feb 2024 10:12:51 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 22 Feb 2024 10:12:51 -0500 Received: from [127.0.0.1] ([10.44.3.55]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 41MFCe42017151; Thu, 22 Feb 2024 10:12:46 -0500 From: Nuno Sa Date: Thu, 22 Feb 2024 16:15:51 +0100 Subject: [PATCH v3 2/2] dmaengine: axi-dmac: move to device managed probe Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <20240222-axi-dmac-devm-probe-v3-2-16bdca9e64d6@analog.com> References: <20240222-axi-dmac-devm-probe-v3-0-16bdca9e64d6@analog.com> In-Reply-To: <20240222-axi-dmac-devm-probe-v3-0-16bdca9e64d6@analog.com> To: CC: Lars-Peter Clausen , Vinod Koul X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1708614963; l=4386; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=YBIk0u7w8OELblFX210hc91bGmi6J//OvQtYO7Bs1cA=; b=mAqSaDEFvGXExLyF29PDx20S2Q+yt5WOWzT/Tn1KySYF//dCFllcyjKyPaAk7rsXZUFqzoQCD jXp2OGGL7ptBsz7s350sQN/YTgo+6SWO5G9BR8lQSxZ8l2xZIjDq3bH X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: tcmIVOG0JWOYys8fpkEcJgkpScenALlx X-Proofpoint-ORIG-GUID: tcmIVOG0JWOYys8fpkEcJgkpScenALlx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_11,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 adultscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 mlxlogscore=732 mlxscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220121 In axi_dmac_probe(), there's a mix in using device managed APIs and explicitly cleaning things in the driver .remove() hook. Move to use device managed APIs and thus drop the .remove() hook. Signed-off-by: Nuno Sa --- drivers/dma/dma-axi-dmac.c | 78 ++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c index d5a33e4a91b1..bdb752f11869 100644 --- a/drivers/dma/dma-axi-dmac.c +++ b/drivers/dma/dma-axi-dmac.c @@ -1002,6 +1002,16 @@ static int axi_dmac_detect_caps(struct axi_dmac *dmac, unsigned int version) return 0; } +static void axi_dmac_tasklet_kill(void *task) +{ + tasklet_kill(task); +} + +static void axi_dmac_free_dma_controller(void *of_node) +{ + of_dma_controller_free(of_node); +} + static int axi_dmac_probe(struct platform_device *pdev) { struct dma_device *dma_dev; @@ -1025,14 +1035,10 @@ static int axi_dmac_probe(struct platform_device *pdev) if (IS_ERR(dmac->base)) return PTR_ERR(dmac->base); - dmac->clk = devm_clk_get(&pdev->dev, NULL); + dmac->clk = devm_clk_get_enabled(&pdev->dev, NULL); if (IS_ERR(dmac->clk)) return PTR_ERR(dmac->clk); - ret = clk_prepare_enable(dmac->clk); - if (ret < 0) - return ret; - version = axi_dmac_read(dmac, ADI_AXI_REG_VERSION); if (version >= ADI_AXI_PCORE_VER(4, 3, 'a')) @@ -1041,7 +1047,7 @@ static int axi_dmac_probe(struct platform_device *pdev) ret = axi_dmac_parse_dt(&pdev->dev, dmac); if (ret < 0) - goto err_clk_disable; + return ret; INIT_LIST_HEAD(&dmac->chan.active_descs); @@ -1072,7 +1078,7 @@ static int axi_dmac_probe(struct platform_device *pdev) ret = axi_dmac_detect_caps(dmac, version); if (ret) - goto err_clk_disable; + return ret; dma_dev->copy_align = (dmac->chan.address_align_mask + 1); @@ -1088,57 +1094,42 @@ static int axi_dmac_probe(struct platform_device *pdev) !AXI_DMAC_DST_COHERENT_GET(ret)) { dev_err(dmac->dma_dev.dev, "Coherent DMA not supported in hardware"); - ret = -EINVAL; - goto err_clk_disable; + return -EINVAL; } } - ret = dma_async_device_register(dma_dev); + ret = dmaenginem_async_device_register(dma_dev); if (ret) - goto err_clk_disable; + return ret; + + /* + * Put the action in here so it get's done before unregistering the DMA + * device. + */ + ret = devm_add_action_or_reset(&pdev->dev, axi_dmac_tasklet_kill, + &dmac->chan.vchan.task); + if (ret) + return ret; ret = of_dma_controller_register(pdev->dev.of_node, of_dma_xlate_by_chan_id, dma_dev); if (ret) - goto err_unregister_device; + return ret; - ret = request_irq(dmac->irq, axi_dmac_interrupt_handler, IRQF_SHARED, - dev_name(&pdev->dev), dmac); + ret = devm_add_action_or_reset(&pdev->dev, axi_dmac_free_dma_controller, + pdev->dev.of_node); if (ret) - goto err_unregister_of; + return ret; - platform_set_drvdata(pdev, dmac); + ret = devm_request_irq(&pdev->dev, dmac->irq, axi_dmac_interrupt_handler, + IRQF_SHARED, dev_name(&pdev->dev), dmac); + if (ret) + return ret; regmap = devm_regmap_init_mmio(&pdev->dev, dmac->base, &axi_dmac_regmap_config); - if (IS_ERR(regmap)) { - ret = PTR_ERR(regmap); - goto err_free_irq; - } - return 0; - -err_free_irq: - free_irq(dmac->irq, dmac); -err_unregister_of: - of_dma_controller_free(pdev->dev.of_node); -err_unregister_device: - dma_async_device_unregister(&dmac->dma_dev); -err_clk_disable: - clk_disable_unprepare(dmac->clk); - - return ret; -} - -static void axi_dmac_remove(struct platform_device *pdev) -{ - struct axi_dmac *dmac = platform_get_drvdata(pdev); - - free_irq(dmac->irq, dmac); - of_dma_controller_free(pdev->dev.of_node); - tasklet_kill(&dmac->chan.vchan.task); - dma_async_device_unregister(&dmac->dma_dev); - clk_disable_unprepare(dmac->clk); + return PTR_ERR_OR_ZERO(regmap); } static const struct of_device_id axi_dmac_of_match_table[] = { @@ -1153,7 +1144,6 @@ static struct platform_driver axi_dmac_driver = { .of_match_table = axi_dmac_of_match_table, }, .probe = axi_dmac_probe, - .remove_new = axi_dmac_remove, }; module_platform_driver(axi_dmac_driver);