Fixes with regard to errors reported by checkpatch.pl script (part of Linux kernel package).
* cls_can.c -- Controller Area Network classifier.
* Makes decisions according to Controller Area Network identifiers (can_id).
*
* cls_can.c -- Controller Area Network classifier.
* Makes decisions according to Controller Area Network identifiers (can_id).
*
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2 of
* the License.
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2 of
* the License.
- *
- * Idea: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
+ *
+ * Idea: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
* Copyright: (c) 2011 Czech Technical University in Prague
* (c) 2011 Volkswagen Group Research
* Authors: Michal Sojka <sojkam1@fel.cvut.cz>
* Copyright: (c) 2011 Czech Technical University in Prague
* (c) 2011 Volkswagen Group Research
* Authors: Michal Sojka <sojkam1@fel.cvut.cz>
#include <linux/can.h>
#ifndef CAN_SFF_ID_BITS
#include <linux/can.h>
#ifndef CAN_SFF_ID_BITS
- #define CAN_SFF_ID_BITS 11
- #define CAN_EFF_ID_BITS 29
+ #define CAN_SFF_ID_BITS 11
+ #define CAN_EFF_ID_BITS 29
/* Definition of Netlink messages */
enum {
TCA_CANFLTR_UNSPEC,
TCA_CANFLTR_CLASSID,
/* Definition of Netlink messages */
enum {
TCA_CANFLTR_UNSPEC,
TCA_CANFLTR_CLASSID,
- TCA_CANFLTR_RULES, /* Array of can_filter structs; We are able
+ TCA_CANFLTR_RULES, /* Array of can_filter structs; We are able
to determine the length after receiving */
__TCA_CANFLTR_MAX
};
to determine the length after receiving */
__TCA_CANFLTR_MAX
};
static const struct nla_policy canfltr_policy[TCA_CANFLTR_MAX + 1] = {
[TCA_CANFLTR_CLASSID] = { .type = NLA_U32 },
static const struct nla_policy canfltr_policy[TCA_CANFLTR_MAX + 1] = {
[TCA_CANFLTR_CLASSID] = { .type = NLA_U32 },
- //FIXME Be aware of possible problems with 64bit kernel and 32bit userspace etc.
- [TCA_CANFLTR_RULES] = { /*.len = (sizeof(struct can_filter))*/ } //FIXME
+ /* FIXME Be aware of possible problems with 64bit kernel and
+ 32bit userspace etc. */
+ [TCA_CANFLTR_RULES] = { /*.len = (sizeof(struct can_filter))*/ } /* FIXME */
};
struct canfltr_rules {
};
struct canfltr_rules {
- struct can_filter *rules_raw; /* Raw rules copied from netlink message;
- Used for sending information to userspace
+ struct can_filter *rules_raw; /* Raw rules copied from netlink message;
+ Used for sending information to userspace
(when 'tc filter show' is invoked) AND
when matching EFF frames*/
#ifdef SFF_BITMAP
(when 'tc filter show' is invoked) AND
when matching EFF frames*/
#ifdef SFF_BITMAP
- DECLARE_BITMAP(match_sff, (1 << CAN_SFF_ID_BITS)); /* For each SFF Can ID (11 bit)
- there is one record in this bitfield */
+ DECLARE_BITMAP(match_sff, (1 << CAN_SFF_ID_BITS)); /* For each SFF Can
+ ID (11 bit) there is one record in this
+ bitfield */
- int inv_match_en; /* Inverted match flag */
+ int inv_match_en; /* Inverted match flag */
int rules_count;
int eff_rules_count;
int sff_rules_count;
int rules_count;
int eff_rules_count;
int sff_rules_count;
struct canfltr_state {
u32 handle;
struct canfltr_rules *rules; /* All rules necessary for classification */
struct canfltr_state {
u32 handle;
struct canfltr_rules *rules; /* All rules necessary for classification */
- struct tcf_result res; /* Class ID (flow id) the instance
+ struct tcf_result res; /* Class ID (flow id) the instance
of a filter is bound to */
struct list_head link;
};
of a filter is bound to */
struct list_head link;
};
- /* Limit can_mask and can_id to SFF range to protect against write after end of array */
+ /* Limit can_mask and can_id to SFF range to
+ protect against write after end of array */
can_mask &= CAN_SFF_MASK;
can_id &= can_mask;
/* single frame */
can_mask &= CAN_SFF_MASK;
can_id &= can_mask;
/* single frame */
- if (can_mask == CAN_SFF_MASK) {
+ if (can_mask == CAN_SFF_MASK) {
set_bit(can_id, rls->match_sff);
return;
}
set_bit(can_id, rls->match_sff);
return;
}
* Extracts Can ID out of the sk_buff structure.
*/
static canid_t canfltr_get_id(struct sk_buff *skb)
* Extracts Can ID out of the sk_buff structure.
*/
static canid_t canfltr_get_id(struct sk_buff *skb)
/*
* Performs the classification. Iterates over all instances of filter,
* checking for CAN ID match.
/*
* Performs the classification. Iterates over all instances of filter,
* checking for CAN ID match.
- * @tp:
- * @res: Is used for setting Class ID as a result of classification
- *
+ * @tp:
+ * @res: Is used for setting Class ID as a result of classification
+ *
* Returns value relevant for policing. Used return values:
* TC_POLICE_OK if succesfully classified (without regard to policing rules)
* TC_POLICE_UNSPEC if no matching rule was found
* Returns value relevant for policing. Used return values:
* TC_POLICE_OK if succesfully classified (without regard to policing rules)
* TC_POLICE_UNSPEC if no matching rule was found
list_for_each_entry(f, &head->flist, link) {
bool match = false;
r = rcu_dereference(f->rules);
list_for_each_entry(f, &head->flist, link) {
bool match = false;
r = rcu_dereference(f->rules);
if (can_id & CAN_EFF_FLAG) {
can_id &= CAN_EFF_MASK;
if (can_id & CAN_EFF_FLAG) {
can_id &= CAN_EFF_MASK;
for (i = 0; i < r->eff_rules_count; i++) {
for (i = 0; i < r->eff_rules_count; i++) {
- if ((r->rules_raw[i].can_id & r->rules_raw[i].can_mask & CAN_EFF_MASK) == /* XXX: Why aren't these & performed "off-line"? */
- (can_id & r->rules_raw[i].can_mask & CAN_EFF_MASK)) {
+ /* XXX: Why aren't these & performed "off-line"? */
+ if ((r->rules_raw[i].can_id & r->rules_raw[i].can_mask & CAN_EFF_MASK) ==
+ (can_id & r->rules_raw[i].can_mask & CAN_EFF_MASK)) {
- * Looks up a filter element by its handle and returns the internal
+ * Looks up a filter element by its handle and returns the internal
* filter ID (i.e. pointer)
*/
static unsigned long canfltr_get(struct tcf_proto *tp, u32 handle)
* filter ID (i.e. pointer)
*/
static unsigned long canfltr_get(struct tcf_proto *tp, u32 handle)
return 0UL;
list_for_each_entry(f, &head->flist, link) {
return 0UL;
list_for_each_entry(f, &head->flist, link) {
- if (f->handle == handle) {
+ if (f->handle == handle)
return (unsigned long) f;
return (unsigned long) f;
- * Is invoked when a filter element previously referenced
+ * Is invoked when a filter element previously referenced
* with get() is no longer used
*/
static void canfltr_put(struct tcf_proto *tp, unsigned long f)
* with get() is no longer used
*/
static void canfltr_put(struct tcf_proto *tp, unsigned long f)
- if ((head->hgenerator += 0x10000) == 0)
+ head->hgenerator += 0x10000;
+ if (head->hgenerator == 0)
head->hgenerator = 0x10000;
h = head->hgenerator;
head->hgenerator = 0x10000;
h = head->hgenerator;
- if (canfltr_get(tp, h) == 0);
+ if (canfltr_get(tp, h) == 0)
canfltr_nl_rules = nla_data(tb[TCA_CANFLTR_RULES]);
rules_tmp->sff_rules_count = 0;
rules_tmp->eff_rules_count = 0;
canfltr_nl_rules = nla_data(tb[TCA_CANFLTR_RULES]);
rules_tmp->sff_rules_count = 0;
rules_tmp->eff_rules_count = 0;
- rules_tmp->rules_count =
+ rules_tmp->rules_count =
(nla_len(tb[TCA_CANFLTR_RULES]) / sizeof(struct can_filter));
(nla_len(tb[TCA_CANFLTR_RULES]) / sizeof(struct can_filter));
kzalloc(sizeof(struct can_filter) * rules_tmp->rules_count, GFP_KERNEL);
err = -ENOMEM;
if (rules_tmp->rules_raw == NULL)
kzalloc(sizeof(struct can_filter) * rules_tmp->rules_count, GFP_KERNEL);
err = -ENOMEM;
if (rules_tmp->rules_raw == NULL)
for (i = 0; i < rules_tmp->rules_count; i++) {
if ((canfltr_nl_rules[i].can_id & CAN_EFF_FLAG) &&
(canfltr_nl_rules[i].can_mask & CAN_EFF_FLAG)) {
for (i = 0; i < rules_tmp->rules_count; i++) {
if ((canfltr_nl_rules[i].can_id & CAN_EFF_FLAG) &&
(canfltr_nl_rules[i].can_mask & CAN_EFF_FLAG)) {
- memcpy(rules_tmp->rules_raw + rules_tmp->eff_rules_count,
+ memcpy(rules_tmp->rules_raw + rules_tmp->eff_rules_count,
&canfltr_nl_rules[i], sizeof(struct can_filter));
&canfltr_nl_rules[i], sizeof(struct can_filter));
- rules_tmp->eff_rules_count ++;
+ rules_tmp->eff_rules_count++;
(canfltr_nl_rules[i].can_mask & CAN_EFF_FLAG)) {
continue;
} else {
(canfltr_nl_rules[i].can_mask & CAN_EFF_FLAG)) {
continue;
} else {
- memcpy(rules_tmp->rules_raw + rules_tmp->eff_rules_count + rules_tmp->sff_rules_count,
- &canfltr_nl_rules[i], sizeof(struct can_filter));
- rules_tmp->sff_rules_count ++;
- canfltr_sff_match_add(rules_tmp, canfltr_nl_rules[i].can_id,
+ memcpy(rules_tmp->rules_raw + rules_tmp->eff_rules_count +
+ rules_tmp->sff_rules_count,
+ &canfltr_nl_rules[i], sizeof(struct can_filter));
+ rules_tmp->sff_rules_count++;
+ canfltr_sff_match_add(rules_tmp, canfltr_nl_rules[i].can_id,
canfltr_nl_rules[i].can_mask);
}
}
canfltr_nl_rules[i].can_mask);
}
}
-/*
- * Called for changing properties of an existing filter or after addition
+/*
+ * Called for changing properties of an existing filter or after addition
* of a new filter to a class (by calling bind_tcf which binds an instance
* of a filter to the class).
*
* of a new filter to a class (by calling bind_tcf which binds an instance
* of a filter to the class).
*
- * @tp: Structure representing instance of a filter.
+ * @tp: Structure representing instance of a filter.
* Part of a linked list of all filters.
* @base:
* Part of a linked list of all filters.
* @base:
* @tca: Messages passed through the Netlink from userspace.
* @arg:
*/
* @tca: Messages passed through the Netlink from userspace.
* @arg:
*/
struct canfltr_state *f = (struct canfltr_state *)*arg;
struct nlattr *tb[TCA_CANFLTR_MAX + 1];
int err;
struct canfltr_state *f = (struct canfltr_state *)*arg;
struct nlattr *tb[TCA_CANFLTR_MAX + 1];
int err;
if (tca[TCA_OPTIONS] == NULL)
return -EINVAL;
if (tca[TCA_OPTIONS] == NULL)
return -EINVAL;
- /* Parses a stream of attributes and stores a pointer to each attribute in
- the tb array accessible via the attribute type. Policy may be set to NULL
- if no validation is required.*/
- err = nla_parse_nested(tb, TCA_CANFLTR_MAX, tca[TCA_OPTIONS], canfltr_policy);
- if (err < 0)
+ /* Parses a stream of attributes and stores a pointer to each
+ attribute in the tb array accessible via the attribute type.
+ Policy may be set to NULL if no validation is required.*/
+ err = nla_parse_nested(tb, TCA_CANFLTR_MAX, tca[TCA_OPTIONS],
+ canfltr_policy);
+ if (err < 0)
- /* Change existing filter (remove all settings and add
+ /* Change existing filter (remove all settings and add
them thereafter as if filter was newly created) */
if (f != NULL) {
if (handle && f->handle != handle)
them thereafter as if filter was newly created) */
if (f != NULL) {
if (handle && f->handle != handle)
/* Configure filter */
err = canfltr_set_parms(tp, f, base, tb, tca[TCA_RATE]);
if (err < 0)
/* Configure filter */
err = canfltr_set_parms(tp, f, base, tb, tca[TCA_RATE]);
if (err < 0)
/* Add newly created filter to list of all filters */
tcf_tree_lock(tp);
/* Add newly created filter to list of all filters */
tcf_tree_lock(tp);
rcu_barrier();
kfree(f->rules->rules_raw);
kfree(f->rules);
rcu_barrier();
kfree(f->rules->rules_raw);
kfree(f->rules);
*/
static void canfltr_destroy(struct tcf_proto *tp)
{
*/
static void canfltr_destroy(struct tcf_proto *tp)
{
- struct canfltr_head *head = tp->root;
- struct canfltr_state *f, *n;
-
- list_for_each_entry_safe(f, n, &head->flist, link) {
- list_del(&f->link);
- canfltr_delete_filter(tp, f);
- }
- kfree(head);
+ struct canfltr_head *head = tp->root;
+ struct canfltr_state *f, *n;
+
+ list_for_each_entry_safe(f, n, &head->flist, link) {
+ list_del(&f->link);
+ canfltr_delete_filter(tp, f);
+ }
+ kfree(head);
{
struct canfltr_head *head = (struct canfltr_head *) tp->root;
struct canfltr_state *f;
{
struct canfltr_head *head = (struct canfltr_head *) tp->root;
struct canfltr_state *f;
list_for_each_entry(f, &head->flist, link) {
if (arg->count < arg->skip)
goto skip;
list_for_each_entry(f, &head->flist, link) {
if (arg->count < arg->skip)
goto skip;
-/*
- * Returns diagnostic data for a filter or one of its elements.
+/*
+ * Returns diagnostic data for a filter or one of its elements.
*/
static int canfltr_dump(struct tcf_proto *tp, unsigned long fh,
*/
static int canfltr_dump(struct tcf_proto *tp, unsigned long fh,
- struct sk_buff *skb, struct tcmsg *t)
+ struct sk_buff *skb, struct tcmsg *t)
{
struct canfltr_state *f = (struct canfltr_state *) fh;
struct nlattr *nest;
{
struct canfltr_state *f = (struct canfltr_state *) fh;
struct nlattr *nest;
if (f->res.classid)
NLA_PUT_U32(skb, TCA_CANFLTR_CLASSID, f->res.classid);
if (f->res.classid)
NLA_PUT_U32(skb, TCA_CANFLTR_CLASSID, f->res.classid);
- NLA_PUT(skb, TCA_CANFLTR_RULES, r->rules_count *
+ NLA_PUT(skb, TCA_CANFLTR_RULES, r->rules_count *
sizeof(struct can_filter), r->rules_raw);
sizeof(struct can_filter), r->rules_raw);
module_init(init_canfltr);
module_exit(exit_canfltr);
MODULE_LICENSE("GPL");
module_init(init_canfltr);
module_exit(exit_canfltr);
MODULE_LICENSE("GPL");
-MODULE_AUTHOR(""); // FIXME
+MODULE_AUTHOR(""); /* FIXME */
MODULE_DESCRIPTION("Controller Area Network classifier");
MODULE_DESCRIPTION("Controller Area Network classifier");