Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1530311pxa; Sun, 16 Aug 2020 01:43:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+gXzx5+Yi7dW9t0p7QKstwdCuBKrZNM2tVTxCEhwIg3+4cOR1RNl9MNw5bqrETkkQPxHj X-Received: by 2002:a05:6402:1c85:: with SMTP id cy5mr10177999edb.6.1597567399677; Sun, 16 Aug 2020 01:43:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597567399; cv=none; d=google.com; s=arc-20160816; b=gJY226LqDYh6byJ73uVecNndZps0E5d0SSN3mGxyA140hwUMgHtc/XxRWkGkPn1IEO M66YndYObXAi1wGmdWZNI3H7N9wG1CHmay+7l4uIIWStj6yQFlfBjlb9mXz6xUtVCU/6 8rOTv9VmIjL8bEUIe86e4YhIPZXfOXa4ndfPnLq/hb+JpIxvGm5OoicqzAl0Q8RJ6FYE CiAsCdJ5ooYvOnRGz2kf8c3HooslXa1EkLZA0VRO8eA+SeJEXI8vJ93MLzFKefQYmt6A ujeA4uU5EQY6Ron38tWHFidDtDQAwiaews54Uoyx2Gv6wc0YCNEoLRMzvpUgfa2IJXot +edg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=XsWzkI7b5pu8oXRoyOcjalYLcDw0bFRQKxSKHW3RdiE=; b=Lg6y4ov0COtcPzO0MB5qpKZGf3UOXz8bNM5r5riPJxB/Qz7bRZeJ+4Xoo0uCEWKJ0s uSW4TsWwWBJF3NClfm6KWD13MNBBnI2+VO7AUFFqHemxwQ8jdCE8TNchAO7qq8ay8Xy0 JV7bM9Zw2DNjpvqdUiyGVlwQMkJyRlt17T0V449Dtyw5+2diPGvo3VFpfEB9ivPxfszO qTiRMOXbYgLf3VmSjZKdMHvpfW1TYXDYYBp+gjS5PHUiNHsV0IuXiceIUJ9lYolQolPV Syi1Us2DEWh4QqVGWpxBqVPBTk8pmRgmx/QJOtfpC3jq6sFqU7oIHgYmB8wLzfuse8qp x6gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KnfhSjMI; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e19si8695411ejc.215.2020.08.16.01.42.56; Sun, 16 Aug 2020 01:43:19 -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=@gmail.com header.s=20161025 header.b=KnfhSjMI; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726111AbgHPHXD (ORCPT + 99 others); Sun, 16 Aug 2020 03:23:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725943AbgHPHXC (ORCPT ); Sun, 16 Aug 2020 03:23:02 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDD12C061786; Sun, 16 Aug 2020 00:23:02 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id u20so6617362pfn.0; Sun, 16 Aug 2020 00:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=XsWzkI7b5pu8oXRoyOcjalYLcDw0bFRQKxSKHW3RdiE=; b=KnfhSjMIJRK9g0L1/TkVJwJ+MZLfx9QY8vyjsQeXdxMvc7pHJ+XF4PXGFngDemEagf uXHun+YRQygAj9a8L+WiXupgmh1V1GckbRqwBBfw6XxOPcpFyzyG34B0oB5q7XM+gurL hZh6j1HEy04Cd1nhn0g5ROqeIINp5tukMDDecpzBX0mT8uBa4hQ4082KYmFEJYfk5iql +g8QBDlUsDxY5rzo8jVgJwHc/WN0BLh4xSRkCyrSmh5b1PTt2uyNJnDYlyLe7vEtk+JA EeEyp9GCqH23grUC4k+powv+wo1ZaJ5la1nrnH0/k6SKrAQAOFvnuBBu2QSmUcf6+L++ Z1rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=XsWzkI7b5pu8oXRoyOcjalYLcDw0bFRQKxSKHW3RdiE=; b=cCP/YPFut+oN/CRRrSb4XkaB7NB0x7ccW0H1PKl8DfkpWCQGHazZlM0uwWJNvYbu/n 1xceoX0jcdf7GO4xlN1Z12Dl/RgTThRGm2iBZV6XYKf4f9y/XBNE+QzoN0Enpnt5Fhbw m6aabaa8yvwdK2+l/WBwlK3PdH584uCDz4AxqYLh93Gt6mtIfz28KR9jKBxIlTYDq9ng rgb8GUZGcwNCf2p1NU41X5L+uXfmjvvD3sVH85V+WHdpO3VaULZAeEXaK/309OAX6Iuq hgGhx/WfYjjWF4MbZb+wjhnEadBPfDeujfJAgSU6UxKhOoz5AAUkJP16p8DVuHqMJ50T ljeA== X-Gm-Message-State: AOAM532ySIOdt9lKwnfX0i+l0qi0HiSsLzl2M4lOlAFBu29Kn/8FzSzP eK8n6FsqMTYzIdxNbmQU2Q== X-Received: by 2002:a62:3486:: with SMTP id b128mr7032696pfa.98.1597562581911; Sun, 16 Aug 2020 00:23:01 -0700 (PDT) Received: from localhost.localdomain ([2402:3a80:cea:9294:8100:367f:a3dd:e679]) by smtp.gmail.com with ESMTPSA id b22sm14825962pfb.213.2020.08.16.00.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2020 00:23:01 -0700 (PDT) From: madhuparnabhowmik10@gmail.com To: paul@crapouillou.net, Zubair.Kakakhel@imgtec.com, dan.j.williams@intel.com, vkoul@kernel.org Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, andrianov@ispras.ru, ldv-project@linuxtesting.org, Madhuparna Bhowmik Subject: [PATCH] drivers/dma/dma-jz4780: Fix race condition between probe and irq handler Date: Sun, 16 Aug 2020 12:52:53 +0530 Message-Id: <20200816072253.13817-1-madhuparnabhowmik10@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Madhuparna Bhowmik In probe IRQ is requested before zchan->id is initialized which can be read in the irq handler. Hence, shift request irq and enable clock after other initializations complete. Here, enable clock part is not part of the race, it is just shifted down after request_irq to keep the error path same as before. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Madhuparna Bhowmik --- drivers/dma/dma-jz4780.c | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c index 448f663da89c..5cbc8c3bd6c7 100644 --- a/drivers/dma/dma-jz4780.c +++ b/drivers/dma/dma-jz4780.c @@ -879,28 +879,6 @@ static int jz4780_dma_probe(struct platform_device *pdev) return -EINVAL; } - ret = platform_get_irq(pdev, 0); - if (ret < 0) - return ret; - - jzdma->irq = ret; - - ret = request_irq(jzdma->irq, jz4780_dma_irq_handler, 0, dev_name(dev), - jzdma); - if (ret) { - dev_err(dev, "failed to request IRQ %u!\n", jzdma->irq); - return ret; - } - - jzdma->clk = devm_clk_get(dev, NULL); - if (IS_ERR(jzdma->clk)) { - dev_err(dev, "failed to get clock\n"); - ret = PTR_ERR(jzdma->clk); - goto err_free_irq; - } - - clk_prepare_enable(jzdma->clk); - /* Property is optional, if it doesn't exist the value will remain 0. */ of_property_read_u32_index(dev->of_node, "ingenic,reserved-channels", 0, &jzdma->chan_reserved); @@ -949,6 +927,28 @@ static int jz4780_dma_probe(struct platform_device *pdev) jzchan->vchan.desc_free = jz4780_dma_desc_free; } + ret = platform_get_irq(pdev, 0); + if (ret < 0) + return ret; + + jzdma->irq = ret; + + ret = request_irq(jzdma->irq, jz4780_dma_irq_handler, 0, dev_name(dev), + jzdma); + if (ret) { + dev_err(dev, "failed to request IRQ %u!\n", jzdma->irq); + return ret; + } + + jzdma->clk = devm_clk_get(dev, NULL); + if (IS_ERR(jzdma->clk)) { + dev_err(dev, "failed to get clock\n"); + ret = PTR_ERR(jzdma->clk); + goto err_free_irq; + } + + clk_prepare_enable(jzdma->clk); + ret = dmaenginem_async_device_register(dd); if (ret) { dev_err(dev, "failed to register device\n"); -- 2.17.1