Skip to contentSkip to conversation

x86: remove cast from void*

PATCH In review matt mooney 3 participants 6 messages Sep 14, 2010 – Sep 21, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 x86: remove cast from void*

Unnecessary cast from void* in assignment.

---
 arch/x86/xen/mmu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/xen/mmu.c +1 -1
index 42086ac..7436283 100644
@@ -737,7 +737,7 @@ pgd_t *xen_get_user_pgd(pgd_t *pgd)
 
 	if (offset < pgd_index(USER_LIMIT)) {
 		struct page *page = virt_to_page(pgd_page);
-		user_ptr = (pgd_t *)page->private;
+		user_ptr = page->private;
 		if (user_ptr)
 			user_ptr += offset;
 	}
Signature · 1 line
1.7.2.1
#1 lore raw
Quoted 1 line · matt mooney

Unnecessary cast from void* in assignment.

Not very keen on this. The cast may not be strictly required, but it does document what's going on there.

J

Quoted 18 lines
---
 arch/x86/xen/mmu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/xen/mmu.c +1 -1
index 42086ac..7436283 100644
@@ -737,7 +737,7 @@ pgd_t *xen_get_user_pgd(pgd_t *pgd)
 
 	if (offset < pgd_index(USER_LIMIT)) {
 		struct page *page = virt_to_page(pgd_page);
-		user_ptr = (pgd_t *)page->private;
+		user_ptr = page->private;
 		if (user_ptr)
 			user_ptr += offset;
 	}
#2 lore raw
Quoted 6 lines · Jeremy Fitzhardinge
Quoted 1 line · matt mooney

Unnecessary cast from void* in assignment.

Not very keen on this. The cast may not be strictly required, but it does document what's going on there.

But unnecessary casts are problematic in that if the type changes, they can hide a real bug in the future.

-hpa

#3 lore raw
Quoted 8 lines · H. Peter Anvin
Quoted 5 lines · Jeremy Fitzhardinge
Quoted 1 line · matt mooney

Unnecessary cast from void* in assignment.

Not very keen on this. The cast may not be strictly required, but it does document what's going on there.

But unnecessary casts are problematic in that if the type changes, they can hide a real bug in the future.

If page->private changes in a way which invalidates this kind of usage, I would hope it would also change name to something more descriptive of its new role. If it changes type but is broadly compatible with this usage (say, void * -> unsigned long), then the cast won't matter, or will become a requirement.

I'm more concerned about "user_ptr" changing type, in which case the cast will highlight the problem.

In general, the casts from these kinds of generic/polymorphic fields let you easily eyeball how they're being used, without having to work out what the type of the other side is.

J

#4 lore raw
In reply to matt mooney
Quoted 12 lines · matt mooney

Unnecessary cast from void* in assignment.

---
 arch/x86/xen/mmu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/xen/mmu.c +0 -0
index 42086ac..7436283 100644

arch/x86/xen/mmu.c pgd_t *xen_get_user_pgd(pgd_t *pgd) · line 740

Quoted 5 lines
arch/x86/xen/mmu.c +1 -1
@@ -737,7 +737,7 @@ pgd_t *xen_get_user_pgd(pgd_t *pgd)
 
 	if (offset < pgd_index(USER_LIMIT)) {
 		struct page *page = virt_to_page(pgd_page);
-		user_ptr = (pgd_t *)page->private;
+		user_ptr = page->private;

Um, page->private is unsigned long anyway, so this is needed either way.

J

#5 lore raw
Quoted 14 lines · Jeremy Fitzhardinge
Quoted 13 lines · matt mooney

Unnecessary cast from void* in assignment.

---
 arch/x86/xen/mmu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/xen/mmu.c +0 -0
index 42086ac..7436283 100644
@@ -737,7 +737,7 @@ pgd_t *xen_get_user_pgd(pgd_t *pgd)
 
Quoted 7 lines

arch/x86/xen/mmu.c pgd_t *xen_get_user_pgd(pgd_t *pgd) · line 740

Quoted 4 lines
arch/x86/xen/mmu.c +1 -1
 	if (offset < pgd_index(USER_LIMIT)) {
 		struct page *page = virt_to_page(pgd_page);
-		user_ptr = (pgd_t *)page->private;
+		user_ptr = page->private;

Um, page->private is unsigned long anyway, so this is needed either way.

You're right. I missed that one, sorry; I really thought I had verified it.

-mfm