Skip to content

Commit

Permalink
cifs: turn BCC into a static inlined function
Browse files Browse the repository at this point in the history
It's a bad idea to have macro functions that reference variables more
than once, as the arguments could have side effects. Turn BCC() into
a static inlined function instead.

While we're at it, make it return a void * to discourage anyone from
dereferencing it as-is.

Reported-and-acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru>
Signed-off-by: Steve French <sfrench@us.ibm.com>
  • Loading branch information
jtlayton authored and Steve French committed May 19, 2011
1 parent 820a803 commit 460458c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fs/cifs/cifspdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,12 @@ struct smb_hdr {
__u8 WordCount;
} __attribute__((packed));

/* given a pointer to an smb_hdr retrieve a char pointer to the byte count */
#define BCC(smb_var) ((unsigned char *)(smb_var) + sizeof(struct smb_hdr) + \
(2 * (smb_var)->WordCount))
/* given a pointer to an smb_hdr, retrieve a void pointer to the ByteCount */
static inline void *
BCC(struct smb_hdr *smb)
{
return (void *)smb + sizeof(*smb) + 2 * smb->WordCount;
}

/* given a pointer to an smb_hdr retrieve the pointer to the byte area */
#define pByteArea(smb_var) (BCC(smb_var) + 2)
Expand Down

0 comments on commit 460458c

Please sign in to comment.