Skip to content

Commit

Permalink
openocd: convert 'unsigned' to 'unsigned int'
Browse files Browse the repository at this point in the history
Conversion done with
	checkpatch --fix-inplace -types UNSPECIFIED_INT

Ignore the cast as they could be better addressed.
Fix only minor additional checkpatch issue (spacing and line
length).

Change-Id: I4f936ffc4cedb153afa331cd293b08f4c913dc93
Signed-off-by: Antonio Borneo <[email protected]>
Reviewed-on: https://review.openocd.org/c/openocd/+/8482
Tested-by: jenkins
  • Loading branch information
borneoa committed Oct 5, 2024
1 parent a64dc23 commit 436e6f1
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 78 deletions.
48 changes: 24 additions & 24 deletions src/helper/binarybuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static const char hex_digits[] = {
'a', 'b', 'c', 'd', 'e', 'f'
};

void *buf_cpy(const void *from, void *_to, unsigned size)
void *buf_cpy(const void *from, void *_to, unsigned int size)
{
if (!from || !_to)
return NULL;
Expand All @@ -49,7 +49,7 @@ void *buf_cpy(const void *from, void *_to, unsigned size)
memcpy(_to, from, DIV_ROUND_UP(size, 8));

/* mask out bits that don't belong to the buffer */
unsigned trailing_bits = size % 8;
unsigned int trailing_bits = size % 8;
if (trailing_bits) {
uint8_t *to = _to;
to[size / 8] &= (1 << trailing_bits) - 1;
Expand All @@ -61,22 +61,22 @@ static bool buf_eq_masked(uint8_t a, uint8_t b, uint8_t m)
{
return (a & m) == (b & m);
}
static bool buf_eq_trailing(uint8_t a, uint8_t b, uint8_t m, unsigned trailing)
static bool buf_eq_trailing(uint8_t a, uint8_t b, uint8_t m, unsigned int trailing)
{
uint8_t mask = (1 << trailing) - 1;
return buf_eq_masked(a, b, mask & m);
}

bool buf_eq(const void *_buf1, const void *_buf2, unsigned size)
bool buf_eq(const void *_buf1, const void *_buf2, unsigned int size)
{
if (!_buf1 || !_buf2)
return _buf1 == _buf2;

unsigned last = size / 8;
unsigned int last = size / 8;
if (memcmp(_buf1, _buf2, last) != 0)
return false;

unsigned trailing = size % 8;
unsigned int trailing = size % 8;
if (!trailing)
return true;

Expand All @@ -85,44 +85,44 @@ bool buf_eq(const void *_buf1, const void *_buf2, unsigned size)
}

bool buf_eq_mask(const void *_buf1, const void *_buf2,
const void *_mask, unsigned size)
const void *_mask, unsigned int size)
{
if (!_buf1 || !_buf2)
return _buf1 == _buf2 && _buf1 == _mask;

const uint8_t *buf1 = _buf1, *buf2 = _buf2, *mask = _mask;
unsigned last = size / 8;
for (unsigned i = 0; i < last; i++) {
unsigned int last = size / 8;
for (unsigned int i = 0; i < last; i++) {
if (!buf_eq_masked(buf1[i], buf2[i], mask[i]))
return false;
}
unsigned trailing = size % 8;
unsigned int trailing = size % 8;
if (!trailing)
return true;
return buf_eq_trailing(buf1[last], buf2[last], mask[last], trailing);
}

void *buf_set_ones(void *_buf, unsigned size)
void *buf_set_ones(void *_buf, unsigned int size)
{
uint8_t *buf = _buf;
if (!buf)
return NULL;

memset(buf, 0xff, size / 8);

unsigned trailing_bits = size % 8;
unsigned int trailing_bits = size % 8;
if (trailing_bits)
buf[size / 8] = (1 << trailing_bits) - 1;

return buf;
}

void *buf_set_buf(const void *_src, unsigned src_start,
void *_dst, unsigned dst_start, unsigned len)
void *buf_set_buf(const void *_src, unsigned int src_start,
void *_dst, unsigned int dst_start, unsigned int len)
{
const uint8_t *src = _src;
uint8_t *dst = _dst;
unsigned i, sb, db, sq, dq, lb, lq;
unsigned int i, sb, db, sq, dq, lb, lq;

sb = src_start / 8;
db = dst_start / 8;
Expand Down Expand Up @@ -175,13 +175,13 @@ uint32_t flip_u32(uint32_t value, unsigned int num)
return c;
}

char *buf_to_hex_str(const void *_buf, unsigned buf_len)
char *buf_to_hex_str(const void *_buf, unsigned int buf_len)
{
unsigned len_bytes = DIV_ROUND_UP(buf_len, 8);
unsigned int len_bytes = DIV_ROUND_UP(buf_len, 8);
char *str = calloc(len_bytes * 2 + 1, 1);

const uint8_t *buf = _buf;
for (unsigned i = 0; i < len_bytes; i++) {
for (unsigned int i = 0; i < len_bytes; i++) {
uint8_t tmp = buf[len_bytes - i - 1];
if ((i == 0) && (buf_len % 8))
tmp &= (0xff >> (8 - (buf_len % 8)));
Expand Down Expand Up @@ -289,8 +289,8 @@ void bit_copy_queue_init(struct bit_copy_queue *q)
INIT_LIST_HEAD(&q->list);
}

int bit_copy_queued(struct bit_copy_queue *q, uint8_t *dst, unsigned dst_offset, const uint8_t *src,
unsigned src_offset, unsigned bit_count)
int bit_copy_queued(struct bit_copy_queue *q, uint8_t *dst, unsigned int dst_offset, const uint8_t *src,
unsigned int src_offset, unsigned int bit_count)
{
struct bit_copy_queue_entry *qe = malloc(sizeof(*qe));
if (!qe)
Expand Down Expand Up @@ -395,12 +395,12 @@ size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t length)
return i;
}

void buffer_shr(void *_buf, unsigned buf_len, unsigned count)
void buffer_shr(void *_buf, unsigned int buf_len, unsigned int count)
{
unsigned i;
unsigned int i;
unsigned char *buf = _buf;
unsigned bytes_to_remove;
unsigned shift;
unsigned int bytes_to_remove;
unsigned int shift;

bytes_to_remove = count / 8;
shift = count - (bytes_to_remove * 8);
Expand Down
48 changes: 24 additions & 24 deletions src/helper/binarybuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @param value Up to 32 bits that will be copied to _buffer.
*/
static inline void buf_set_u32(uint8_t *_buffer,
unsigned first, unsigned num, uint32_t value)
unsigned int first, unsigned int num, uint32_t value)
{
assert(num >= 1 && num <= 32);
uint8_t *buffer = _buffer;
Expand All @@ -43,7 +43,7 @@ static inline void buf_set_u32(uint8_t *_buffer,
buffer[1] = (value >> 8) & 0xff;
buffer[0] = (value >> 0) & 0xff;
} else {
for (unsigned i = first; i < first + num; i++) {
for (unsigned int i = first; i < first + num; i++) {
if (((value >> (i - first)) & 1) == 1)
buffer[i / 8] |= 1 << (i % 8);
else
Expand All @@ -63,7 +63,7 @@ static inline void buf_set_u32(uint8_t *_buffer,
* @param value Up to 64 bits that will be copied to _buffer.
*/
static inline void buf_set_u64(uint8_t *_buffer,
unsigned first, unsigned num, uint64_t value)
unsigned int first, unsigned int num, uint64_t value)
{
assert(num >= 1 && num <= 64);
uint8_t *buffer = _buffer;
Expand All @@ -83,7 +83,7 @@ static inline void buf_set_u64(uint8_t *_buffer,
buffer[1] = (value >> 8) & 0xff;
buffer[0] = (value >> 0) & 0xff;
} else {
for (unsigned i = first; i < first + num; i++) {
for (unsigned int i = first; i < first + num; i++) {
if (((value >> (i - first)) & 1) == 1)
buffer[i / 8] |= 1 << (i % 8);
else
Expand All @@ -102,7 +102,7 @@ static inline void buf_set_u64(uint8_t *_buffer,
* @returns Up to 32-bits that were read from @c _buffer.
*/
static inline uint32_t buf_get_u32(const uint8_t *_buffer,
unsigned first, unsigned num)
unsigned int first, unsigned int num)
{
assert(num >= 1 && num <= 32);
const uint8_t *buffer = _buffer;
Expand All @@ -114,7 +114,7 @@ static inline uint32_t buf_get_u32(const uint8_t *_buffer,
(((uint32_t)buffer[0]) << 0);
} else {
uint32_t result = 0;
for (unsigned i = first; i < first + num; i++) {
for (unsigned int i = first; i < first + num; i++) {
if (((buffer[i / 8] >> (i % 8)) & 1) == 1)
result |= 1U << (i - first);
}
Expand All @@ -132,7 +132,7 @@ static inline uint32_t buf_get_u32(const uint8_t *_buffer,
* @returns Up to 64-bits that were read from @c _buffer.
*/
static inline uint64_t buf_get_u64(const uint8_t *_buffer,
unsigned first, unsigned num)
unsigned int first, unsigned int num)
{
assert(num >= 1 && num <= 64);
const uint8_t *buffer = _buffer;
Expand All @@ -153,7 +153,7 @@ static inline uint64_t buf_get_u64(const uint8_t *_buffer,
(((uint64_t)buffer[0]) << 0));
} else {
uint64_t result = 0;
for (unsigned i = first; i < first + num; i++) {
for (unsigned int i = first; i < first + num; i++) {
if (((buffer[i / 8] >> (i % 8)) & 1) == 1)
result = result | ((uint64_t)1 << (uint64_t)(i - first));
}
Expand All @@ -170,11 +170,11 @@ static inline uint64_t buf_get_u64(const uint8_t *_buffer,
* @param width The number of bits in value (2-32).
* @returns A 32-bit word with @c value in reversed bit-order.
*/
uint32_t flip_u32(uint32_t value, unsigned width);
uint32_t flip_u32(uint32_t value, unsigned int width);

bool buf_eq(const void *buf1, const void *buf2, unsigned size);
bool buf_eq(const void *buf1, const void *buf2, unsigned int size);
bool buf_eq_mask(const void *buf1, const void *buf2,
const void *mask, unsigned size);
const void *mask, unsigned int size);

/**
* Copies @c size bits out of @c from and into @c to. Any extra
Expand All @@ -183,18 +183,18 @@ bool buf_eq_mask(const void *buf1, const void *buf2,
* @param to The buffer that will receive the copy of @c from.
* @param size The number of bits to copy.
*/
void *buf_cpy(const void *from, void *to, unsigned size);
void *buf_cpy(const void *from, void *to, unsigned int size);

/**
* Set the contents of @c buf with @c count bits, all set to 1.
* @param buf The buffer to fill with ones.
* @param size The number of bits.
* @returns The original buffer (@c buf).
*/
void *buf_set_ones(void *buf, unsigned size);
void *buf_set_ones(void *buf, unsigned int size);

void *buf_set_buf(const void *src, unsigned src_start,
void *dst, unsigned dst_start, unsigned len);
void *buf_set_buf(const void *src, unsigned int src_start,
void *dst, unsigned int dst_start, unsigned int len);

/**
* Parse an unsigned number (provided as a zero-terminated string)
Expand All @@ -207,16 +207,16 @@ void *buf_set_buf(const void *src, unsigned src_start,
*/
int str_to_buf(const char *str, void *_buf, unsigned int buf_bitsize);

char *buf_to_hex_str(const void *buf, unsigned size);
char *buf_to_hex_str(const void *buf, unsigned int size);

/* read a uint32_t from a buffer in target memory endianness */
static inline uint32_t fast_target_buffer_get_u32(const void *p, bool le)
{
return le ? le_to_h_u32(p) : be_to_h_u32(p);
}

static inline void bit_copy(uint8_t *dst, unsigned dst_offset, const uint8_t *src,
unsigned src_offset, unsigned bit_count)
static inline void bit_copy(uint8_t *dst, unsigned int dst_offset, const uint8_t *src,
unsigned int src_offset, unsigned int bit_count)
{
buf_set_buf(src, src_offset, dst, dst_offset, bit_count);
}
Expand All @@ -227,23 +227,23 @@ struct bit_copy_queue {

struct bit_copy_queue_entry {
uint8_t *dst;
unsigned dst_offset;
unsigned int dst_offset;
const uint8_t *src;
unsigned src_offset;
unsigned bit_count;
unsigned int src_offset;
unsigned int bit_count;
struct list_head list;
};

void bit_copy_queue_init(struct bit_copy_queue *q);
int bit_copy_queued(struct bit_copy_queue *q, uint8_t *dst, unsigned dst_offset, const uint8_t *src,
unsigned src_offset, unsigned bit_count);
int bit_copy_queued(struct bit_copy_queue *q, uint8_t *dst, unsigned int dst_offset, const uint8_t *src,
unsigned int src_offset, unsigned int bit_count);
void bit_copy_execute(struct bit_copy_queue *q);
void bit_copy_discard(struct bit_copy_queue *q);

/* functions to convert to/from hex encoded buffer
* used in ti-icdi driver and gdb server */
size_t unhexify(uint8_t *bin, const char *hex, size_t count);
size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t out_maxlen);
void buffer_shr(void *_buf, unsigned buf_len, unsigned count);
void buffer_shr(void *_buf, unsigned int buf_len, unsigned int count);

#endif /* OPENOCD_HELPER_BINARYBUFFER_H */
16 changes: 8 additions & 8 deletions src/helper/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void *jimcmd_privdata(Jim_Cmd *cmd)
return cmd->isproc ? NULL : cmd->u.native.privData;
}

static void tcl_output(void *privData, const char *file, unsigned line,
static void tcl_output(void *privData, const char *file, unsigned int line,
const char *function, const char *string)
{
struct log_capture_state *state = privData;
Expand Down Expand Up @@ -144,7 +144,7 @@ static void script_debug(Jim_Interp *interp, unsigned int argc, Jim_Obj * const
return;

char *dbg = alloc_printf("command -");
for (unsigned i = 0; i < argc; i++) {
for (unsigned int i = 0; i < argc; i++) {
const char *w = Jim_GetString(argv[i], NULL);
char *t = alloc_printf("%s %s", dbg, w);
free(dbg);
Expand Down Expand Up @@ -288,7 +288,7 @@ int __register_commands(struct command_context *cmd_ctx, const char *cmd_prefix,
struct target *override_target)
{
int retval = ERROR_OK;
unsigned i;
unsigned int i;
for (i = 0; cmds[i].name || cmds[i].chain; i++) {
const struct command_registration *cr = cmds + i;

Expand Down Expand Up @@ -323,7 +323,7 @@ int __register_commands(struct command_context *cmd_ctx, const char *cmd_prefix,
}
}
if (retval != ERROR_OK) {
for (unsigned j = 0; j < i; j++)
for (unsigned int j = 0; j < i; j++)
unregister_command(cmd_ctx, cmd_prefix, cmds[j].name);
}
return retval;
Expand Down Expand Up @@ -728,12 +728,12 @@ static COMMAND_HELPER(command_help_show_list, bool show_help, const char *cmd_ma

#define HELP_LINE_WIDTH(_n) (int)(76 - (2 * _n))

static void command_help_show_indent(unsigned n)
static void command_help_show_indent(unsigned int n)
{
for (unsigned i = 0; i < n; i++)
for (unsigned int i = 0; i < n; i++)
LOG_USER_N(" ");
}
static void command_help_show_wrap(const char *str, unsigned n, unsigned n2)
static void command_help_show_wrap(const char *str, unsigned int n, unsigned int n2)
{
const char *cp = str, *last = str;
while (*cp) {
Expand Down Expand Up @@ -1317,7 +1317,7 @@ DEFINE_PARSE_NUM_TYPE(_llong, long long, strtoll, LLONG_MIN, LLONG_MAX)

#define DEFINE_PARSE_ULONGLONG(name, type, min, max) \
DEFINE_PARSE_WRAPPER(name, type, min, max, unsigned long long, _ullong)
DEFINE_PARSE_ULONGLONG(_uint, unsigned, 0, UINT_MAX)
DEFINE_PARSE_ULONGLONG(_uint, unsigned int, 0, UINT_MAX)
DEFINE_PARSE_ULONGLONG(_u64, uint64_t, 0, UINT64_MAX)
DEFINE_PARSE_ULONGLONG(_u32, uint32_t, 0, UINT32_MAX)
DEFINE_PARSE_ULONGLONG(_u16, uint16_t, 0, UINT16_MAX)
Expand Down
4 changes: 2 additions & 2 deletions src/helper/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct command_invocation {
struct command_context *ctx;
struct command *current;
const char *name;
unsigned argc;
unsigned int argc;
const char **argv;
Jim_Obj * const *jimtcl_argv;
Jim_Obj *output;
Expand Down Expand Up @@ -414,7 +414,7 @@ int parse_llong(const char *str, long long *ul);
#define DECLARE_PARSE_WRAPPER(name, type) \
int parse ## name(const char *str, type * ul)

DECLARE_PARSE_WRAPPER(_uint, unsigned);
DECLARE_PARSE_WRAPPER(_uint, unsigned int);
DECLARE_PARSE_WRAPPER(_u64, uint64_t);
DECLARE_PARSE_WRAPPER(_u32, uint32_t);
DECLARE_PARSE_WRAPPER(_u16, uint16_t);
Expand Down
Loading

0 comments on commit 436e6f1

Please sign in to comment.