1 From d36a6b361a3a181559daebcf32e11ab18431a854 Mon Sep 17 00:00:00 2001
2 From: Cihangir Akturk <cakturk@gmail.com>
3 Date: Sat, 9 Apr 2016 21:45:18 +0300
4 Subject: [PATCH 164/226] staging: fsl-mc: get rid of mutex_locked variables
6 Remove mutex_locked variables which are used to determine whether mutex is
7 locked, instead add another label to unlock mutex on premature exits due to
10 This patch also addresses the folowing warnings reported by coccinelle:
12 drivers/staging/fsl-mc/bus/mc-allocator.c:237:1-7: preceding lock on line 204
13 drivers/staging/fsl-mc/bus/mc-allocator.c:89:1-7: preceding lock on line 57
14 drivers/staging/fsl-mc/bus/mc-allocator.c:157:1-7: preceding lock on line 124
16 Signed-off-by: Cihangir Akturk <cakturk@gmail.com>
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19 drivers/staging/fsl-mc/bus/mc-allocator.c | 61 ++++++++++++-----------------
20 1 file changed, 24 insertions(+), 37 deletions(-)
22 --- a/drivers/staging/fsl-mc/bus/mc-allocator.c
23 +++ b/drivers/staging/fsl-mc/bus/mc-allocator.c
24 @@ -39,7 +39,6 @@ static int __must_check fsl_mc_resource_
25 struct fsl_mc_resource *resource;
26 struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev;
28 - bool mutex_locked = false;
30 if (WARN_ON(pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES))
32 @@ -55,13 +54,12 @@ static int __must_check fsl_mc_resource_
35 mutex_lock(&res_pool->mutex);
36 - mutex_locked = true;
38 if (WARN_ON(res_pool->max_count < 0))
41 if (WARN_ON(res_pool->free_count < 0 ||
42 res_pool->free_count > res_pool->max_count))
46 resource = devm_kzalloc(&mc_bus_dev->dev, sizeof(*resource),
48 @@ -69,7 +67,7 @@ static int __must_check fsl_mc_resource_
50 dev_err(&mc_bus_dev->dev,
51 "Failed to allocate memory for fsl_mc_resource\n");
56 resource->type = pool_type;
57 @@ -82,10 +80,9 @@ static int __must_check fsl_mc_resource_
58 res_pool->free_count++;
59 res_pool->max_count++;
62 + mutex_unlock(&res_pool->mutex);
65 - mutex_unlock(&res_pool->mutex);
70 @@ -106,7 +103,6 @@ static int __must_check fsl_mc_resource_
71 struct fsl_mc_resource_pool *res_pool;
72 struct fsl_mc_resource *resource;
74 - bool mutex_locked = false;
76 if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type)))
78 @@ -122,13 +118,12 @@ static int __must_check fsl_mc_resource_
81 mutex_lock(&res_pool->mutex);
82 - mutex_locked = true;
84 if (WARN_ON(res_pool->max_count <= 0))
87 if (WARN_ON(res_pool->free_count <= 0 ||
88 res_pool->free_count > res_pool->max_count))
93 * If the device is currently allocated, its resource is not
94 @@ -139,7 +134,7 @@ static int __must_check fsl_mc_resource_
95 dev_err(&mc_bus_dev->dev,
96 "Device %s cannot be removed from resource pool\n",
97 dev_name(&mc_dev->dev));
102 list_del(&resource->node);
103 @@ -150,10 +145,9 @@ static int __must_check fsl_mc_resource_
104 devm_kfree(&mc_bus_dev->dev, resource);
105 mc_dev->resource = NULL;
108 + mutex_unlock(&res_pool->mutex);
111 - mutex_unlock(&res_pool->mutex);
116 @@ -188,21 +182,19 @@ int __must_check fsl_mc_resource_allocat
117 struct fsl_mc_resource *resource;
118 struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev;
120 - bool mutex_locked = false;
122 BUILD_BUG_ON(ARRAY_SIZE(fsl_mc_pool_type_strings) !=
123 FSL_MC_NUM_POOL_TYPES);
125 *new_resource = NULL;
126 if (WARN_ON(pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES))
130 res_pool = &mc_bus->resource_pools[pool_type];
131 if (WARN_ON(res_pool->mc_bus != mc_bus))
135 mutex_lock(&res_pool->mutex);
136 - mutex_locked = true;
137 resource = list_first_entry_or_null(&res_pool->free_list,
138 struct fsl_mc_resource, node);
140 @@ -212,28 +204,26 @@ int __must_check fsl_mc_resource_allocat
141 dev_err(&mc_bus_dev->dev,
142 "No more resources of type %s left\n",
143 fsl_mc_pool_type_strings[pool_type]);
148 if (WARN_ON(resource->type != pool_type))
151 if (WARN_ON(resource->parent_pool != res_pool))
154 if (WARN_ON(res_pool->free_count <= 0 ||
155 res_pool->free_count > res_pool->max_count))
159 list_del(&resource->node);
160 INIT_LIST_HEAD(&resource->node);
162 res_pool->free_count--;
165 mutex_unlock(&res_pool->mutex);
166 *new_resource = resource;
170 - mutex_unlock(&res_pool->mutex);
175 EXPORT_SYMBOL_GPL(fsl_mc_resource_allocate);
176 @@ -241,26 +231,23 @@ EXPORT_SYMBOL_GPL(fsl_mc_resource_alloca
177 void fsl_mc_resource_free(struct fsl_mc_resource *resource)
179 struct fsl_mc_resource_pool *res_pool;
180 - bool mutex_locked = false;
182 res_pool = resource->parent_pool;
183 if (WARN_ON(resource->type != res_pool->type))
187 mutex_lock(&res_pool->mutex);
188 - mutex_locked = true;
189 if (WARN_ON(res_pool->free_count < 0 ||
190 res_pool->free_count >= res_pool->max_count))
194 if (WARN_ON(!list_empty(&resource->node)))
198 list_add_tail(&resource->node, &res_pool->free_list);
199 res_pool->free_count++;
202 - mutex_unlock(&res_pool->mutex);
204 + mutex_unlock(&res_pool->mutex);
206 EXPORT_SYMBOL_GPL(fsl_mc_resource_free);