Skip to content

Commit

Permalink
batman-adv: Replace C99 int types with kernel type
Browse files Browse the repository at this point in the history
(s|u)(8|16|32|64) are the preferred types in the kernel. The use of the
standard C99 types u?int(8|16|32|64)_t are objected by some people and even
checkpatch now warns about using them.

Signed-off-by: Sven Eckelmann <[email protected]>
Signed-off-by: Marek Lindner <[email protected]>
Signed-off-by: Antonio Quartulli <[email protected]>
  • Loading branch information
ecsv authored and ordex committed Aug 24, 2015
1 parent 56fff0a commit 6b5e971
Show file tree
Hide file tree
Showing 30 changed files with 563 additions and 585 deletions.
94 changes: 46 additions & 48 deletions net/batman-adv/bat_iv_ogm.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ enum batadv_dup_status {
* @lq_index: index to store the value at
* @value: value to store in the ring buffer
*/
static void batadv_ring_buffer_set(uint8_t lq_recv[], uint8_t *lq_index,
uint8_t value)
static void batadv_ring_buffer_set(u8 lq_recv[], u8 *lq_index, u8 value)
{
lq_recv[*lq_index] = value;
*lq_index = (*lq_index + 1) % BATADV_TQ_GLOBAL_WINDOW_SIZE;
Expand All @@ -91,12 +90,12 @@ static void batadv_ring_buffer_set(uint8_t lq_recv[], uint8_t *lq_index,
*
* Returns computed average value.
*/
static uint8_t batadv_ring_buffer_avg(const uint8_t lq_recv[])
static u8 batadv_ring_buffer_avg(const u8 lq_recv[])
{
const uint8_t *ptr;
uint16_t count = 0;
uint16_t i = 0;
uint16_t sum = 0;
const u8 *ptr;
u16 count = 0;
u16 i = 0;
u16 sum = 0;

ptr = lq_recv;

Expand All @@ -113,7 +112,7 @@ static uint8_t batadv_ring_buffer_avg(const uint8_t lq_recv[])
if (count == 0)
return 0;

return (uint8_t)(sum / count);
return (u8)(sum / count);
}

/**
Expand Down Expand Up @@ -155,14 +154,14 @@ static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node,
kfree(orig_node->bat_iv.bcast_own);
orig_node->bat_iv.bcast_own = data_ptr;

data_ptr = kmalloc_array(max_if_num, sizeof(uint8_t), GFP_ATOMIC);
data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC);
if (!data_ptr) {
kfree(orig_node->bat_iv.bcast_own);
goto unlock;
}

memcpy(data_ptr, orig_node->bat_iv.bcast_own_sum,
(max_if_num - 1) * sizeof(uint8_t));
(max_if_num - 1) * sizeof(u8));
kfree(orig_node->bat_iv.bcast_own_sum);
orig_node->bat_iv.bcast_own_sum = data_ptr;

Expand Down Expand Up @@ -215,19 +214,19 @@ static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node,
if (max_if_num == 0)
goto free_own_sum;

data_ptr = kmalloc_array(max_if_num, sizeof(uint8_t), GFP_ATOMIC);
data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC);
if (!data_ptr) {
kfree(orig_node->bat_iv.bcast_own);
goto unlock;
}

memcpy(data_ptr, orig_node->bat_iv.bcast_own_sum,
del_if_num * sizeof(uint8_t));
del_if_num * sizeof(u8));

if_offset = (del_if_num + 1) * sizeof(uint8_t);
memcpy((char *)data_ptr + del_if_num * sizeof(uint8_t),
if_offset = (del_if_num + 1) * sizeof(u8);
memcpy((char *)data_ptr + del_if_num * sizeof(u8),
orig_node->bat_iv.bcast_own_sum + if_offset,
(max_if_num - del_if_num) * sizeof(uint8_t));
(max_if_num - del_if_num) * sizeof(u8));

free_own_sum:
kfree(orig_node->bat_iv.bcast_own_sum);
Expand All @@ -250,7 +249,7 @@ static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node,
* If the object does not exists it is created an initialised.
*/
static struct batadv_orig_node *
batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const uint8_t *addr)
batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr)
{
struct batadv_orig_node *orig_node;
int size, hash_added;
Expand All @@ -270,7 +269,7 @@ batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const uint8_t *addr)
if (!orig_node->bat_iv.bcast_own)
goto free_orig_node;

size = bat_priv->num_ifaces * sizeof(uint8_t);
size = bat_priv->num_ifaces * sizeof(u8);
orig_node->bat_iv.bcast_own_sum = kzalloc(size, GFP_ATOMIC);
if (!orig_node->bat_iv.bcast_own_sum)
goto free_orig_node;
Expand All @@ -293,7 +292,7 @@ batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const uint8_t *addr)

