Skip to content

Commit

Permalink
batman-adv: Add const type qualifier for pointers
Browse files Browse the repository at this point in the history
batman-adv uses pointers which are marked as const and should not
violate that type qualifier by passing it to functions which force a
cast to the non-const version.

Signed-off-by: Sven Eckelmann <[email protected]>
  • Loading branch information
ecsv committed May 30, 2011
1 parent 38e3c5f commit 747e422
Show file tree
Hide file tree
Showing 27 changed files with 166 additions and 157 deletions.
21 changes: 11 additions & 10 deletions net/batman-adv/aggregation.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
#include "hard-interface.h"

/* calculate the size of the tt information for a given packet */
static int tt_len(struct batman_packet *batman_packet)
static int tt_len(const struct batman_packet *batman_packet)
{
return batman_packet->num_tt * ETH_ALEN;
}

/* return true if new_packet can be aggregated with forw_packet */
static bool can_aggregate_with(struct batman_packet *new_batman_packet,
static bool can_aggregate_with(const struct batman_packet *new_batman_packet,
int packet_len,
unsigned long send_time,
bool directlink,
struct hard_iface *if_incoming,
struct forw_packet *forw_packet)
const struct hard_iface *if_incoming,
const struct forw_packet *forw_packet)
{
struct batman_packet *batman_packet =
(struct batman_packet *)forw_packet->skb->data;
Expand Down Expand Up @@ -97,8 +97,9 @@ static bool can_aggregate_with(struct batman_packet *new_batman_packet,
}

/* create a new aggregated packet and add this packet to it */
static void new_aggregated_packet(unsigned char *packet_buff, int packet_len,
unsigned long send_time, bool direct_link,
static void new_aggregated_packet(const unsigned char *packet_buff,
int packet_len, unsigned long send_time,
bool direct_link,
struct hard_iface *if_incoming,
int own_packet)
{
Expand Down Expand Up @@ -176,8 +177,7 @@ static void new_aggregated_packet(unsigned char *packet_buff, int packet_len,

/* aggregate a new packet into the existing aggregation */
static void aggregate(struct forw_packet *forw_packet_aggr,
unsigned char *packet_buff,
int packet_len,
const unsigned char *packet_buff, int packet_len,
bool direct_link)
{
unsigned char *skb_buff;
Expand Down Expand Up @@ -253,8 +253,9 @@ void add_bat_packet_to_list(struct bat_priv *bat_priv,
}

/* unpack the aggregated packets and process them one by one */
void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff,
int packet_len, struct hard_iface *if_incoming)
void receive_aggr_bat_packet(const struct ethhdr *ethhdr,
unsigned char *packet_buff, int packet_len,
struct hard_iface *if_incoming)
{
struct batman_packet *batman_packet;
int buff_pos = 0;
Expand Down
5 changes: 3 additions & 2 deletions net/batman-adv/aggregation.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ void add_bat_packet_to_list(struct bat_priv *bat_priv,
unsigned char *packet_buff, int packet_len,
struct hard_iface *if_incoming, char own_packet,
unsigned long send_time);
void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff,
int packet_len, struct hard_iface *if_incoming);
void receive_aggr_bat_packet(const struct ethhdr *ethhdr,
unsigned char *packet_buff, int packet_len,
struct hard_iface *if_incoming);

#endif /* _NET_BATMAN_ADV_AGGREGATION_H_ */
4 changes: 2 additions & 2 deletions net/batman-adv/bat_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void emit_log_char(struct debug_log *debug_log, char c)
}

__printf(2, 3)
static int fdebug_log(struct debug_log *debug_log, char *fmt, ...)
static int fdebug_log(struct debug_log *debug_log, const char *fmt, ...)
{
va_list args;
static char debug_log_buf[256];
Expand All @@ -75,7 +75,7 @@ static int fdebug_log(struct debug_log *debug_log, char *fmt, ...)
return 0;
}

int debug_log(struct bat_priv *bat_priv, char *fmt, ...)
int debug_log(struct bat_priv *bat_priv, const char *fmt, ...)
{
va_list args;
char tmp_log_buf[256];
Expand Down
15 changes: 7 additions & 8 deletions net/batman-adv/bat_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ssize_t show_##_name(struct kobject *kobj, struct attribute *attr, \

static int store_bool_attr(char *buff, size_t count,
struct net_device *net_dev,
char *attr_name, atomic_t *attr)
const char *attr_name, atomic_t *attr)
{
int enabled = -1;

Expand Down Expand Up @@ -138,16 +138,15 @@ static inline ssize_t __store_bool_attr(char *buff, size_t count,
{
int ret;

ret = store_bool_attr(buff, count, net_dev, (char *)attr->name,
attr_store);
ret = store_bool_attr(buff, count, net_dev, attr->name, attr_store);
if (post_func && ret)
post_func(net_dev);

return ret;
}

static int store_uint_attr(char *buff, size_t count,
struct net_device *net_dev, char *attr_name,
static int store_uint_attr(const char *buff, size_t count,
struct net_device *net_dev, const char *attr_name,
unsigned int min, unsigned int max, atomic_t *attr)
{
unsigned long uint_val;
Expand Down Expand Up @@ -183,15 +182,15 @@ static int store_uint_attr(char *buff, size_t count,
return count;
}

static inline ssize_t __store_uint_attr(char *buff, size_t count,
static inline ssize_t __store_uint_attr(const char *buff, size_t count,
int min, int max,
void (*post_func)(struct net_device *),
struct attribute *attr,
const struct attribute *attr,
atomic_t *attr_store, struct net_device *net_dev)
{
int ret;

ret = store_uint_attr(buff, count, net_dev, (char *)attr->name,
ret = store_uint_attr(buff, count, net_dev, attr->name,
min, max, attr_store);
if (post_func && ret)
post_func(net_dev);
Expand Down
4 changes: 2 additions & 2 deletions net/batman-adv/bitarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/* returns true if the corresponding bit in the given seq_bits indicates true
* and curr_seqno is within range of last_seqno */
uint8_t get_bit_status(unsigned long *seq_bits, uint32_t last_seqno,
uint8_t get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
uint32_t curr_seqno)
{
int32_t diff, word_offset, word_num;
Expand Down Expand Up @@ -190,7 +190,7 @@ char bit_get_packet(void *priv, unsigned long *seq_bits,
/* count the hamming weight, how many good packets did we receive? just count
* the 1's.
*/
int bit_packet_count(unsigned long *seq_bits)
int bit_packet_count(const unsigned long *seq_bits)
{
int i, hamming = 0;

Expand Down
6 changes: 3 additions & 3 deletions net/batman-adv/bitarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

/* returns true if the corresponding bit in the given seq_bits indicates true
* and curr_seqno is within range of last_seqno */
uint8_t get_bit_status(unsigned long *seq_bits, uint32_t last_seqno,
uint32_t curr_seqno);
uint8_t get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
uint32_t curr_seqno);

/* turn corresponding bit on, so we can remember that we got the packet */
void bit_mark(unsigned long *seq_bits, int32_t n);
Expand All @@ -39,6 +39,6 @@ char bit_get_packet(void *priv, unsigned long *seq_bits,
int32_t seq_num_diff, int8_t set_mark);

/* count the hamming weight, how many good packets did we receive? */
int bit_packet_count(unsigned long *seq_bits);
int bit_packet_count(const unsigned long *seq_bits);

#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */
4 changes: 2 additions & 2 deletions net/batman-adv/gateway_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ void gw_node_purge(struct bat_priv *bat_priv)
/**
* fails if orig_node has no router
*/
static int _write_buffer_text(struct bat_priv *bat_priv,
struct seq_file *seq, struct gw_node *gw_node)
static int _write_buffer_text(struct bat_priv *bat_priv, struct seq_file *seq,
const struct gw_node *gw_node)
{
struct gw_node *curr_gw;
struct neigh_node *router;
Expand Down
19 changes: 10 additions & 9 deletions net/batman-adv/hard-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void hardif_free_rcu(struct rcu_head *rcu)
kfree(hard_iface);
}

struct hard_iface *hardif_get_by_netdev(struct net_device *net_dev)
struct hard_iface *hardif_get_by_netdev(const struct net_device *net_dev)
{
struct hard_iface *hard_iface;

Expand All @@ -64,7 +64,7 @@ struct hard_iface *hardif_get_by_netdev(struct net_device *net_dev)
return hard_iface;
}

static int is_valid_iface(struct net_device *net_dev)
static int is_valid_iface(const struct net_device *net_dev)
{
if (net_dev->flags & IFF_LOOPBACK)
return 0;
Expand All @@ -86,7 +86,7 @@ static int is_valid_iface(struct net_device *net_dev)
return 1;
}

static struct hard_iface *hardif_get_active(struct net_device *soft_iface)
static struct hard_iface *hardif_get_active(const struct net_device *soft_iface)
{
struct hard_iface *hard_iface;

Expand Down Expand Up @@ -160,7 +160,7 @@ static void primary_if_select(struct bat_priv *bat_priv,
atomic_set(&bat_priv->tt_local_changed, 1);
}

static bool hardif_is_iface_up(struct hard_iface *hard_iface)
static bool hardif_is_iface_up(const struct hard_iface *hard_iface)
{
if (hard_iface->net_dev->flags & IFF_UP)
return true;
Expand All @@ -176,9 +176,9 @@ static void update_mac_addresses(struct hard_iface *hard_iface)
hard_iface->net_dev->dev_addr, ETH_ALEN);
}

static void check_known_mac_addr(struct net_device *net_dev)
static void check_known_mac_addr(const struct net_device *net_dev)
{
struct hard_iface *hard_iface;
const struct hard_iface *hard_iface;

rcu_read_lock();
list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
Expand All @@ -204,8 +204,8 @@ static void check_known_mac_addr(struct net_device *net_dev)

int hardif_min_mtu(struct net_device *soft_iface)
{
struct bat_priv *bat_priv = netdev_priv(soft_iface);
struct hard_iface *hard_iface;
const struct bat_priv *bat_priv = netdev_priv(soft_iface);
const struct hard_iface *hard_iface;
/* allow big frames if all devices are capable to do so
* (have MTU > 1500 + BAT_HEADER_LEN) */
int min_mtu = ETH_DATA_LEN;
Expand Down Expand Up @@ -285,7 +285,8 @@ static void hardif_deactivate_interface(struct hard_iface *hard_iface)
update_min_mtu(hard_iface->soft_iface);
}

int hardif_enable_interface(struct hard_iface *hard_iface, char *iface_name)
int hardif_enable_interface(struct hard_iface *hard_iface,
const char *iface_name)
{
struct bat_priv *bat_priv;
struct batman_packet *batman_packet;
Expand Down
6 changes: 4 additions & 2 deletions net/batman-adv/hard-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@

extern struct notifier_block hard_if_notifier;

struct hard_iface *hardif_get_by_netdev(struct net_device *net_dev);
int hardif_enable_interface(struct hard_iface *hard_iface, char *iface_name);
struct hard_iface*
hardif_get_by_netdev(const struct net_device *net_dev);
int hardif_enable_interface(struct hard_iface *hard_iface,
const char *iface_name);
void hardif_disable_interface(struct hard_iface *hard_iface);
void hardif_remove_interfaces(void);
int hardif_min_mtu(struct net_device *soft_iface);
Expand Down
6 changes: 3 additions & 3 deletions net/batman-adv/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
* compare 2 element datas for their keys,
* return 0 if same and not 0 if not
* same */
typedef int (*hashdata_compare_cb)(struct hlist_node *, void *);
typedef int (*hashdata_compare_cb)(const struct hlist_node *, const void *);

/* the hashfunction, should return an index
* based on the key in the data of the first
* argument and the size the second */
typedef int (*hashdata_choose_cb)(void *, int);
typedef int (*hashdata_choose_cb)(const void *, int);
typedef void (*hashdata_free_cb)(struct hlist_node *, void *);

struct hashtable_t {
Expand Down Expand Up @@ -80,7 +80,7 @@ static inline void hash_delete(struct hashtable_t *hash,
static inline int hash_add(struct hashtable_t *hash,
hashdata_compare_cb compare,
hashdata_choose_cb choose,
void *data, struct hlist_node *data_node)
const void *data, struct hlist_node *data_node)
{
int index;
struct hlist_head *head;
Expand Down
4 changes: 2 additions & 2 deletions net/batman-adv/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ void dec_module_count(void)
module_put(THIS_MODULE);
}

int is_my_mac(uint8_t *addr)
int is_my_mac(const uint8_t *addr)
{
struct hard_iface *hard_iface;
const struct hard_iface *hard_iface;

rcu_read_lock();
list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
Expand Down
10 changes: 6 additions & 4 deletions net/batman-adv/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ int mesh_init(struct net_device *soft_iface);
void mesh_free(struct net_device *soft_iface);
void inc_module_count(void);
void dec_module_count(void);
int is_my_mac(uint8_t *addr);
int is_my_mac(const uint8_t *addr);

#ifdef CONFIG_BATMAN_ADV_DEBUG
int debug_log(struct bat_priv *bat_priv, char *fmt, ...) __printf(2, 3);
int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3);

#define bat_dbg(type, bat_priv, fmt, arg...) \
do { \
Expand All @@ -148,7 +148,7 @@ int debug_log(struct bat_priv *bat_priv, char *fmt, ...) __printf(2, 3);
__printf(3, 4)
static inline void bat_dbg(char type __always_unused,
struct bat_priv *bat_priv __always_unused,
char *fmt __always_unused, ...)
const char *fmt __always_unused, ...)
{
}
#endif
Expand All @@ -173,11 +173,13 @@ static inline void bat_dbg(char type __always_unused,
*
* note: can't use compare_ether_addr() as it requires aligned memory
*/
static inline int compare_eth(void *data1, void *data2)

static inline int compare_eth(const void *data1, const void *data2)
{
return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
}


#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)

#endif /* _NET_BATMAN_ADV_MAIN_H_ */
4 changes: 2 additions & 2 deletions net/batman-adv/originator.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct neigh_node *orig_node_get_router(struct orig_node *orig_node)

struct neigh_node *create_neighbor(struct orig_node *orig_node,
struct orig_node *orig_neigh_node,
uint8_t *neigh,
const uint8_t *neigh,
struct hard_iface *if_incoming)
{
struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
Expand Down Expand Up @@ -183,7 +183,7 @@ void originator_free(struct bat_priv *bat_priv)

/* this function finds or creates an originator entry for the given
* address if it does not exits */
struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr)
{
struct orig_node *orig_node;
int size;
Expand Down
14 changes: 7 additions & 7 deletions net/batman-adv/originator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ int originator_init(struct bat_priv *bat_priv);
void originator_free(struct bat_priv *bat_priv);
void purge_orig_ref(struct bat_priv *bat_priv);
void orig_node_free_ref(struct orig_node *orig_node);
struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr);
struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr);
struct neigh_node *create_neighbor(struct orig_node *orig_node,
struct orig_node *orig_neigh_node,
uint8_t *neigh,
const uint8_t *neigh,
struct hard_iface *if_incoming);
void neigh_node_free_ref(struct neigh_node *neigh_node);
struct neigh_node *orig_node_get_router(struct orig_node *orig_node);
Expand All @@ -41,18 +41,18 @@ int orig_hash_del_if(struct hard_iface *hard_iface, int max_if_num);


/* returns 1 if they are the same originator */
static inline int compare_orig(struct hlist_node *node, void *data2)
static inline int compare_orig(const struct hlist_node *node, const void *data2)
{
void *data1 = container_of(node, struct orig_node, hash_entry);
const void *data1 = container_of(node, struct orig_node, hash_entry);

return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
}

/* hashfunction to choose an entry in a hash table of given size */
/* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */
static inline int choose_orig(void *data, int32_t size)
static inline int choose_orig(const void *data, int32_t size)
{
unsigned char *key = data;
const unsigned char *key = data;
uint32_t hash = 0;
size_t i;

Expand All @@ -70,7 +70,7 @@ static inline int choose_orig(void *data, int32_t size)
}

static inline struct orig_node *orig_hash_find(struct bat_priv *bat_priv,
void *data)
const void *data)
{
struct hashtable_t *hash = bat_priv->orig_hash;
struct hlist_head *head;
Expand Down
Loading

0 comments on commit 747e422

Please sign in to comment.