x86: remove cast from void*
Subsystems (4)
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
@@ -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
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
Signed-off-by matt mooney <[email protected]>--- arch/x86/xen/mmu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)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;if (user_ptr) user_ptr += offset; }
H. Peter Anvin
reviewerQuoted 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
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
Quoted 12 lines · matt mooney
Unnecessary cast from void* in assignment.
Signed-off-by matt mooney <[email protected]>--- arch/x86/xen/mmu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)arch/x86/xen/mmu.c +0
-0
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
Quoted 14 lines · Jeremy Fitzhardinge
Quoted 13 lines · matt mooney
Unnecessary cast from void* in assignment.
Signed-off-by matt mooney <[email protected]>--- arch/x86/xen/mmu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)arch/x86/xen/mmu.c +0
-0@@ -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
-1if (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->privateis 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