devlink: Fix resource coverity errors
authorArkadi Sharshevsky <arkadis@mellanox.com>
Mon, 26 Feb 2018 16:25:42 +0000 (18:25 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 27 Feb 2018 16:16:42 +0000 (11:16 -0500)
Fix resource coverity errors.

Fixes: d9f9b9a4d05f ("devlink: Add support for resource abstraction")
Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/devlink.c

index 92aad7c4638392b3f668d296970adda7e23f0623..7b1076dc1292f7ef02248d46f8c733c54adbeb85 100644 (file)
@@ -1695,10 +1695,11 @@ static int devlink_dpipe_table_put(struct sk_buff *skb,
                goto nla_put_failure;
 
        if (table->resource_valid) {
-               nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID,
-                                 table->resource_id, DEVLINK_ATTR_PAD);
-               nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS,
-                                 table->resource_units, DEVLINK_ATTR_PAD);
+               if (nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID,
+                                     table->resource_id, DEVLINK_ATTR_PAD) ||
+                   nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS,
+                                     table->resource_units, DEVLINK_ATTR_PAD))
+                       goto nla_put_failure;
        }
        if (devlink_dpipe_matches_put(table, skb))
                goto nla_put_failure;
@@ -2372,20 +2373,22 @@ static int devlink_nl_cmd_resource_set(struct sk_buff *skb,
        return 0;
 }
 
-static void
+static int
 devlink_resource_size_params_put(struct devlink_resource *resource,
                                 struct sk_buff *skb)
 {
        struct devlink_resource_size_params *size_params;
 
        size_params = resource->size_params;
-       nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_GRAN,
-                         size_params->size_granularity, DEVLINK_ATTR_PAD);
-       nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MAX,
-                         size_params->size_max, DEVLINK_ATTR_PAD);
-       nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MIN,
-                         size_params->size_min, DEVLINK_ATTR_PAD);
-       nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_UNIT, size_params->unit);
+       if (nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_GRAN,
+                             size_params->size_granularity, DEVLINK_ATTR_PAD) ||
+           nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MAX,
+                             size_params->size_max, DEVLINK_ATTR_PAD) ||
+           nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MIN,
+                             size_params->size_min, DEVLINK_ATTR_PAD) ||
+           nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_UNIT, size_params->unit))
+               return -EMSGSIZE;
+       return 0;
 }
 
 static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb,
@@ -2409,10 +2412,12 @@ static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb,
                nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_NEW,
                                  resource->size_new, DEVLINK_ATTR_PAD);
        if (resource->resource_ops && resource->resource_ops->occ_get)
-               nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_OCC,
-                                 resource->resource_ops->occ_get(devlink),
-                                 DEVLINK_ATTR_PAD);
-       devlink_resource_size_params_put(resource, skb);
+               if (nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_OCC,
+                                     resource->resource_ops->occ_get(devlink),
+                                     DEVLINK_ATTR_PAD))
+                       goto nla_put_failure;
+       if (devlink_resource_size_params_put(resource, skb))
+               goto nla_put_failure;
        if (list_empty(&resource->resource_list))
                goto out;