Skip to content

Commit 23b2029

Browse files
committed
firmware: rp1: Simplify rp1_firmware_get
Simplify the implementation of rp1_firmware_get, requiring its clients to have a valid 'firmware' property. Also make it return NULL on error. Link: #6593 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
1 parent 518ce29 commit 23b2029

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

drivers/firmware/rp1.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,42 +159,36 @@ struct rp1_firmware *rp1_firmware_get(struct device_node *client)
159159
struct device_node *fwnode;
160160
struct rp1_firmware *fw;
161161

162-
if (client) {
163-
fwnode = of_parse_phandle(client, "firmware", 0);
164-
if (!fwnode)
165-
fwnode = of_get_parent(client);
166-
if (fwnode && !of_device_is_compatible(fwnode, match)) {
167-
of_node_put(fwnode);
168-
fwnode = NULL;
169-
}
170-
}
171-
162+
if (!client)
163+
return NULL;
164+
fwnode = of_parse_phandle(client, "firmware", 0);
172165
if (!fwnode)
173-
fwnode = of_find_matching_node(NULL, rp1_firmware_of_match);
174-
175-
if (!fwnode)
176-
return ERR_PTR(-ENOENT);
166+
return NULL;
167+
if (!of_device_is_compatible(fwnode, match)) {
168+
of_node_put(fwnode);
169+
return NULL;
170+
}
177171

178172
pdev = of_find_device_by_node(fwnode);
179173
of_node_put(fwnode);
180174

181175
if (!pdev)
182-
return ERR_PTR(-EPROBE_DEFER);
176+
goto err_exit;
183177

184178
fw = platform_get_drvdata(pdev);
185179
if (!fw)
186-
goto err_defer;
180+
goto err_exit;
187181

188182
if (!kref_get_unless_zero(&fw->consumers))
189-
goto err_defer;
183+
goto err_exit;
190184

191185
put_device(&pdev->dev);
192186

193187
return fw;
194188

195-
err_defer:
189+
err_exit:
196190
put_device(&pdev->dev);
197-
return ERR_PTR(-EPROBE_DEFER);
191+
return NULL;
198192
}
199193
EXPORT_SYMBOL_GPL(rp1_firmware_get);
200194

@@ -210,8 +204,8 @@ struct rp1_firmware *devm_rp1_firmware_get(struct device *dev, struct device_nod
210204
int ret;
211205

212206
fw = rp1_firmware_get(client);
213-
if (IS_ERR(fw))
214-
return fw;
207+
if (!fw)
208+
return NULL;
215209

216210
ret = devm_add_action_or_reset(dev, devm_rp1_firmware_put, fw);
217211
if (ret)

0 commit comments

Comments
 (0)