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: 9189393 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 ED3DF60756 for ; Tue, 21 Jun 2016 04:37:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA69D27F96 for ; Tue, 21 Jun 2016 04:37:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEF6027F9A; Tue, 21 Jun 2016 04:37:11 +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 8E82127F96 for ; Tue, 21 Jun 2016 04:37:11 +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 1bFDPg-0001R0-6E; Tue, 21 Jun 2016 04:35:48 +0000 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFDPJ-0000pB-Tw for linux-arm-kernel@lists.infradead.org; Tue, 21 Jun 2016 04:35:27 +0000 Received: by mail-pa0-x22c.google.com with SMTP id b13so2222918pat.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=cA+++hO7IIfIbKWiruNlcwQjS1uR1x7ALkSuGl4WyincWx2VaNvZmCp+hPy57qjivS jOvj5rDCGRyULsPNv1cclannhAm0LB1E82QfU9TUacdliG2K9NJqtapjZ98P/EBZuYZe LiqiadVOLrcpcMO+Tc6H2pIRGkz5AOnJGbZ9muxy6xvOv1KuzwGevFiQXSsQ1ckjmnXj fM5GKwCDWTMpb3S2JPV0kiWBPmIuEjGVl47n1g7uwuDIQkxwwaoI4txbhPb7Wqu6j11Q STDM2N1WDsgGfrGvHUuNkKmF7dyYOS4tgT+qsK3Rqnt+pCRp61SxrI7ZgLonl128IluC pZtw== X-Gm-Message-State: ALyK8tLqoMUjCJL0UgZa76slOPXJ0MWkxHOz7kb0Y/hQB7Sau3w+3bTdN6Wbp/q7kwpSR1p6 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_156912_48D0580A X-CRM114-Status: GOOD ( 13.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: 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-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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;