]> rtime.felk.cvut.cz Git - lisovros/linux_canprio.git/commitdiff
em_canid: Removed unnecessary CAN_EFF_MASK masking, error handling etc.
authorRostislav Lisovy <lisovy@gmail.com>
Thu, 28 Jun 2012 15:47:13 +0000 (17:47 +0200)
committerRostislav Lisovy <lisovy@gmail.com>
Thu, 28 Jun 2012 15:47:13 +0000 (17:47 +0200)
net/sched/Kconfig
net/sched/em_canid.c

index bc0ceab29aadbe2603bc214334f35fe0f46b9e33..68a4c38a58b455d0d782945475846d36a6eff4f7 100644 (file)
@@ -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.
index 1cdd4a175afe8928427b23cabc809df71e58d3cf..f0c7c757e3a3e354d61d3b424c8f3431199be74e 100644 (file)
@@ -24,7 +24,7 @@
 #include <net/pkt_cls.h>
 #include <linux/can.h>
 
-#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 = {