Skip to contentSkip to conversation

of: unittest: fix warning on PowerPC frame size warning

PATCH Applied Jim Quinlan 5 participants 6 messages Dec 10, 2021 – Dec 15, 2021 Device tree

lore
Share & tools
lore
#0 lore raw

v2 cover of: unittest: fix warning on PowerPC frame size warning

v2 -- Fix memory leak (Florian).

v1 -- Original.

Jim Quinlan (1):
of: unittest: fix warning on PowerPC frame size warning

 drivers/of/unittest.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

base-commit: c741e49150dbb0c0aebe234389f4aa8b47958fa8

Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/1 of: unittest: fix warning on PowerPC frame size warning

The struct device variable "dev_bogus" was triggering this warning on a PowerPC build:

drivers/of/unittest.c: In function 'of_unittest_dma_ranges_one.constprop':
[...] >> The frame size of 1424 bytes is larger than 1024 bytes
[-Wframe-larger-than=]

This variable is now dynamically allocated.

Fixes e0d072782c734 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset")
---
 drivers/of/unittest.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/of/unittest.c +12 -4
index 481ba8682ebf..02c5cd06ad19 100644
@@ -911,11 +911,18 @@ static void __init of_unittest_dma_ranges_one(const char *path,
 	if (!rc) {
 		phys_addr_t	paddr;
 		dma_addr_t	dma_addr;
-		struct device	dev_bogus;
+		struct device	*dev_bogus;
 
-		dev_bogus.dma_range_map = map;
-		paddr = dma_to_phys(&dev_bogus, expect_dma_addr);
-		dma_addr = phys_to_dma(&dev_bogus, expect_paddr);
+		dev_bogus = kzalloc(sizeof(struct device), GFP_KERNEL);
+		if (!dev_bogus) {
+			unittest(0, "kzalloc() failed\n");
+			kfree(map);
+			return;
+		}
+
+		dev_bogus->dma_range_map = map;
+		paddr = dma_to_phys(dev_bogus, expect_dma_addr);
+		dma_addr = phys_to_dma(dev_bogus, expect_paddr);
 
 		unittest(paddr == expect_paddr,
 			 "of_dma_get_range: wrong phys addr %pap (expecting %llx) on node %pOF\n",
@@ -925,6 +932,7 @@ static void __init of_unittest_dma_ranges_one(const char *path,
 			 &dma_addr, expect_dma_addr, np);
 
 		kfree(map);
+		kfree(dev_bogus);
 	}
 	of_node_put(np);
 #endif
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#2 lore raw

moved the file's maintainers from the "cc:" list to the "to:" list

review comments below

Quoted 8 lines · Jim Quinlan

The struct device variable "dev_bogus" was triggering this warning on a PowerPC build:

drivers/of/unittest.c: In function 'of_unittest_dma_ranges_one.constprop':
[...] >> The frame size of 1424 bytes is larger than 1024 bytes
[-Wframe-larger-than=]

This variable is now dynamically allocated.

A side effect of the change is that dev_bogus is initialized to all zeros instead of containing random data from the stack.

Quoted 37 lines
Fixes e0d072782c734 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset")
---
 drivers/of/unittest.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/of/unittest.c +11 -4
index 481ba8682ebf..02c5cd06ad19 100644
@@ -911,11 +911,18 @@ static void __init of_unittest_dma_ranges_one(const char *path,
 	if (!rc) {
 		phys_addr_t	paddr;
 		dma_addr_t	dma_addr;
-		struct device	dev_bogus;
+		struct device	*dev_bogus;
 
-		dev_bogus.dma_range_map = map;
-		paddr = dma_to_phys(&dev_bogus, expect_dma_addr);
-		dma_addr = phys_to_dma(&dev_bogus, expect_paddr);
+		dev_bogus = kzalloc(sizeof(struct device), GFP_KERNEL);
+		if (!dev_bogus) {
+			unittest(0, "kzalloc() failed\n");
+			kfree(map);
+			return;
+		}
+
+		dev_bogus->dma_range_map = map;
+		paddr = dma_to_phys(dev_bogus, expect_dma_addr);
+		dma_addr = phys_to_dma(dev_bogus, expect_paddr);
 
 		unittest(paddr == expect_paddr,
 			 "of_dma_get_range: wrong phys addr %pap (expecting %llx) on node %pOF\n",

drivers/of/unittest.c static void __init of_unittest_dma_ranges_one(const char *path, · line 938

Quoted 7 lines
drivers/of/unittest.c +1 -0
@@ -925,6 +932,7 @@ static void __init of_unittest_dma_ranges_one(const char *path,
 			 &dma_addr, expect_dma_addr, np);
 
 		kfree(map);
+		kfree(dev_bogus);
 	}
 	of_node_put(np);
 #endif
Reviewed-by on v2 1/1
#4 lore raw
In reply to Jim Quinlan
Quoted 7 lines · Jim Quinlan

The struct device variable "dev_bogus" was triggering this warning on a PowerPC build:

drivers/of/unittest.c: In function 'of_unittest_dma_ranges_one.constprop':
[...] >> The frame size of 1424 bytes is larger than 1024 bytes
[-Wframe-larger-than=]

Quoted 5 lines

This variable is now dynamically allocated.

Fixes e0d072782c734 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset")
Signature · 1 line
Florian
maintainer Applied
#5 lore raw
In reply to Jim Quinlan
Quoted 7 lines · Jim Quinlan

The struct device variable "dev_bogus" was triggering this warning on a PowerPC build:

drivers/of/unittest.c: In function 'of_unittest_dma_ranges_one.constprop':
[...] >> The frame size of 1424 bytes is larger than 1024 bytes
[-Wframe-larger-than=]

Quoted 9 lines

This variable is now dynamically allocated.

Fixes e0d072782c734 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset")
---
 drivers/of/unittest.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Applied, thanks!