瀏覽代碼

RDMA/uverbs: Don't overwrite NULL pointer with ZERO_SIZE_PTR

Number of specs is provided by user and in valid case can be equal to zero.
Such argument causes to call to kcalloc() with zero-length request and in
return the ZERO_SIZE_PTR is assigned. This pointer is different from NULL
and makes various if (..) checks to success.

Fixes: b6ba4a9aa59f ("IB/uverbs: Add support for flow counters")
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Leon Romanovsky 7 年之前
父節點
當前提交
a5cc9831af
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      drivers/infiniband/core/uverbs_cmd.c

+ 4 - 1
drivers/infiniband/core/uverbs_cmd.c

@@ -2763,6 +2763,9 @@ static struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)
 	if (!resources)
 	if (!resources)
 		return NULL;
 		return NULL;
 
 
+	if (!num_specs)
+		goto out;
+
 	resources->counters =
 	resources->counters =
 		kcalloc(num_specs, sizeof(*resources->counters), GFP_KERNEL);
 		kcalloc(num_specs, sizeof(*resources->counters), GFP_KERNEL);
 	resources->collection =
 	resources->collection =
@@ -2771,8 +2774,8 @@ static struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)
 	if (!resources->counters || !resources->collection)
 	if (!resources->counters || !resources->collection)
 		goto err;
 		goto err;
 
 
+out:
 	resources->max = num_specs;
 	resources->max = num_specs;
-
 	return resources;
 	return resources;
 
 
 err:
 err: