Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 1/5] cifs: turn BCC into a static inlined function
Date: Thu, 31 Mar 2011 17:36:41 -0400	[thread overview]
Message-ID: <1301607405-4379-2-git-send-email-jlayton@redhat.com> (raw)
In-Reply-To: <1301607405-4379-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

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-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 fs/cifs/cifspdu.h |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h
index 291d735..de3aa28 100644
--- a/fs/cifs/cifspdu.h
+++ b/fs/cifs/cifspdu.h
@@ -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)
-- 
1.7.4

  parent reply	other threads:[~2011-03-31 21:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-31 21:36 [PATCH 0/5] cifs: various cleanups pointed out by David Howells Jeff Layton
     [not found] ` <1301607405-4379-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-03-31 21:36   ` Jeff Layton [this message]
2011-03-31 21:36   ` [PATCH 2/5] cifs: remove unneeded variable initialization in cifs_reconnect_tcon Jeff Layton
     [not found]     ` <1301607405-4379-3-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-04-05 17:06       ` Steve French
     [not found]         ` <BANLkTin4Js462-nZcBcSYD6YO_1b9UEeRA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-04-05 17:17           ` Jeff Layton
     [not found]             ` <20110405101729.27657db0-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2011-04-05 17:20               ` Steve French
     [not found]                 ` <BANLkTi=pfFJKs3ZE1ogZrxpaJGf94RFxew-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-04-05 17:28                   ` Jeff Layton
2011-03-31 21:36   ` [PATCH 3/5] cifs: fix comment in validate_t2 Jeff Layton
2011-03-31 21:36   ` [PATCH 4/5] cifs: clean up length checks in check2ndT2 Jeff Layton
2011-03-31 21:36   ` [PATCH 5/5] cifs: clean up various nits in unicode routines Jeff Layton
     [not found]     ` <1301607405-4379-6-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-04-05 17:23       ` Steve French
     [not found]         ` <20110405103209.75fb7da5-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2011-04-05 17:58           ` David Howells
     [not found]             ` <7828.1302026339-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-04-05 18:00               ` Steve French
2011-04-05 18:01               ` David Howells
     [not found]                 ` <7882.1302026478-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-04-05 18:37                   ` Jeff Layton
     [not found]         ` <BANLkTino1a1Wr55BCynPGK176Zbm5DPcXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-04-05 17:32           ` Jeff Layton
2011-04-05 19:02           ` [PATCH] cifs: clean up various nits in unicode routines (try #2) Jeff Layton
     [not found]             ` <1302030157-5486-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-04-05 19:11               ` Steve French

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1301607405-4379-2-git-send-email-jlayton@redhat.com \
    --to=jlayton-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox