From patchwork Mon Jul 4 07:59:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 12904809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D161C43334 for ; Mon, 4 Jul 2022 07:50:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :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=7J9ooU5x5D9Z44OxdZ3t3N07XQwkLoB2zwyfmEbc2M4=; b=4h+raObsuBH2mV whqPsH5V4ueTs+QKteERDnJl1XMizwqBSu/oQ2AqcZyLqbGv4rjD6ZxrM6wlXHTj2Y+LUR99h/G3c 6YIJYVAzpxyJCdl786EzMBJbAcWvQmfAmkklfzyrfuLaiimvjIkJvdBPwISJnZIjxHupkdUzJyODK sNxbmSg3ByHNSJJYS7botq+stFG9nwS5ScYKvEFxBKQMLr99vjK+jCQPS4Ot1dbQiJKSWmv71GyRy dUX3+gdKAB2lfvVK8n1CS1ZwVR8/HB+MNXvA4r0MlAYDJpUa4zNwMuxsQPruNj2ysRfiOkZCdINiv 2zlcaQqhFojq3jkvfYdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8Gpp-005q4B-OJ; Mon, 04 Jul 2022 07:49:33 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8Gpm-005q1k-9i; Mon, 04 Jul 2022 07:49:31 +0000 Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Lbybj6bt7z9t1Z; Mon, 4 Jul 2022 15:48:33 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 4 Jul 2022 15:49:18 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 4 Jul 2022 15:49:18 +0800 From: Yang Yingliang To: , , , , CC: , Subject: [PATCH] iommu/mediatek: check return value after calling platform_get_resource() Date: Mon, 4 Jul 2022 15:59:00 +0800 Message-ID: <20220704075900.1294218-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_004930_556599_2B36E32C X-CRM114-Status: UNSURE ( 7.94 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org It will cause null-ptr-deref if platform_get_resource() returns NULL, we need check the return value. Fixes: 42d57fc58aeb ("iommu/mediatek: Initialise/Remove for multi bank dev") Reported-by: Hulk Robot Signed-off-by: Yang Yingliang --- drivers/iommu/mtk_iommu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index b2ae84046249..b45b0c1cfff9 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -1174,6 +1174,8 @@ static int mtk_iommu_probe(struct platform_device *pdev) banks_num = data->plat_data->banks_num; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -EINVAL; if (resource_size(res) < banks_num * MTK_IOMMU_BANK_SZ) { dev_err(dev, "banknr %d. res %pR is not enough.\n", banks_num, res); return -EINVAL;