Skip to content

Commit d428032

Browse files
Al Viropaulmckrcu
authored andcommitted
parisc: add u16 support to cmpxchg()
Add (and export) __cmpxchg_u16(), teach __cmpxchg() to use it. And get rid of manual truncation down to u8, etc. in there - the only reason for those is to avoid bogus warnings about constant truncation from sparse, and those are easy to avoid by turning that switch into conditional expression. Signed-off-by: Al Viro <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent c57e5dc commit d428032

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

arch/parisc/include/asm/cmpxchg.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,24 @@ __arch_xchg(unsigned long x, volatile void *ptr, int size)
5656
/* bug catcher for when unsupported size is used - won't link */
5757
extern void __cmpxchg_called_with_bad_pointer(void);
5858

59-
/* __cmpxchg_u32/u64 defined in arch/parisc/lib/bitops.c */
59+
/* __cmpxchg_u... defined in arch/parisc/lib/bitops.c */
60+
extern u8 __cmpxchg_u8(volatile u8 *ptr, u8 old, u8 new_);
61+
extern u16 __cmpxchg_u16(volatile u16 *ptr, u16 old, u16 new_);
6062
extern u32 __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_);
6163
extern u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new_);
62-
extern u8 __cmpxchg_u8(volatile u8 *ptr, u8 old, u8 new_);
6364

6465
/* don't worry...optimizer will get rid of most of this */
6566
static inline unsigned long
6667
__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
6768
{
68-
switch (size) {
69+
return
6970
#ifdef CONFIG_64BIT
70-
case 8: return __cmpxchg_u64((u64 *)ptr, old, new_);
71+
size == 8 ? __cmpxchg_u64(ptr, old, new_) :
7172
#endif
72-
case 4: return __cmpxchg_u32((unsigned int *)ptr,
73-
(unsigned int)old, (unsigned int)new_);
74-
case 1: return __cmpxchg_u8((u8 *)ptr, old & 0xff, new_ & 0xff);
75-
}
76-
__cmpxchg_called_with_bad_pointer();
77-
return old;
73+
size == 4 ? __cmpxchg_u32(ptr, old, new_) :
74+
size == 2 ? __cmpxchg_u16(ptr, old, new_) :
75+
size == 1 ? __cmpxchg_u8(ptr, old, new_) :
76+
(__cmpxchg_called_with_bad_pointer(), old);
7877
}
7978

8079
#define arch_cmpxchg(ptr, o, n) \

arch/parisc/kernel/parisc_ksyms.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ EXPORT_SYMBOL(memset);
2323
EXPORT_SYMBOL(__xchg8);
2424
EXPORT_SYMBOL(__xchg32);
2525
EXPORT_SYMBOL(__cmpxchg_u8);
26+
EXPORT_SYMBOL(__cmpxchg_u16);
2627
EXPORT_SYMBOL(__cmpxchg_u32);
2728
EXPORT_SYMBOL(__cmpxchg_u64);
2829
#ifdef CONFIG_SMP

arch/parisc/lib/bitops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ unsigned long notrace __xchg8(char x, volatile char *ptr)
7171

7272
CMPXCHG(u64)
7373
CMPXCHG(u32)
74+
CMPXCHG(u16)
7475
CMPXCHG(u8)

0 commit comments

Comments
 (0)