sys_io: don't allow negative bit offsets

Use of these is the mark of a deranged imagination.

Change-Id: Ib4b5f78cf61c016e333288090b397e9a3e0b8a40
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2016-03-02 12:28:09 -08:00 committed by Gerrit Code Review
commit f0a01163be
3 changed files with 42 additions and 42 deletions

View file

@ -70,7 +70,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void sys_io_set_bit(io_port_t port, int bit) void sys_io_set_bit(io_port_t port, unsigned int bit)
{ {
uint32_t reg = 0; uint32_t reg = 0;
@ -84,7 +84,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void sys_io_clear_bit(io_port_t port, int bit) void sys_io_clear_bit(io_port_t port, unsigned int bit)
{ {
uint32_t reg = 0; uint32_t reg = 0;
@ -98,7 +98,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_io_test_bit(io_port_t port, int bit) int sys_io_test_bit(io_port_t port, unsigned int bit)
{ {
uint32_t status = _ARC_V2_STATUS32; uint32_t status = _ARC_V2_STATUS32;
uint32_t reg = 0; uint32_t reg = 0;
@ -116,7 +116,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_io_test_and_set_bit(io_port_t port, int bit) int sys_io_test_and_set_bit(io_port_t port, unsigned int bit)
{ {
int ret; int ret;
@ -127,7 +127,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_io_test_and_clear_bit(io_port_t port, int bit) int sys_io_test_and_clear_bit(io_port_t port, unsigned int bit)
{ {
int ret; int ret;
@ -204,7 +204,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void sys_set_bit(mem_addr_t addr, int bit) void sys_set_bit(mem_addr_t addr, unsigned int bit)
{ {
uint32_t reg = 0; uint32_t reg = 0;
@ -217,7 +217,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void sys_clear_bit(mem_addr_t addr, int bit) void sys_clear_bit(mem_addr_t addr, unsigned int bit)
{ {
uint32_t reg = 0; uint32_t reg = 0;
@ -230,7 +230,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_test_bit(mem_addr_t addr, int bit) int sys_test_bit(mem_addr_t addr, unsigned int bit)
{ {
uint32_t status = _ARC_V2_STATUS32; uint32_t status = _ARC_V2_STATUS32;
uint32_t reg = 0; uint32_t reg = 0;
@ -248,7 +248,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_test_and_set_bit(mem_addr_t addr, int bit) int sys_test_and_set_bit(mem_addr_t addr, unsigned int bit)
{ {
int ret; int ret;
@ -259,7 +259,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_test_and_clear_bit(mem_addr_t addr, int bit) int sys_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
{ {
int ret; int ret;
@ -270,7 +270,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void sys_bitfield_set_bit(mem_addr_t addr, int bit) void sys_bitfield_set_bit(mem_addr_t addr, unsigned int bit)
{ {
/* Doing memory offsets in terms of 32-bit values to prevent /* Doing memory offsets in terms of 32-bit values to prevent
* alignment issues * alignment issues
@ -279,20 +279,20 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void sys_bitfield_clear_bit(mem_addr_t addr, int bit) void sys_bitfield_clear_bit(mem_addr_t addr, unsigned int bit)
{ {
sys_clear_bit(addr + ((bit >> 5) << 2), bit & 0x1F); sys_clear_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_bitfield_test_bit(mem_addr_t addr, int bit) int sys_bitfield_test_bit(mem_addr_t addr, unsigned int bit)
{ {
return sys_test_bit(addr + ((bit >> 5) << 2), bit & 0x1F); return sys_test_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_bitfield_test_and_set_bit(mem_addr_t addr, int bit) int sys_bitfield_test_and_set_bit(mem_addr_t addr, unsigned int bit)
{ {
int ret; int ret;
@ -303,7 +303,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_bitfield_test_and_clear_bit(mem_addr_t addr, int bit) int sys_bitfield_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
{ {
int ret; int ret;

View file

@ -108,7 +108,7 @@ static inline __attribute__((always_inline)) void _do_irq_unlock(void)
static ALWAYS_INLINE unsigned int find_lsb_set(uint32_t op) static ALWAYS_INLINE unsigned int find_lsb_set(uint32_t op)
{ {
int bitpos; unsigned int bitpos;
__asm__ volatile ( __asm__ volatile (
@ -158,7 +158,7 @@ static ALWAYS_INLINE unsigned int find_lsb_set(uint32_t op)
static ALWAYS_INLINE unsigned int find_msb_set(uint32_t op) static ALWAYS_INLINE unsigned int find_msb_set(uint32_t op)
{ {
int bitpos; unsigned int bitpos;
__asm__ volatile ( __asm__ volatile (
@ -304,7 +304,7 @@ static inline __attribute__((always_inline))
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void sys_io_set_bit(io_port_t port, int bit) void sys_io_set_bit(io_port_t port, unsigned int bit)
{ {
uint32_t reg = 0; uint32_t reg = 0;
@ -316,7 +316,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void sys_io_clear_bit(io_port_t port, int bit) void sys_io_clear_bit(io_port_t port, unsigned int bit)
{ {
uint32_t reg = 0; uint32_t reg = 0;
@ -328,7 +328,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_io_test_bit(io_port_t port, int bit) int sys_io_test_bit(io_port_t port, unsigned int bit)
{ {
uint32_t ret; uint32_t ret;
@ -341,7 +341,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_io_test_and_set_bit(io_port_t port, int bit) int sys_io_test_and_set_bit(io_port_t port, unsigned int bit)
{ {
int ret; int ret;
@ -352,7 +352,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_io_test_and_clear_bit(io_port_t port, int bit) int sys_io_test_and_clear_bit(io_port_t port, unsigned int bit)
{ {
int ret; int ret;
@ -430,7 +430,7 @@ static inline __attribute__((always_inline))
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void sys_set_bit(mem_addr_t addr, int bit) void sys_set_bit(mem_addr_t addr, unsigned int bit)
{ {
__asm__ volatile("btsl %1, %0;\n\t" __asm__ volatile("btsl %1, %0;\n\t"
: "+m" (*(volatile uint32_t *) (addr)) : "+m" (*(volatile uint32_t *) (addr))
@ -439,7 +439,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void sys_clear_bit(mem_addr_t addr, int bit) void sys_clear_bit(mem_addr_t addr, unsigned int bit)
{ {
__asm__ volatile("btrl %1, %0;\n\t" __asm__ volatile("btrl %1, %0;\n\t"
: "+m" (*(volatile uint32_t *) (addr)) : "+m" (*(volatile uint32_t *) (addr))
@ -447,7 +447,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_test_bit(mem_addr_t addr, int bit) int sys_test_bit(mem_addr_t addr, unsigned int bit)
{ {
int ret; int ret;
@ -460,7 +460,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_test_and_set_bit(mem_addr_t addr, int bit) int sys_test_and_set_bit(mem_addr_t addr, unsigned int bit)
{ {
int ret; int ret;
@ -473,7 +473,7 @@ static inline __attribute__((always_inline))
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
int sys_test_and_clear_bit(mem_addr_t addr, int bit) int sys_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
{ {
int ret; int ret;

View file

@ -97,7 +97,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline void sys_io_set_bit(io_port_t port, int bit) * @fn static inline void sys_io_set_bit(io_port_t port, unsigned int bit)
* @brief Set the designated bit from port to 1 * @brief Set the designated bit from port to 1
* *
* This functions takes the designated bit starting from port and sets it to 1. * This functions takes the designated bit starting from port and sets it to 1.
@ -107,7 +107,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline void sys_io_clear_bit(io_port_t port, int bit) * @fn static inline void sys_io_clear_bit(io_port_t port, unsigned int bit)
* @brief Clear the designated bit from port to 0 * @brief Clear the designated bit from port to 0
* *
* This functions takes the designated bit starting from port and sets it to 0. * This functions takes the designated bit starting from port and sets it to 0.
@ -117,7 +117,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline int sys_io_test_bit(io_port_t port, int bit) * @fn static inline int sys_io_test_bit(io_port_t port, unsigned int bit)
* @brief Test the bit from port if it is set or not * @brief Test the bit from port if it is set or not
* *
* This functions takes the designated bit starting from port and tests its * This functions takes the designated bit starting from port and tests its
@ -130,7 +130,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline int sys_io_test_and_set_bit(io_port_t port, int bit) * @fn static inline int sys_io_test_and_set_bit(io_port_t port, unsigned int bit)
* @brief Test the bit from port and set it * @brief Test the bit from port and set it
* *
* This functions takes the designated bit starting from port, tests its * This functions takes the designated bit starting from port, tests its
@ -143,7 +143,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline int sys_io_test_and_clear_bit(io_port_t port, int bit) * @fn static inline int sys_io_test_and_clear_bit(io_port_t port, unsigned int bit)
* @brief Test the bit from port and clear it * @brief Test the bit from port and clear it
* *
* This functions takes the designated bit starting from port, tests its * This functions takes the designated bit starting from port, tests its
@ -225,7 +225,7 @@ typedef uint32_t mem_addr_t;
/* Memory bits manipulation functions */ /* Memory bits manipulation functions */
/** /**
* @fn static inline void sys_set_bit(mem_addr_t addr, int bit) * @fn static inline void sys_set_bit(mem_addr_t addr, unsigned int bit)
* @brief Set the designated bit from addr to 1 * @brief Set the designated bit from addr to 1
* *
* This functions takes the designated bit starting from addr and sets it to 1. * This functions takes the designated bit starting from addr and sets it to 1.
@ -235,7 +235,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline void sys_clear_bit(mem_addr_t addr, int bit) * @fn static inline void sys_clear_bit(mem_addr_t addr, unsigned int bit)
* @brief Clear the designated bit from addr to 0 * @brief Clear the designated bit from addr to 0
* *
* This functions takes the designated bit starting from addr and sets it to 0. * This functions takes the designated bit starting from addr and sets it to 0.
@ -245,7 +245,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline int sys_test_bit(mem_addr_t addr, int bit) * @fn static inline int sys_test_bit(mem_addr_t addr, unsigned int bit)
* @brief Test the bit if it is set or not * @brief Test the bit if it is set or not
* *
* This functions takes the designated bit starting from addr and tests its * This functions takes the designated bit starting from addr and tests its
@ -258,7 +258,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline int sys_test_and_set_bit(mem_addr_t addr, int bit) * @fn static inline int sys_test_and_set_bit(mem_addr_t addr, unsigned int bit)
* @brief Test the bit and set it * @brief Test the bit and set it
* *
* This functions takes the designated bit starting from addr, tests its * This functions takes the designated bit starting from addr, tests its
@ -271,7 +271,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline int sys_test_and_clear_bit(mem_addr_t addr, int bit) * @fn static inline int sys_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
* @brief Test the bit and clear it * @brief Test the bit and clear it
* *
* This functions takes the designated bit starting from addr, test its * This functions takes the designated bit starting from addr, test its
@ -284,7 +284,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline void sys_bitfield_set_bit(mem_addr_t addr, int bit) * @fn static inline void sys_bitfield_set_bit(mem_addr_t addr, unsigned int bit)
* @brief Set the designated bit from addr to 1 * @brief Set the designated bit from addr to 1
* *
* This functions takes the designated bit starting from addr and sets it to 1. * This functions takes the designated bit starting from addr and sets it to 1.
@ -294,7 +294,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline void sys_bitfield_clear_bit(mem_addr_t addr, int bit) * @fn static inline void sys_bitfield_clear_bit(mem_addr_t addr, unsigned int bit)
* @brief Clear the designated bit from addr to 0 * @brief Clear the designated bit from addr to 0
* *
* This functions takes the designated bit starting from addr and sets it to 0. * This functions takes the designated bit starting from addr and sets it to 0.
@ -304,7 +304,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline int sys_bitfield_test_bit(mem_addr_t addr, int bit) * @fn static inline int sys_bitfield_test_bit(mem_addr_t addr, unsigned int bit)
* @brief Test the bit if it is set or not * @brief Test the bit if it is set or not
* *
* This functions takes the designated bit starting from addr and tests its * This functions takes the designated bit starting from addr and tests its
@ -317,7 +317,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline int sys_bitfield_test_and_set_bit(mem_addr_t addr, int bit) * @fn static inline int sys_bitfield_test_and_set_bit(mem_addr_t addr, unsigned int bit)
* @brief Test the bit and set it * @brief Test the bit and set it
* *
* This functions takes the designated bit starting from addr, tests its * This functions takes the designated bit starting from addr, tests its
@ -330,7 +330,7 @@ typedef uint32_t mem_addr_t;
*/ */
/** /**
* @fn static inline int sys_bitfield_test_and_clear_bit(mem_addr_t addr, int bit) * @fn static inline int sys_bitfield_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
* @brief Test the bit and clear it * @brief Test the bit and clear it
* *
* This functions takes the designated bit starting from addr, test its * This functions takes the designated bit starting from addr, test its