Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetoot...
[cascardo/linux.git] / drivers / net / can / dev.c
index 1870c47..bda1888 100644 (file)
@@ -645,19 +645,6 @@ static int can_changelink(struct net_device *dev,
        /* We need synchronization with dev->stop() */
        ASSERT_RTNL();
 
-       if (data[IFLA_CAN_CTRLMODE]) {
-               struct can_ctrlmode *cm;
-
-               /* Do not allow changing controller mode while running */
-               if (dev->flags & IFF_UP)
-                       return -EBUSY;
-               cm = nla_data(data[IFLA_CAN_CTRLMODE]);
-               if (cm->flags & ~priv->ctrlmode_supported)
-                       return -EOPNOTSUPP;
-               priv->ctrlmode &= ~cm->mask;
-               priv->ctrlmode |= cm->flags;
-       }
-
        if (data[IFLA_CAN_BITTIMING]) {
                struct can_bittiming bt;
 
@@ -680,6 +667,19 @@ static int can_changelink(struct net_device *dev,
                }
        }
 
+       if (data[IFLA_CAN_CTRLMODE]) {
+               struct can_ctrlmode *cm;
+
+               /* Do not allow changing controller mode while running */
+               if (dev->flags & IFF_UP)
+                       return -EBUSY;
+               cm = nla_data(data[IFLA_CAN_CTRLMODE]);
+               if (cm->flags & ~priv->ctrlmode_supported)
+                       return -EOPNOTSUPP;
+               priv->ctrlmode &= ~cm->mask;
+               priv->ctrlmode |= cm->flags;
+       }
+
        if (data[IFLA_CAN_RESTART_MS]) {
                /* Do not allow changing restart delay while running */
                if (dev->flags & IFF_UP)
@@ -702,17 +702,17 @@ static int can_changelink(struct net_device *dev,
 static size_t can_get_size(const struct net_device *dev)
 {
        struct can_priv *priv = netdev_priv(dev);
-       size_t size;
-
-       size = nla_total_size(sizeof(u32));   /* IFLA_CAN_STATE */
-       size += nla_total_size(sizeof(struct can_ctrlmode));  /* IFLA_CAN_CTRLMODE */
-       size += nla_total_size(sizeof(u32));  /* IFLA_CAN_RESTART_MS */
-       size += nla_total_size(sizeof(struct can_bittiming)); /* IFLA_CAN_BITTIMING */
-       size += nla_total_size(sizeof(struct can_clock));     /* IFLA_CAN_CLOCK */
-       if (priv->do_get_berr_counter)        /* IFLA_CAN_BERR_COUNTER */
-               size += nla_total_size(sizeof(struct can_berr_counter));
-       if (priv->bittiming_const)            /* IFLA_CAN_BITTIMING_CONST */
+       size_t size = 0;
+
+       size += nla_total_size(sizeof(struct can_bittiming));   /* IFLA_CAN_BITTIMING */
+       if (priv->bittiming_const)                              /* IFLA_CAN_BITTIMING_CONST */
                size += nla_total_size(sizeof(struct can_bittiming_const));
+       size += nla_total_size(sizeof(struct can_clock));       /* IFLA_CAN_CLOCK */
+       size += nla_total_size(sizeof(u32));                    /* IFLA_CAN_STATE */
+       size += nla_total_size(sizeof(struct can_ctrlmode));    /* IFLA_CAN_CTRLMODE */
+       size += nla_total_size(sizeof(u32));                    /* IFLA_CAN_RESTART_MS */
+       if (priv->do_get_berr_counter)                          /* IFLA_CAN_BERR_COUNTER */
+               size += nla_total_size(sizeof(struct can_berr_counter));
 
        return size;
 }
@@ -726,23 +726,20 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
 
        if (priv->do_get_state)
                priv->do_get_state(dev, &state);
-       if (nla_put_u32(skb, IFLA_CAN_STATE, state) ||
-           nla_put(skb, IFLA_CAN_CTRLMODE, sizeof(cm), &cm) ||
-           nla_put_u32(skb, IFLA_CAN_RESTART_MS, priv->restart_ms) ||
-           nla_put(skb, IFLA_CAN_BITTIMING,
+       if (nla_put(skb, IFLA_CAN_BITTIMING,
                    sizeof(priv->bittiming), &priv->bittiming) ||
+           (priv->bittiming_const &&
+            nla_put(skb, IFLA_CAN_BITTIMING_CONST,
+                    sizeof(*priv->bittiming_const), priv->bittiming_const)) ||
            nla_put(skb, IFLA_CAN_CLOCK, sizeof(cm), &priv->clock) ||
+           nla_put_u32(skb, IFLA_CAN_STATE, state) ||
+           nla_put(skb, IFLA_CAN_CTRLMODE, sizeof(cm), &cm) ||
+           nla_put_u32(skb, IFLA_CAN_RESTART_MS, priv->restart_ms) ||
            (priv->do_get_berr_counter &&
             !priv->do_get_berr_counter(dev, &bec) &&
-            nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)) ||
-           (priv->bittiming_const &&
-            nla_put(skb, IFLA_CAN_BITTIMING_CONST,
-                    sizeof(*priv->bittiming_const), priv->bittiming_const)))
-               goto nla_put_failure;
+            nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)))
+               return -EMSGSIZE;
        return 0;
-
-nla_put_failure:
-       return -EMSGSIZE;
 }
 
 static size_t can_get_xstats_size(const struct net_device *dev)