diff mbox series

[2/2,V2] xfs: don't take addresses of packed xfs_rmap_key member

Message ID b44b9c6e-4c40-2670-8c38-874a79e0d066@redhat.com (mailing list archive)
State Superseded
Headers show
Series None | expand

Commit Message

Eric Sandeen Jan. 29, 2020, 6:15 p.m. UTC
gcc now warns about taking an address of a packed structure member.

This happens here because of how be32_add_cpu() works; just open-code
the modification using a temporary variable instead.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2: fix key-> vs rec-> derp derp thinko

Comments

Christoph Hellwig Jan. 29, 2020, 6:29 p.m. UTC | #1
On Wed, Jan 29, 2020 at 12:15:06PM -0600, Eric Sandeen wrote:
>  {
>  	uint64_t		off;
> +	xfs_agblock_t		start;
>  	int			adj;
>  
>  	adj = be32_to_cpu(rec->rmap.rm_blockcount) - 1;
>  
>  	key->rmap.rm_startblock = rec->rmap.rm_startblock;
> -	be32_add_cpu(&key->rmap.rm_startblock, adj);
> +	start = be32_to_cpu(key->rmap.rm_startblock) - adj;
> +	key->rmap.rm_startblock = cpu_to_be32(start);

Do we really need the local variable?  Why not:

	key->rmap.rm_startblock =
		cpu_to_be32(be32_to_cpu(key->rmap.rm_startblock) - adj);
Eric Sandeen Jan. 29, 2020, 6:31 p.m. UTC | #2
On 1/29/20 12:29 PM, Christoph Hellwig wrote:
> On Wed, Jan 29, 2020 at 12:15:06PM -0600, Eric Sandeen wrote:
>>  {
>>  	uint64_t		off;
>> +	xfs_agblock_t		start;
>>  	int			adj;
>>  
>>  	adj = be32_to_cpu(rec->rmap.rm_blockcount) - 1;
>>  
>>  	key->rmap.rm_startblock = rec->rmap.rm_startblock;
>> -	be32_add_cpu(&key->rmap.rm_startblock, adj);
>> +	start = be32_to_cpu(key->rmap.rm_startblock) - adj;
>> +	key->rmap.rm_startblock = cpu_to_be32(start);
> 
> Do we really need the local variable?  Why not:
> 
> 	key->rmap.rm_startblock =
> 		cpu_to_be32(be32_to_cpu(key->rmap.rm_startblock) - adj);
> 

Sure

-Eric
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_rmap_btree.c b/fs/xfs/libxfs/xfs_rmap_btree.c
index fc78efa52c94..9e5ac773fc9e 100644
--- a/fs/xfs/libxfs/xfs_rmap_btree.c
+++ b/fs/xfs/libxfs/xfs_rmap_btree.c
@@ -182,12 +182,14 @@  xfs_rmapbt_init_high_key_from_rec(
 	union xfs_btree_rec	*rec)
 {
 	uint64_t		off;
+	xfs_agblock_t		start;
 	int			adj;
 
 	adj = be32_to_cpu(rec->rmap.rm_blockcount) - 1;
 
 	key->rmap.rm_startblock = rec->rmap.rm_startblock;
-	be32_add_cpu(&key->rmap.rm_startblock, adj);
+	start = be32_to_cpu(key->rmap.rm_startblock) - adj;
+	key->rmap.rm_startblock = cpu_to_be32(start);
 	key->rmap.rm_owner = rec->rmap.rm_owner;
 	key->rmap.rm_offset = rec->rmap.rm_offset;
 	if (XFS_RMAP_NON_INODE_OWNER(be64_to_cpu(rec->rmap.rm_owner)) ||