From 71d1656da6cd638110a43e9c873ba97ea3793490 Mon Sep 17 00:00:00 2001 From: Rostislav Lisovy Date: Thu, 28 Jun 2012 17:47:13 +0200 Subject: [PATCH] em_canid: Removed unnecessary CAN_EFF_MASK masking, error handling etc. --- net/sched/Kconfig | 4 ++-- net/sched/em_canid.c | 48 +++++++++++++++++--------------------------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/net/sched/Kconfig b/net/sched/Kconfig index bc0ceab29aa..68a4c38a58b 100644 --- a/net/sched/Kconfig +++ b/net/sched/Kconfig @@ -486,11 +486,11 @@ config NET_EMATCH_TEXT module will be called em_text. config NET_EMATCH_CANID - tristate "CAN ID" + tristate "CAN Identifier" depends on NET_EMATCH && CAN ---help--- Say Y here if you want to be able to classify CAN frames based - on CAN ID. + on CAN Identifier. To compile this code as a module, choose M here: the module will be called em_canid. diff --git a/net/sched/em_canid.c b/net/sched/em_canid.c index 1cdd4a175af..f0c7c757e3a 100644 --- a/net/sched/em_canid.c +++ b/net/sched/em_canid.c @@ -24,7 +24,7 @@ #include #include -#define EM_CAN_RULES_MAX 500 +#define EM_CAN_RULES_MAX 500 struct canid_match { /* For each SFF CAN ID (11 bit) there is one record in this bitfield */ @@ -98,17 +98,16 @@ static int em_canid_match(struct sk_buff *skb, struct tcf_ematch *m, { struct canid_match *cm = em_canid_priv(m); canid_t can_id; - unsigned int match = false; + int match = false; int i; + const struct can_filter *lp; can_id = em_canid_get_id(skb); if (can_id & CAN_EFF_FLAG) { - can_id &= CAN_EFF_MASK; - - for (i = 0; i < cm->eff_rules_count; i++) { - if (!(((cm->rules_raw[i].can_id ^ can_id) & - cm->rules_raw[i].can_mask) & CAN_EFF_MASK)) { + for (i = 0, lp = cm->rules_raw; + i < cm->eff_rules_count; i++, lp++) { + if (!(((lp->can_id ^ can_id) & lp->can_mask))) { match = true; break; } @@ -132,29 +131,25 @@ static int em_canid_change(struct tcf_proto *tp, void *data, int len, */ struct canid_match *cm; struct canid_match *cm_old = (struct canid_match *) m->data; - int err; int i; int rulescnt; - if (len < sizeof(struct can_filter)) + if (len % sizeof(struct can_filter)) + return -EINVAL; + + if (len > sizeof(struct can_filter) * EM_CAN_RULES_MAX) return -EINVAL; rulescnt = len / sizeof(struct can_filter); - err = -ENOBUFS; cm = kzalloc(sizeof(struct canid_match) + sizeof(struct can_filter) * rulescnt, GFP_KERNEL); - if (cm == NULL) - goto errout; + if (!cm) + return -ENOMEM; cm->sff_rules_count = 0; cm->eff_rules_count = 0; cm->rules_count = rulescnt; - err = -EINVAL; - - /* Be sure to fit into the array */ - if (cm->rules_count > EM_CAN_RULES_MAX) - goto errout_free; /* * We need two for() loops for copying rules into @@ -163,8 +158,9 @@ static int em_canid_change(struct tcf_proto *tp, void *data, int len, /* Process EFF frame rules*/ for (i = 0; i < cm->rules_count; i++) { - if ((conf[i].can_id & CAN_EFF_FLAG) && - (conf[i].can_mask & CAN_EFF_FLAG)) { + if (((conf[i].can_id & CAN_EFF_FLAG) && + (conf[i].can_mask & CAN_EFF_FLAG)) || + !(conf[i].can_mask & CAN_EFF_FLAG)) { memcpy(cm->rules_raw + cm->eff_rules_count, &conf[i], sizeof(struct can_filter)); @@ -197,16 +193,11 @@ static int em_canid_change(struct tcf_proto *tp, void *data, int len, m->data = (unsigned long) cm; if (cm_old != NULL) { - printk("canid: Configuring an existing ematch!\n"); + printk(KERN_ERR"canid: Configuring an existing ematch!\n"); kfree(cm_old); } return 0; - -errout_free: - kfree(cm); -errout: - return err; } static void em_canid_destroy(struct tcf_proto *tp, struct tcf_ematch *m) @@ -224,14 +215,11 @@ static int em_canid_dump(struct sk_buff *skb, struct tcf_ematch *m) * When configuring this ematch 'rules_count' is set not to exceed * 'rules_raw' array size */ - if (nla_put_nohdr(skb, sizeof(cm->rules_raw[0]) * cm->rules_count, + if (nla_put_nohdr(skb, sizeof(struct can_filter) * cm->rules_count, &cm->rules_raw) < 0) - goto nla_put_failure; + return -EMSGSIZE; return 0; - -nla_put_failure: - return -1; } static struct tcf_ematch_ops em_canid_ops = { -- 2.39.2