static struct batadv_neigh_node *
batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
const uint8_t *neigh_addr,
const u8 *neigh_addr,
struct batadv_orig_node *orig_node,
struct batadv_orig_node *orig_neigh)
{
Expand Down Expand Up @@ -339,7 +338,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
{
struct batadv_ogm_packet *batadv_ogm_packet;
unsigned char *ogm_buff;
uint32_t random_seqno;
u32 random_seqno;

/* randomize initial seqno to avoid collision */
get_random_bytes(&random_seqno, sizeof(random_seqno));
Expand Down Expand Up @@ -411,8 +410,7 @@ static unsigned long batadv_iv_ogm_fwd_send_time(void)
}

/* apply hop penalty for a normal link */
static uint8_t batadv_hop_penalty(uint8_t tq,
const struct batadv_priv *bat_priv)
static u8 batadv_hop_penalty(u8 tq, const struct batadv_priv *bat_priv)
{
int hop_penalty = atomic_read(&bat_priv->hop_penalty);
int new_tq;
Expand Down Expand Up @@ -442,11 +440,11 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
{
struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
const char *fwd_str;
uint8_t packet_num;
int16_t buff_pos;
u8 packet_num;
s16 buff_pos;
struct batadv_ogm_packet *batadv_ogm_packet;
struct sk_buff *skb;
uint8_t *packet_pos;
u8 *packet_pos;

if (hard_iface->if_status != BATADV_IF_ACTIVE)
return;
Expand Down Expand Up @@ -837,7 +835,7 @@ static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
struct batadv_hard_iface *if_outgoing)
{
struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
uint16_t tvlv_len;
u16 tvlv_len;

if (batadv_ogm_packet->ttl <= 1) {
batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n");
Expand Down Expand Up @@ -896,9 +894,9 @@ batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)
struct hlist_head *head;
struct batadv_orig_node *orig_node;
unsigned long *word;
uint32_t i;
u32 i;
size_t word_index;
uint8_t *w;
u8 *w;
int if_num;

for (i = 0; i < hash->size; i++) {
Expand Down Expand Up @@ -927,8 +925,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
struct batadv_ogm_packet *batadv_ogm_packet;
struct batadv_hard_iface *primary_if, *tmp_hard_iface;
int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len;
uint32_t seqno;
uint16_t tvlv_len = 0;
u32 seqno;
u16 tvlv_len = 0;
unsigned long send_time;

primary_if = batadv_primary_if_get_selected(bat_priv);
Expand All @@ -947,7 +945,7 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
batadv_ogm_packet->tvlv_len = htons(tvlv_len);

/* change sequence number to network order */
seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
seqno = (u32)atomic_read(&hard_iface->bat_iv.ogm_seqno);
batadv_ogm_packet->seqno = htonl(seqno);
atomic_inc(&hard_iface->bat_iv.ogm_seqno);

Expand Down Expand Up @@ -1010,9 +1008,9 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
struct batadv_neigh_node *router = NULL;
struct batadv_orig_node *orig_node_tmp;
int if_num;
uint8_t sum_orig, sum_neigh;
uint8_t *neigh_addr;
uint8_t tq_avg;
u8 sum_orig, sum_neigh;
u8 *neigh_addr;
u8 tq_avg;

batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"update_originator(): Searching and updating originator entry of received packet\n");
Expand Down Expand Up @@ -1164,8 +1162,8 @@ static int batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
struct batadv_neigh_node *neigh_node = NULL, *tmp_neigh_node;
struct batadv_neigh_ifinfo *neigh_ifinfo;
uint8_t total_count;
uint8_t orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
u8 total_count;
u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
int tq_asym_penalty, inv_asym_penalty, if_num, ret = 0;
unsigned int combined_tq;
Expand Down Expand Up @@ -1311,13 +1309,13 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
struct batadv_neigh_node *neigh_node;
struct batadv_neigh_ifinfo *neigh_ifinfo;
int is_dup;
int32_t seq_diff;
s32 seq_diff;
int need_update = 0;
int set_mark;
enum batadv_dup_status ret = BATADV_NO_DUP;
uint32_t seqno = ntohl(batadv_ogm_packet->seqno);
uint8_t *neigh_addr;
uint8_t packet_count;
u32 seqno = ntohl(batadv_ogm_packet->seqno);
u8 *neigh_addr;
u8 packet_count;
unsigned long *bitmap;

orig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet->orig);
Expand Down Expand Up @@ -1418,7 +1416,7 @@ batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset,
bool sameseq, similar_ttl;
struct sk_buff *skb_priv;
struct ethhdr *ethhdr;
uint8_t *prev_sender;
u8 *prev_sender;
int is_bidirect;

/* create a private copy of the skb, as some functions change tq value
Expand Down Expand Up @@ -1600,7 +1598,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
struct batadv_orig_node *orig_neigh_node, *orig_node;
struct batadv_hard_iface *hard_iface;
struct batadv_ogm_packet *ogm_packet;
uint32_t if_incoming_seqno;
u32 if_incoming_seqno;
bool has_directlink_flag;
struct ethhdr *ethhdr;
bool is_my_oldorig = false;
Expand Down Expand Up @@ -1673,9 +1671,9 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
if (is_my_orig) {
unsigned long *word;
int offset;
int32_t bit_pos;
int16_t if_num;
uint8_t *weight;
s32 bit_pos;
s16 if_num;
u8 *weight;

orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
ethhdr->h_source);
Expand Down Expand Up @@ -1751,7 +1749,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
{
struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
struct batadv_ogm_packet *ogm_packet;
uint8_t *packet_pos;
u8 *packet_pos;
int ogm_offset;
bool ret;

Expand Down Expand Up @@ -1835,7 +1833,7 @@ static void batadv_iv_ogm_orig_print(struct batadv_priv *bat_priv,
unsigned long last_seen_jiffies;
struct hlist_head *head;
int batman_count = 0;
uint32_t i;
u32 i;

seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
"Originator", "last-seen", "#", BATADV_TQ_MAX_VALUE,
Expand Down Expand Up @@ -1903,7 +1901,7 @@ static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1,
struct batadv_hard_iface *if_outgoing2)
{
struct batadv_neigh_ifinfo *neigh1_ifinfo, *neigh2_ifinfo;
uint8_t tq1, tq2;
u8 tq1, tq2;
int diff;

neigh1_ifinfo = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);
Expand Down Expand Up @@ -1945,7 +1943,7 @@ batadv_iv_ogm_neigh_is_eob(struct batadv_neigh_node *neigh1,
struct batadv_hard_iface *if_outgoing2)
{
struct batadv_neigh_ifinfo *neigh1_ifinfo, *neigh2_ifinfo;
uint8_t tq1, tq2;
u8 tq1, tq2;
bool ret;

neigh1_ifinfo = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);
Expand Down
6 changes: 3 additions & 3 deletions net/batman-adv/bitarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <linux/bitmap.h>

/* shift the packet array by n places. */
static void batadv_bitmap_shift_left(unsigned long *seq_bits, int32_t n)
static void batadv_bitmap_shift_left(unsigned long *seq_bits, s32 n)
{
if (n <= 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE)
return;
Expand All @@ -35,8 +35,8 @@ static void batadv_bitmap_shift_left(unsigned long *seq_bits, int32_t n)
* 1 if the window was moved (either new or very old)
* 0 if the window was not moved/shifted.
*/
int batadv_bit_get_packet(void *priv, unsigned long *seq_bits,
int32_t seq_num_diff, int set_mark)
int batadv_bit_get_packet(void *priv, unsigned long *seq_bits, s32 seq_num_diff,
int set_mark)
{
struct batadv_priv *bat_priv = priv;

Expand Down
10 changes: 5 additions & 5 deletions net/batman-adv/bitarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
* and curr_seqno is within range of last_seqno. Otherwise returns 0.
*/
static inline int batadv_test_bit(const unsigned long *seq_bits,
uint32_t last_seqno, uint32_t curr_seqno)
u32 last_seqno, u32 curr_seqno)
{
int32_t diff;
s32 diff;

diff = last_seqno - curr_seqno;
if (diff < 0 || diff >= BATADV_TQ_LOCAL_WINDOW_SIZE)
Expand All @@ -39,7 +39,7 @@ static inline int batadv_test_bit(const unsigned long *seq_bits,
}

/* turn corresponding bit on, so we can remember that we got the packet */
static inline void batadv_set_bit(unsigned long *seq_bits, int32_t n)
static inline void batadv_set_bit(unsigned long *seq_bits, s32 n)
{
/* if too old, just drop it */
if (n < 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE)
Expand All @@ -51,7 +51,7 @@ static inline void batadv_set_bit(unsigned long *seq_bits, int32_t n)
/* receive and process one packet, returns 1 if received seq_num is considered
* new, 0 if old
*/
int batadv_bit_get_packet(void *priv, unsigned long *seq_bits,
int32_t seq_num_diff, int set_mark);
int batadv_bit_get_packet(void *priv, unsigned long *seq_bits, s32 seq_num_diff,
int set_mark);

#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */
Loading

0 comments on commit 6b5e971

Please sign in to comment.