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: 9189355 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 0F7C361281 for ; Tue, 21 Jun 2016 04:35:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A9F327FA3 for ; Tue, 21 Jun 2016 04:35:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F357C27FA5; Tue, 21 Jun 2016 04:35:56 +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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E45A27FA3 for ; Tue, 21 Jun 2016 04:35:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFDPo-0001X3-5G; Tue, 21 Jun 2016 04:35:56 +0000 Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFDPJ-0000pD-Tm for linux-rockchip@lists.infradead.org; Tue, 21 Jun 2016 04:35:27 +0000 Received: by mail-pa0-x22e.google.com with SMTP id b13so2222920pat.0 for ; Mon, 20 Jun 2016 21:35:05 -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=jFxjJHLcz6LwNpkl1wfmw5EaZXAQa8zIXc/J9ax6AwcnQaG2PbxvWrCeFAn2jaqBAL 2jziki+MBHGkr9Eo9dRxx58GpI+wi41qMAR112O0iHMTJVj3EwOJ8wmR12PM4SL90CyI er+qdz/cgGSTJYSC/d8bcrbIAgKDKzbt1CXnyPZ0Bv4b7j0Pr4obKNxS7F2JNl+rQQWM gFVYGkiLGLBVO8LdiVASmlp6FW/RwdlNxuUrEruXhQZFH/qvFZgxM5u3qSEuvLBl2L66 vqbyL829kTIipgoEIALq9tkHoY0JBeYGEPbieedcCklvtZuOArmd4z6LbPSi0RKaRlIq OsAA== X-Gm-Message-State: ALyK8tIeXmVjZAy2lZ9baIyLnGoa9yfL6Ixnz7LZui0cIzNtNaPREW1aDwwyawRvAvL6Q6JA 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160620_213526_140725_47FF2E38 X-CRM114-Status: GOOD ( 11.80 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , David Airlie , Joerg Roedel , linux-kernel@vger.kernel.org, Daniel Kurtz , Tomasz Figa , linux-rockchip@lists.infradead.org, Marek Szyprowski , Shunqian Zheng , linux-arm-kernel@lists.infradead.org, Mark Yao MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org 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;