Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965387AbXAYSGg (ORCPT ); Thu, 25 Jan 2007 13:06:36 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S965383AbXAYSGg (ORCPT ); Thu, 25 Jan 2007 13:06:36 -0500 Received: from tomts22-srv.bellnexxia.net ([209.226.175.184]:59387 "EHLO tomts22-srv.bellnexxia.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965387AbXAYSGf (ORCPT ); Thu, 25 Jan 2007 13:06:35 -0500 From: Mathieu Desnoyers To: linux-kernel@vger.kernel.org Cc: Linus Torvalds , Andrew Morton , Ingo Molnar , Greg Kroah-Hartman , Christoph Hellwig , ltt-dev@shafik.org, systemtap@sources.redhat.com, Douglas Niehaus , "Martin J. Bligh" , Thomas Gleixner , Paul Mackerras , Mathieu Desnoyers Subject: [PATCH 03/09] atomic.h : i386 type safety fix Date: Thu, 25 Jan 2007 11:15:48 -0500 Message-Id: <11697417552523-git-send-email-mathieu.desnoyers@polymtl.ca> X-Mailer: git-send-email 1.4.4.3 In-Reply-To: <11697417541743-git-send-email-mathieu.desnoyers@polymtl.ca> References: <11697417541743-git-send-email-mathieu.desnoyers@polymtl.ca> Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1604 Lines: 39 atomic.h : i386 type safety fix This patch removes an explicit cast to an integer type for the result returned by cmpxchg. It is not per se a problem on the i386 architecture, because sizeof(int) == sizeof(long), but whenever this code is cut'n'pasted to a different architecture (which happened at least for x86_64), it would simply accept passing an atomic64_t value as parameter to cmpxchg, xchg and add_unless, having 64 bits inputs casted to 32 bits. Signed-off-by: Mathieu Desnoyers --- a/include/asm-i386/atomic.h +++ b/include/asm-i386/atomic.h @@ -207,8 +207,9 @@ static __inline__ int atomic_sub_return(int i, atomic_t *v) return atomic_add_return(-i,v); } -#define atomic_cmpxchg(v, old, new) ((int)cmpxchg(&((v)->counter), old, new)) -#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) +#define atomic_cmpxchg(v, old, new) \ + ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (old), (new))) +#define atomic_xchg(v, new) (xchg(&((v)->counter), (new))) /** * atomic_add_unless - add unless the number is a given value @@ -221,7 +222,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t *v) */ #define atomic_add_unless(v, a, u) \ ({ \ - int c, old; \ + __typeof__((v)->counter) c, old; \ c = atomic_read(v); \ for (;;) { \ if (unlikely(c == (u))) \ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/