From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: [PATCH 3/3] common/spinlock: Ensure the flags parameter is wide enough Date: Mon, 21 Oct 2013 14:41:33 +0100 Message-ID: <1382362893-12603-4-git-send-email-andrew.cooper3@citrix.com> References: <1382362893-12603-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1382362893-12603-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Keir Fraser , Ian Campbell , Andrew Cooper , Tim Deegan , Stefano Stabellini , Jan Beulich List-Id: xen-devel@lists.xenproject.org Because of the construction of spin_lock_irq() (and varients), the flags parameter could be trucated. Use a BUILD_BUG_ON() to verify the width of the parameter. Signed-off-by: Andrew Cooper CC: Keir Fraser CC: Jan Beulich CC: Ian Campbell CC: Stefano Stabellini CC: Tim Deegan --- The previous patch in the series fixes the compilation issues I found as a result of this patch, but I have not tested on arm. I therefore request an explicit ack from an arm maintainer before this is committed. --- xen/include/xen/spinlock.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 76581c5..12b0a89 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -188,7 +188,11 @@ int _rw_is_write_locked(rwlock_t *lock); #define spin_lock(l) _spin_lock(l) #define spin_lock_irq(l) _spin_lock_irq(l) -#define spin_lock_irqsave(l, f) ((f) = _spin_lock_irqsave(l)) +#define spin_lock_irqsave(l, f) \ + ({ \ + BUILD_BUG_ON(sizeof(f) != sizeof(unsigned long)); \ + ((f) = _spin_lock_irqsave(l)); \ + }) #define spin_unlock(l) _spin_unlock(l) #define spin_unlock_irq(l) _spin_unlock_irq(l) @@ -220,7 +224,11 @@ int _rw_is_write_locked(rwlock_t *lock); #define read_lock(l) _read_lock(l) #define read_lock_irq(l) _read_lock_irq(l) -#define read_lock_irqsave(l, f) ((f) = _read_lock_irqsave(l)) +#define read_lock_irqsave(l, f) \ + ({ \ + BUILD_BUG_ON(sizeof(f) != sizeof(unsigned long)); \ + ((f) = _read_lock_irqsave(l)); \ + }) #define read_unlock(l) _read_unlock(l) #define read_unlock_irq(l) _read_unlock_irq(l) @@ -229,7 +237,11 @@ int _rw_is_write_locked(rwlock_t *lock); #define write_lock(l) _write_lock(l) #define write_lock_irq(l) _write_lock_irq(l) -#define write_lock_irqsave(l, f) ((f) = _write_lock_irqsave(l)) +#define write_lock_irqsave(l, f) \ + ({ \ + BUILD_BUG_ON(sizeof(f) != sizeof(unsigned long)); \ + ((f) = _write_lock_irqsave(l)); \ + }) #define write_trylock(l) _write_trylock(l) #define write_unlock(l) _write_unlock(l) -- 1.7.10.4