From patchwork Thu Oct 29 09:22:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 11865729 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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 832ABC55178 for ; Thu, 29 Oct 2020 09:19:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0FE2E20790 for ; Thu, 29 Oct 2020 09:19:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HW1+l14N" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0FE2E20790 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=FphEKjPD/DacaZupms4M6satnOU6tYcPPEPrtIVaGc0=; b=HW1+l14NXhkmtVqlGzyn2/dcsy yFUiZ6h9LbUr/cho4K0CmiPYnCa3DyhgnAWpYSUU7AFEOrSSj73ATzKNAlEKWFNu8/Sf07Y1DrUKq iRFh5x4OIbdsYkCZAeumU+ICQywl5rnYPjHfN/bXYPWLtEl/SszGQVRxuGApXMoo82jSo9MHTPWSw EAgTLNKnB0qcEjWu8bO6FZctc4EXgpiuLyEwrh66OrOOyunpNXTxMQKvp9elnKPqgJgXCoy6bAEGW 5hYxr3XaNiCEOuuq67Q/y8MjRVad4v0sLPDEuZz7DKHYHf1qLgKSNw7rfFLmtpFSGwyFx1BwgaB88 wvkM8Lqw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kY45M-0005rL-Su; Thu, 29 Oct 2020 09:19:08 +0000 Received: from szxga04-in.huawei.com ([45.249.212.190]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kY45I-0005oy-Dm for linux-arm-kernel@lists.infradead.org; Thu, 29 Oct 2020 09:19:06 +0000 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CMKd00X6WzkYYL; Thu, 29 Oct 2020 17:19:00 +0800 (CST) Received: from huawei.com (10.175.127.227) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Thu, 29 Oct 2020 17:18:47 +0800 From: Yu Kuai To: , , Subject: [PATCH] iommu/sun50i: check return value of of_find_device_by_node() in sun50i_iommu_of_xlate() Date: Thu, 29 Oct 2020 17:22:44 +0800 Message-ID: <20201029092244.900564-1-yukuai3@huawei.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201029_051905_336316_D613DA7A X-CRM114-Status: UNSURE ( 9.93 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yukuai3@huawei.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, yi.zhang@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If of_find_device_by_node() failed in sun50i_iommu_of_xlate(), null pointer dereference will be triggered. Thus return error code if of_find_device_by_node() failed. Fixes: 4100b8c229b3("iommu: Add Allwinner H6 IOMMU driver") Signed-off-by: Yu Kuai Acked-by: Maxime Ripard --- drivers/iommu/sun50i-iommu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index ea6db1341916..ce94ffa15215 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -764,6 +764,9 @@ static int sun50i_iommu_of_xlate(struct device *dev, struct platform_device *iommu_pdev = of_find_device_by_node(args->np); unsigned id = args->args[0]; + if (!iommu_pdev) + return -ENODEV; + dev_iommu_priv_set(dev, platform_get_drvdata(iommu_pdev)); return iommu_fwspec_add_ids(dev, &id, 1);