unaligned: delete 1-byte accessors
Subsystems (8)
PATCH 1/1 unaligned: delete 1-byte accessors
Each and every 1-byte access is aligned!
---
There may be more unaligned stuff in arch/.
block/partitions/ldm.h | 2 +- block/partitions/msdos.c | 2 +- drivers/net/wireless/marvell/mwifiex/pcie.c | 2 +- include/linux/unaligned/generic.h | 12 ++---------- net/core/netpoll.c | 4 ++-- security/apparmor/policy_unpack.c | 2 +- 6 files changed, 8 insertions(+), 16 deletions(-)
block/partitions/ldm.h +1 -1
@@ -85,7 +85,7 @@ struct parsed_partitions;#define TOC_BITMAP2 "log"/* bitmaps in the TOCBLOCK. */ /* Borrowed from msdos.c */ -#define SYS_IND (p) (get_unaligned(&(p)->sys_ind)) +#define SYS_IND (p) ((p)->sys_ind)struct frag {/* VBLK Fragment handling */ struct list_head list;
block/partitions/msdos.c +1 -1
@@ -33,7 +33,7 @@*/ #include <asm/unaligned.h> -#define SYS_IND (p) get_unaligned(&p->sys_ind) +#define SYS_IND (p) ((p)->sys_ind)static inline sector_t nr_sects (struct partition *p) {
drivers/net/wireless/marvell/mwifiex/pcie.c +1 -1
@@ -1090,7 +1090,7 @@ static int mwifiex_pcie_alloc_sleep_cookie_buf(struct mwifiex_adapter *adapter)mwifiex_dbg (adapter,INFO ,"alloc_scook: sleep cookie=0x%x\n" , -get_unaligned (card->sleep_cookie_vbase)); + *card->sleep_cookie_vbase);return 0 ; }
include/linux/unaligned/generic.h +2 -10
@@ -9,27 +9,22 @@extern void __bad_unaligned_access_size (void );#define __get_unaligned_le (ptr) ((__force typeof(*(ptr)))({ \ - __builtin_choose_expr(sizeof(*(ptr)) == 1, *(ptr), \ __builtin_choose_expr(sizeof(*(ptr)) == 2, get_unaligned_le16((ptr)), \ __builtin_choose_expr(sizeof(*(ptr)) == 4, get_unaligned_le32((ptr)), \ __builtin_choose_expr(sizeof(*(ptr)) == 8, get_unaligned_le64((ptr)), \ - __bad_unaligned_access_size())))); \ + __bad_unaligned_access_size()))); \ }))#define __get_unaligned_be (ptr) ((__force typeof(*(ptr)))({ \ - __builtin_choose_expr(sizeof(*(ptr)) == 1, *(ptr), \ __builtin_choose_expr(sizeof(*(ptr)) == 2, get_unaligned_be16((ptr)), \ __builtin_choose_expr(sizeof(*(ptr)) == 4, get_unaligned_be32((ptr)), \ __builtin_choose_expr(sizeof(*(ptr)) == 8, get_unaligned_be64((ptr)), \ - __bad_unaligned_access_size())))); \ + __bad_unaligned_access_size()))); \ }))#define __put_unaligned_le (val, ptr) ({ \ void *__gu_p = (ptr); \ switch (sizeof(*(ptr))) { \ - case 1: \ - *(u8 *)__gu_p = (__force u8)(val); \ - break; \ case 2: \ put_unaligned_le16((__force u16)(val), __gu_p); \ break; \
@@ -48,9 +43,6 @@ extern void __bad_unaligned_access_size(void);#define __put_unaligned_be (val, ptr) ({ \ void *__gu_p = (ptr); \ switch (sizeof(*(ptr))) { \ - case 1: \ - *(u8 *)__gu_p = (__force u8)(val); \ - break; \ case 2: \ put_unaligned_be16((__force u16)(val), __gu_p); \ break; \
net/core/netpoll.c +2 -2
@@ -408,7 +408,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len) ip6h =ipv6_hdr (skb);/* ip6h->version = 6; ip6h->priority = 0; */ -put_unaligned (0x60 , (unsigned char *)ip6h); + *(unsigned char *)ip6h =0x60 ; ip6h->flow_lbl[0 ] =0 ; ip6h->flow_lbl[1 ] =0 ; ip6h->flow_lbl[2 ] =0 ;
@@ -436,7 +436,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len) iph =ip_hdr (skb);/* iph->version = 4; iph->ihl = 5; */ -put_unaligned (0x45 , (unsigned char *)iph); + *(unsigned char *)iph =0x45 ; iph->tos =0 ;put_unaligned (htons (ip_len), &(iph->tot_len)); iph->id =htons (atomic_inc_return (&ip_ident));
security/apparmor/policy_unpack.c +1 -1
@@ -301,7 +301,7 @@ static bool unpack_u8(struct aa_ext *e, u8 *data, const char *name)if (!inbounds (e,sizeof (u8))) goto fail;if (data) - *data =get_unaligned ((u8 *)e->pos); + *data = *(u8 *)e->pos; e->pos +=sizeof (u8);return 1 ; }
Quoted 1 line · Alexey Dobriyan
Each and every 1-byte access is aligned!
The design idea of this is for parsing descriptors. We simply chunk up the describing structure using get_unaligned for everything. The reason is because a lot of these structures come with reserved areas which we may make use of later. If we're using get_unaligned for everything we can simply change a u8 to a u16 in the structure absorbing the reserved padding. With your change now I'd have to chase down every byte access and replace it with get_unaligned instead of simply changing the structure.
What's the significant advantage of this change that compensates for the problems the above causes?
James
Quoted 12 lines · James Bottomley
Quoted 1 line · Alexey Dobriyan
Each and every 1-byte access is aligned!
The design idea of this is for parsing descriptors. We simply chunk up the describing structure using
get_unalignedfor everything. The reason is because a lot of these structures come with reserved areas which we may make use of later. If we're usingget_unalignedfor everything we can simply change a u8 to a u16 in the structure absorbing the reserved padding. With your change now I'd have to chase down every byte access and replace it withget_unalignedinstead of simply changing the structure.
Quoted 2 lines
What's the significant advantage of this change that compensates for the problems the above causes?
HW descriptors have fixed endianness, you're supposed to use get_unaligned_be32() and friends.
For that matter, drivers/scsi/ has exactly 2 get_unaligned() calls one of which can be changed to get_unaligned_be32().
Quoted 13 lines · Alexey Dobriyan
Quoted 12 lines · James Bottomley
Quoted 1 line · Alexey Dobriyan
Each and every 1-byte access is aligned!
The design idea of this is for parsing descriptors. We simply chunk up the describing structure using
get_unalignedfor everything. The reason is because a lot of these structures come with reserved areas which we may make use of later. If we're usingget_unalignedfor everything we can simply change a u8 to a u16 in the structure absorbing the reserved padding. With your change now I'd have to chase down every byte access and replace it withget_unalignedinstead of simply changing the structure.
Quoted 5 lines
Quoted 2 lines
What's the significant advantage of this change that compensates for the problems the above causes?
HW descriptors have fixed endianness, you're supposed to use
get_unaligned_be32()and friends.
Not if this is an internal descriptor format, which is what this is mostly used for.
Quoted 2 lines
For that matter,
drivers/scsi/has exactly 2get_unaligned()calls one of which can be changed toget_unaligned_be32().
You haven't answered the "what is the benefit of this change" question.
I mean sure we can do it, but it won't make anything more efficient
and it does help with the descriptor format to treat every structure field the same.
James
Quoted 14 lines · James Bottomley
Quoted 13 lines · Alexey Dobriyan
Quoted 12 lines · James Bottomley
Quoted 1 line · Alexey Dobriyan
Each and every 1-byte access is aligned!
The design idea of this is for parsing descriptors. We simply chunk up the describing structure using
get_unalignedfor everything. The reason is because a lot of these structures come with reserved areas which we may make use of later. If we're usingget_unalignedfor everything we can simply change a u8 to a u16 in the structure absorbing the reserved padding. With your change now I'd have to chase down every byte access and replace it withget_unalignedinstead of simply changing the structure.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
What's the significant advantage of this change that compensates for the problems the above causes?
HW descriptors have fixed endianness, you're supposed to use
get_unaligned_be32()and friends.Not if this is an internal descriptor format, which is what this is mostly used for.
Maybe, but developer is supposed to look at all struct member usages while changing types, right?
Quoted 7 lines
Quoted 2 lines
For that matter,
drivers/scsi/has exactly 2get_unaligned()calls one of which can be changed toget_unaligned_be32().You haven't answered the "what is the benefit of this change" question.
I mean sure we can do it, but it won't make anything more efficient
and it does help with the descriptor format to treat every structure field the same.
The benefit is less code, come on.
Another benefit is that typoing
get_unaligned((u16*)p)
for
get_unaligned((u8*)p)
will get detected.
Quoted 46 lines · Alexey Dobriyan
Quoted 22 lines · James Bottomley
Quoted 21 lines · Alexey Dobriyan
Quoted 19 lines · James Bottomley
Quoted 1 line · Alexey Dobriyan
Each and every 1-byte access is aligned!
The design idea of this is for parsing descriptors. We simply chunk up the describing structure using
get_unalignedfor everything. The reason is because a lot of these structures come
with reserved areas which we may make use of later. If we're usingget_unalignedfor everything we can simply change a u8 to a u16 in
the structure absorbing the reserved padding. With your change now
I'd have to chase down every byte access and replace it withget_unalignedinstead of simply changing the structure.What's the significant advantage of this change that compensates
for the problems the above causes?Quoted 5 lines
Quoted 2 lines
HW descriptors have fixed endianness, you're supposed to use
get_unaligned_be32()and friends.Not if this is an internal descriptor format, which is what this is mostly used for.
Maybe, but developer is supposed to look at all struct member usages while changing types, right?
Quoted 11 lines
Quoted 3 lines
For that matter,
drivers/scsi/has exactly 2get_unaligned()calls
one of which can be changed toget_unaligned_be32().You haven't answered the "what is the benefit of this change" question.
I mean sure we can do it, but it won't make anything more
efficient
and it does help with the descriptor format to treat every structure
field the same.The benefit is less code, come on.
Quoted 8 lines
Another benefit is that typoing
get_unaligned((u16*)p)for
get_unaligned((u8*)p)will get detected.
Well, that's not the way it's supposed to be used. It's supposed to be used as
struct desc {
u8 something;
u8 pad 1;
u16 another;
} __packed;
something = get_unaligned[_le/be](&struct.something);
So that the sizes are encoded in the descriptor structure. If you think it's badly documented, then please update that, I just don't see a benefit to a coding change that removes the u8 version of this because it makes our descriptor structure handling inconsistent.
Even if we allow people are hard coding the typedef, then making u8 not work just looks inconsistent ... you could easily have typoed u32 for u16 in the example above and there would be no detection.
James