Skip to contentSkip to conversation

cma: use macro PFN_DOWN when converting size to pages

PATCH In review Xishi Qiu 2 participants 2 messages Aug 5, 2013

Subsystems (2)
lore
Share & tools
lore

Xishi Qiu

author
#0 lore raw

PATCH v2 1/1 cma: use macro PFN_DOWN when converting size to pages

Use "PFN_DOWN(r->size)" instead of "r->size >> PAGE_SHIFT".

---
 drivers/base/dma-contiguous.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/base/dma-contiguous.c +1 -2
index 0ca5442..b3d711d 100644
@@ -206,8 +206,7 @@ static int __init cma_init_reserved_areas(void)
 
 	for (; i; --i, ++r) {
 		struct cma *cma;
-		cma = cma_create_area(PFN_DOWN(r->start),
-				      r->size >> PAGE_SHIFT);
+		cma = cma_create_area(PFN_DOWN(r->start), PFN_DOWN(r->size));
 		if (!IS_ERR(cma))
 			dev_set_cma_area(r->dev, cma);
 	}
Signature · 1 line
1.7.1
#1 lore raw
Quoted 12 lines · Xishi Qiu

Use "PFN_DOWN(r->size)" instead of "r->size >> PAGE_SHIFT".

---
 drivers/base/dma-contiguous.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/base/dma-contiguous.c +0 -0
index 0ca5442..b3d711d 100644

drivers/base/dma-contiguous.c static int __init cma_init_reserved_areas(void) · line 209

Quoted 6 lines
drivers/base/dma-contiguous.c +1 -2
@@ -206,8 +206,7 @@ static int __init cma_init_reserved_areas(void)
 
 	for (; i; --i, ++r) {
 		struct cma *cma;
-		cma = cma_create_area(PFN_DOWN(r->start),
-				      r->size >> PAGE_SHIFT);
+		cma = cma_create_area(PFN_DOWN(r->start), PFN_DOWN(r->size));

PFN_DOWN(r->start) makes sense because you are dividing and rounding a byte-granular address to a PFN.

r->size >> PAGE_SHIFT translates number of bytes into number of pages.

It ends up being the same arithmetic operation to do both things, but the units are different; the result of the second expression is not a PFN. I think this change actually worsens readability of the code.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>