From patchwork Tue Jun 21 04:34:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 9189339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B9A0F6075A for ; Tue, 21 Jun 2016 04:35:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A729527F96 for ; Tue, 21 Jun 2016 04:35:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 995FE27F9A; Tue, 21 Jun 2016 04:35:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58E6327F96 for ; Tue, 21 Jun 2016 04:35:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8CA716E1E9; Tue, 21 Jun 2016 04:35:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-x231.google.com (mail-pa0-x231.google.com [IPv6:2607:f8b0:400e:c03::231]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1081F6E1E9 for ; Tue, 21 Jun 2016 04:35:06 +0000 (UTC) Received: by mail-pa0-x231.google.com with SMTP id wo6so2177507pac.3 for ; Mon, 20 Jun 2016 21:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rT0LtSh7SOb/jFrDTKpaSfg9ONHKrdaHTdg9XgueVKY=; b=dXBVV1k63wZurOOi3lFHD6H9wMZNVq2dJQrF0jG2+pAkVf1JNnAm/QgAOnV91ehfBI ArGb5NIzkuAaCaGJ/oUcfjD8FDgrwcDMT7WEPCPnjD5QyVDCIQklIGcKJ16lkZg4LOfe 85biV/Sig1jhFDlZfKga/vrHqcwCwcgfTqw+A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rT0LtSh7SOb/jFrDTKpaSfg9ONHKrdaHTdg9XgueVKY=; b=GGq8eudlIPc3D3KIabDtJdIYd63g634jnf6g1f/VzR7E8NlYX5Q+gnfdVcfNXcrecI 9y4peKFkWUJVbKt5fEd3Q7UZWpVSyzrjhOgNrHHwPrdPVECXOP2lbinuUhsoYHeWUrN6 sVMfRDbaCmVndHr6lkkrFQ3nyRL8Jj1/IB3plJzbVx0tT8z+PBqIDW4ems+l2N3PRGlW HlGMivmkFPZmcWzE2CzNXkP4618V4VaGMatHBkcyBj9bssHub1QqTtTzSX013B95Y21K ydWN7zQdDH/Jc8WovHzmBO+cOC54k8wlXHBixgKoMldfveWDX57eTdYGY06edvQOFUdl g7og== X-Gm-Message-State: ALyK8tI3LyKT1hLscGtnhibXeWVznnexQ3E1y057GNaj5meF7GfrkpKpCVHOfZLOyLMvofWD X-Received: by 10.66.164.34 with SMTP id yn2mr23811989pab.97.1466483705046; Mon, 20 Jun 2016 21:35:05 -0700 (PDT) Received: from basement.tok.corp.google.com ([100.103.3.207]) by smtp.gmail.com with ESMTPSA id s3sm24500160pfb.87.2016.06.20.21.35.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Jun 2016 21:35:04 -0700 (PDT) From: Tomasz Figa To: iommu@lists.linux-foundation.org, dri-devel@lists.freedesktop.org Subject: [PATCH v4 3/8] iommu/rockchip: Fix allocation of bases array in driver probe Date: Tue, 21 Jun 2016 13:34:36 +0900 Message-Id: <1466483681-36110-4-git-send-email-tfiga@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1466483681-36110-1-git-send-email-tfiga@chromium.org> References: <1466483681-36110-1-git-send-email-tfiga@chromium.org> Cc: linux-kernel@vger.kernel.org, Tomasz Figa , linux-rockchip@lists.infradead.org, Marek Szyprowski , Shunqian Zheng , linux-arm-kernel@lists.infradead.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Shunqian Zheng In .probe(), devm_kzalloc() is called with size == 0 and works only by luck, due to internal behavior of the allocator and the fact that the proper allocation size is small. Let's use proper value for calculating the size. Fixes: cd6438c5f844 ("iommu/rockchip: Reconstruct to support multi slaves") Signed-off-by: Shunqian Zheng Signed-off-by: Tomasz Figa Reviewed-by: Douglas Anderson --- drivers/iommu/rockchip-iommu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 53fa0d9..8a5bac7 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1034,6 +1034,7 @@ static int rk_iommu_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct rk_iommu *iommu; struct resource *res; + int num_res = pdev->num_resources; int i; iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL); @@ -1043,12 +1044,13 @@ static int rk_iommu_probe(struct platform_device *pdev) platform_set_drvdata(pdev, iommu); iommu->dev = dev; iommu->num_mmu = 0; - iommu->bases = devm_kzalloc(dev, sizeof(*iommu->bases) * iommu->num_mmu, + + iommu->bases = devm_kzalloc(dev, sizeof(*iommu->bases) * num_res, GFP_KERNEL); if (!iommu->bases) return -ENOMEM; - for (i = 0; i < pdev->num_resources; i++) { + for (i = 0; i < num_res; i++) { res = platform_get_resource(pdev, IORESOURCE_MEM, i); if (!res) continue;