layerscape: add ls1088ardb device support
[openwrt/staging/lynxis/omap.git] / target / linux / layerscape / patches-4.4 / 7164-staging-fsl-mc-get-rid-of-mutex_locked-variables.patch
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
5
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
8 an error.
9
10 This patch also addresses the folowing warnings reported by coccinelle:
11
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
15
16 Signed-off-by: Cihangir Akturk <cakturk@gmail.com>
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
18 ---
19 drivers/staging/fsl-mc/bus/mc-allocator.c | 61 ++++++++++++-----------------
20 1 file changed, 24 insertions(+), 37 deletions(-)
21
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;
27 int error = -EINVAL;
28 - bool mutex_locked = false;
29
30 if (WARN_ON(pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES))
31 goto out;
32 @@ -55,13 +54,12 @@ static int __must_check fsl_mc_resource_
33 goto out;
34
35 mutex_lock(&res_pool->mutex);
36 - mutex_locked = true;
37
38 if (WARN_ON(res_pool->max_count < 0))
39 - goto out;
40 + goto out_unlock;
41 if (WARN_ON(res_pool->free_count < 0 ||
42 res_pool->free_count > res_pool->max_count))
43 - goto out;
44 + goto out_unlock;
45
46 resource = devm_kzalloc(&mc_bus_dev->dev, sizeof(*resource),
47 GFP_KERNEL);
48 @@ -69,7 +67,7 @@ static int __must_check fsl_mc_resource_
49 error = -ENOMEM;
50 dev_err(&mc_bus_dev->dev,
51 "Failed to allocate memory for fsl_mc_resource\n");
52 - goto out;
53 + goto out_unlock;
54 }
55
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++;
60 error = 0;
61 +out_unlock:
62 + mutex_unlock(&res_pool->mutex);
63 out:
64 - if (mutex_locked)
65 - mutex_unlock(&res_pool->mutex);
66 -
67 return error;
68 }
69
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;
73 int error = -EINVAL;
74 - bool mutex_locked = false;
75
76 if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type)))
77 goto out;
78 @@ -122,13 +118,12 @@ static int __must_check fsl_mc_resource_
79 goto out;
80
81 mutex_lock(&res_pool->mutex);
82 - mutex_locked = true;
83
84 if (WARN_ON(res_pool->max_count <= 0))
85 - goto out;
86 + goto out_unlock;
87 if (WARN_ON(res_pool->free_count <= 0 ||
88 res_pool->free_count > res_pool->max_count))
89 - goto out;
90 + goto out_unlock;
91
92 /*
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));
98 - goto out;
99 + goto out_unlock;
100 }
101
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;
106 error = 0;
107 +out_unlock:
108 + mutex_unlock(&res_pool->mutex);
109 out:
110 - if (mutex_locked)
111 - mutex_unlock(&res_pool->mutex);
112 -
113 return error;
114 }
115
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;
119 int error = -EINVAL;
120 - bool mutex_locked = false;
121
122 BUILD_BUG_ON(ARRAY_SIZE(fsl_mc_pool_type_strings) !=
123 FSL_MC_NUM_POOL_TYPES);
124
125 *new_resource = NULL;
126 if (WARN_ON(pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES))
127 - goto error;
128 + goto out;
129
130 res_pool = &mc_bus->resource_pools[pool_type];
131 if (WARN_ON(res_pool->mc_bus != mc_bus))
132 - goto error;
133 + goto out;
134
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);
139
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]);
144 - goto error;
145 + goto out_unlock;
146 }
147
148 if (WARN_ON(resource->type != pool_type))
149 - goto error;
150 + goto out_unlock;
151 if (WARN_ON(resource->parent_pool != res_pool))
152 - goto error;
153 + goto out_unlock;
154 if (WARN_ON(res_pool->free_count <= 0 ||
155 res_pool->free_count > res_pool->max_count))
156 - goto error;
157 + goto out_unlock;
158
159 list_del(&resource->node);
160 INIT_LIST_HEAD(&resource->node);
161
162 res_pool->free_count--;
163 + error = 0;
164 +out_unlock:
165 mutex_unlock(&res_pool->mutex);
166 *new_resource = resource;
167 - return 0;
168 -error:
169 - if (mutex_locked)
170 - mutex_unlock(&res_pool->mutex);
171 -
172 +out:
173 return error;
174 }
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)
178 {
179 struct fsl_mc_resource_pool *res_pool;
180 - bool mutex_locked = false;
181
182 res_pool = resource->parent_pool;
183 if (WARN_ON(resource->type != res_pool->type))
184 - goto out;
185 + return;
186
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))
191 - goto out;
192 + goto out_unlock;
193
194 if (WARN_ON(!list_empty(&resource->node)))
195 - goto out;
196 + goto out_unlock;
197
198 list_add_tail(&resource->node, &res_pool->free_list);
199 res_pool->free_count++;
200 -out:
201 - if (mutex_locked)
202 - mutex_unlock(&res_pool->mutex);
203 +out_unlock:
204 + mutex_unlock(&res_pool->mutex);
205 }
206 EXPORT_SYMBOL_GPL(fsl_mc_resource_free);
207