Skip to contentSkip to conversation

sparc/iommu: use BITS_TO_LONGS() to calculate bitmap size

PATCH In review Akinobu Mita 3 participants 4 messages Mar 24, 2013 – Mar 25, 2013 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 sparc/iommu: use BITS_TO_LONGS() to calculate bitmap size

The size of bitmaps which is accessed by bitops must be a multiple of the sizeof(long). So it would be better to use BITS_TO_LONGS() to calculate the bitmap size although IOMMU_NPTES is a multiple of BITS_PER_LONG.

This also fixes typo in the comment for IOMMU_NPTES.

---
 arch/sparc/mm/iommu.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/sparc/mm/iommu.c +5 -4
index 0f4f719..f9027fd 100644
@@ -34,7 +34,7 @@
 #define IOMMU_RNGE	IOMMU_RNGE_256MB
 #define IOMMU_START	0xF0000000
 #define IOMMU_WINSIZE	(256*1024*1024U)
-#define IOMMU_NPTES	(IOMMU_WINSIZE/PAGE_SIZE)	/* 64K PTEs, 265KB */
+#define IOMMU_NPTES	(IOMMU_WINSIZE/PAGE_SIZE)	/* 64K PTEs, 256KB */
 #define IOMMU_ORDER	6				/* 4096 * (1<<6) */
 
 /* srmmu.c */
@@ -103,10 +103,11 @@ static void __init sbus_iommu_init(struct platform_device *op)
 	iommu->regs->base = __pa((unsigned long) iommu->page_table) >> 4;
 	iommu_invalidate(iommu->regs);
 
-	bitmap = kmalloc(IOMMU_NPTES>>3, GFP_KERNEL);
+	bitmap = kmalloc(BITS_TO_LONGS(IOMMU_NPTES) * sizeof(unsigned long),
+			GFP_KERNEL);
 	if (!bitmap) {
-		prom_printf("Unable to allocate iommu bitmap [%d]\n",
-			    (int)(IOMMU_NPTES>>3));
+		prom_printf("Unable to allocate iommu bitmap [%ld]\n",
+			BITS_TO_LONGS(IOMMU_NPTES) * sizeof(unsigned long));
 		prom_halt();
 	}
 	bit_map_init(&iommu->usemap, bitmap, IOMMU_NPTES);
Signature · 1 line
1.8.1.4
maintainer
#1 lore raw

From: Akinobu Mita <[email protected]>
Date: Sun, 24 Mar 2013 17:55:05 +0900

Quoted 8 lines

The size of bitmaps which is accessed by bitops must be a multiple of the sizeof(long). So it would be better to use BITS_TO_LONGS() to calculate the bitmap size although IOMMU_NPTES is a multiple of BITS_PER_LONG.

This also fixes typo in the comment for IOMMU_NPTES.

Again, I'd rather not fix non-bugs.

You've also corrupted the indentation of the prom_printf() calls, the arguments to a function should line up with the first column after the openning parenthesis of the function call.

It was correct before your patch, it will be wrong afterwards.

But I don't want to apply this patch anyways, so don't bother resubmitting the fixed version.

Thanks.

#2 lore raw
In reply to Akinobu Mita

Hi David,

I understand that you're not going to fix a non-bug like this, but:

Quoted 19 lines · Akinobu Mita

The size of bitmaps which is accessed by bitops must be a multiple of the sizeof(long). So it would be better to use BITS_TO_LONGS() to calculate the bitmap size although IOMMU_NPTES is a multiple of BITS_PER_LONG.

This also fixes typo in the comment for IOMMU_NPTES.

---
 arch/sparc/mm/iommu.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/sparc/mm/iommu.c +0 -0
index 0f4f719..f9027fd 100644

arch/sparc/mm/iommu.c line 37

Quoted 5 lines
arch/sparc/mm/iommu.c +1 -1
@@ -34,7 +34,7 @@
 #define IOMMU_RNGE     IOMMU_RNGE_256MB
 #define IOMMU_START    0xF0000000
 #define IOMMU_WINSIZE  (256*1024*1024U)
-#define IOMMU_NPTES    (IOMMU_WINSIZE/PAGE_SIZE)       /* 64K PTEs, 265KB */
+#define IOMMU_NPTES    (IOMMU_WINSIZE/PAGE_SIZE)       /* 64K PTEs, 256KB */

Is this change worthwhile?

Thanks,

Signature · 5 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/
maintainer
#3 lore raw
In reply to Akinobu Mita

From: Julian Calaby <[email protected]>
Date: Tue, 26 Mar 2013 09:11:15 +1100

Quoted 9 lines · Akinobu Mita

arch/sparc/mm/iommu.c line 37

Quoted 6 lines
arch/sparc/mm/iommu.c +1 -1
@@ -34,7 +34,7 @@
 #define IOMMU_RNGE     IOMMU_RNGE_256MB
 #define IOMMU_START    0xF0000000
 #define IOMMU_WINSIZE  (256*1024*1024U)
-#define IOMMU_NPTES    (IOMMU_WINSIZE/PAGE_SIZE)       /* 64K PTEs, 265KB */
+#define IOMMU_NPTES    (IOMMU_WINSIZE/PAGE_SIZE)       /* 64K PTEs, 256KB */

Is this change worthwhile?

It's a comment typo fix, so sure why not.