lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1431976122-4228-7-git-send-email-vladimir_zapolskiy@mentor.com>
Date:	Mon, 18 May 2015 22:08:39 +0300
From:	Vladimir Zapolskiy <vladimir_zapolskiy@...tor.com>
To:	Philipp Zabel <p.zabel@...gutronix.de>,
	Heiko Stübner <heiko@...ech.de>,
	Arnd Bergmann <arnd@...db.de>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
CC:	<linux-kernel@...r.kernel.org>
Subject: [PATCH v3 6/9] misc: sram: add private struct device and virt_base members

No functional change, this is a preceding change to simplify
separation of reserved partition handling logic from probe()
function.

Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@...tor.com>
---
Changes from v1 to v2:
- rebased on top of v2 3/9 misc: sram: use phys_addr_t instead of u32
  for physical address

 drivers/misc/sram.c | 46 +++++++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
index 75e6245..1ad979f 100644
--- a/drivers/misc/sram.c
+++ b/drivers/misc/sram.c
@@ -35,6 +35,9 @@
 #define SRAM_GRANULARITY	32
 
 struct sram_dev {
+	struct device *dev;
+	void __iomem *virt_base;
+
 	struct gen_pool *pool;
 	struct clk *clk;
 };
@@ -56,7 +59,6 @@ static int sram_reserve_cmp(void *priv, struct list_head *a,
 
 static int sram_probe(struct platform_device *pdev)
 {
-	void __iomem *virt_base;
 	struct sram_dev *sram;
 	struct resource *res;
 	struct device_node *np = pdev->dev.of_node, *child;
@@ -69,34 +71,36 @@ static int sram_probe(struct platform_device *pdev)
 
 	INIT_LIST_HEAD(&reserve_list);
 
+	sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
+	if (!sram)
+		return -ENOMEM;
+
+	sram->dev = &pdev->dev;
+
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
-		dev_err(&pdev->dev, "found no memory resource\n");
+		dev_err(sram->dev, "found no memory resource\n");
 		return -EINVAL;
 	}
 
 	size = resource_size(res);
 
-	if (!devm_request_mem_region(&pdev->dev,
+	if (!devm_request_mem_region(sram->dev,
 			res->start, size, pdev->name)) {
-		dev_err(&pdev->dev, "could not request region for resource\n");
+		dev_err(sram->dev, "could not request region for resource\n");
 		return -EBUSY;
 	}
 
-	virt_base = devm_ioremap_wc(&pdev->dev, res->start, size);
-	if (IS_ERR(virt_base))
-		return PTR_ERR(virt_base);
-
-	sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
-	if (!sram)
-		return -ENOMEM;
+	sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size);
+	if (IS_ERR(sram->virt_base))
+		return PTR_ERR(sram->virt_base);
 
-	sram->pool = devm_gen_pool_create(&pdev->dev,
+	sram->pool = devm_gen_pool_create(sram->dev,
 					  ilog2(SRAM_GRANULARITY), -1);
 	if (!sram->pool)
 		return -ENOMEM;
 
-	sram->clk = devm_clk_get(&pdev->dev, NULL);
+	sram->clk = devm_clk_get(sram->dev, NULL);
 	if (IS_ERR(sram->clk))
 		sram->clk = NULL;
 	else
@@ -119,7 +123,7 @@ static int sram_probe(struct platform_device *pdev)
 
 		ret = of_address_to_resource(child, 0, &child_res);
 		if (ret < 0) {
-			dev_err(&pdev->dev,
+			dev_err(sram->dev,
 				"could not get address for node %s\n",
 				child->full_name);
 			of_node_put(child);
@@ -127,7 +131,7 @@ static int sram_probe(struct platform_device *pdev)
 		}
 
 		if (child_res.start < res->start || child_res.end > res->end) {
-			dev_err(&pdev->dev,
+			dev_err(sram->dev,
 				"reserved block %s outside the sram area\n",
 				child->full_name);
 			ret = -EINVAL;
@@ -139,7 +143,7 @@ static int sram_probe(struct platform_device *pdev)
 		block->size = resource_size(&child_res);
 		list_add_tail(&block->list, &reserve_list);
 
-		dev_dbg(&pdev->dev, "found reserved block 0x%llx-0x%llx\n",
+		dev_dbg(sram->dev, "found reserved block 0x%llx-0x%llx\n",
 			(unsigned long long)block->start,
 			(unsigned long long)block->start + block->size);
 
@@ -158,7 +162,7 @@ static int sram_probe(struct platform_device *pdev)
 	list_for_each_entry(block, &reserve_list, list) {
 		/* can only happen if sections overlap */
 		if (block->start < cur_start) {
-			dev_err(&pdev->dev,
+			dev_err(sram->dev,
 				"block at 0x%llx starts after current offset 0x%llx\n",
 				(unsigned long long)block->start,
 				(unsigned long long)cur_start);
@@ -179,11 +183,11 @@ static int sram_probe(struct platform_device *pdev)
 		 */
 		cur_size = block->start - cur_start;
 
-		dev_dbg(&pdev->dev, "adding chunk 0x%llx-0x%llx\n",
+		dev_dbg(sram->dev, "adding chunk 0x%llx-0x%llx\n",
 			(unsigned long long)cur_start,
 			(unsigned long long)cur_start + cur_size);
 		ret = gen_pool_add_virt(sram->pool,
-				(unsigned long)virt_base + cur_start,
+				(unsigned long)sram->virt_base + cur_start,
 				res->start + cur_start, cur_size, -1);
 		if (ret < 0)
 			goto err_chunks;
@@ -197,7 +201,7 @@ static int sram_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, sram);
 
 	dev_dbg(&pdev->dev, "SRAM pool: %zu KiB @ 0x%p\n",
-		gen_pool_size(sram->pool) / 1024, virt_base);
+		gen_pool_size(sram->pool) / 1024, sram->virt_base);
 
 	return 0;
 
@@ -214,7 +218,7 @@ static int sram_remove(struct platform_device *pdev)
 	struct sram_dev *sram = platform_get_drvdata(pdev);
 
 	if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool))
-		dev_err(&pdev->dev, "removed while SRAM allocated\n");
+		dev_err(sram->dev, "removed while SRAM allocated\n");
 
 	if (sram->clk)
 		clk_disable_unprepare(sram->clk);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