Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle probe dependencies and hard errors better #6645

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions drivers/firmware/rp1.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ static void rp1_firmware_delete(struct kref *kref)

void rp1_firmware_put(struct rp1_firmware *fw)
{
kref_put(&fw->consumers, rp1_firmware_delete);
if (!IS_ERR_OR_NULL(fw))
kref_put(&fw->consumers, rp1_firmware_delete);
}
EXPORT_SYMBOL_GPL(rp1_firmware_put);

Expand Down Expand Up @@ -157,7 +158,7 @@ struct rp1_firmware *rp1_firmware_get(struct device_node *client)
const char *match = rp1_firmware_of_match[0].compatible;
struct platform_device *pdev;
struct device_node *fwnode;
struct rp1_firmware *fw;
struct rp1_firmware *fw = NULL;

if (!client)
return NULL;
Expand All @@ -166,17 +167,17 @@ struct rp1_firmware *rp1_firmware_get(struct device_node *client)
return NULL;
if (!of_device_is_compatible(fwnode, match)) {
of_node_put(fwnode);
return NULL;
return ERR_PTR(-ENXIO);
}

pdev = of_find_device_by_node(fwnode);
of_node_put(fwnode);

if (!pdev)
goto err_exit;
return ERR_PTR(-ENXIO);

fw = platform_get_drvdata(pdev);
if (!fw)
if (IS_ERR_OR_NULL(fw))
goto err_exit;

if (!kref_get_unless_zero(&fw->consumers))
Expand All @@ -188,7 +189,7 @@ struct rp1_firmware *rp1_firmware_get(struct device_node *client)

err_exit:
put_device(&pdev->dev);
return NULL;
return fw;
}
EXPORT_SYMBOL_GPL(rp1_firmware_get);

Expand All @@ -204,8 +205,8 @@ struct rp1_firmware *devm_rp1_firmware_get(struct device *dev, struct device_nod
int ret;

fw = rp1_firmware_get(client);
if (!fw)
return NULL;
if (IS_ERR_OR_NULL(fw))
return fw;

ret = devm_add_action_or_reset(dev, devm_rp1_firmware_put, fw);
if (ret)
Expand Down Expand Up @@ -270,19 +271,18 @@ static int rp1_firmware_probe(struct platform_device *pdev)
init_completion(&fw->c);
kref_init(&fw->consumers);

platform_set_drvdata(pdev, fw);

ret = rp1_firmware_message(fw, GET_FIRMWARE_VERSION,
NULL, 0, &version, sizeof(version));
if (ret == sizeof(version)) {
dev_info(dev, "RP1 Firmware version %08x%08x%08x%08x%08x\n",
version[0], version[1], version[2], version[3], version[4]);
ret = 0;
} else if (ret >= 0) {
ret = -EIO;
platform_set_drvdata(pdev, fw);
} else {
rp1_firmware_put(fw);
platform_set_drvdata(pdev, ERR_PTR(-ENOENT));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do dereference this in rp1_firmware_remove (without a check).
I'm not sure if that can happen, but looks like a potential pitfall.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing the obvious fix has uncovered some deficiencies in the end-of-life code. Thank goodness for runtime overlays.

}

return ret;
return 0;
}

static int rp1_firmware_remove(struct platform_device *pdev)
Expand Down
2 changes: 0 additions & 2 deletions drivers/mailbox/rp1-mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ static struct mbox_chan *rp1_mbox_xlate(struct mbox_controller *mbox,
return ERR_PTR(-EINVAL);

chan = &mbox->chans[doorbell];
if (chan->con_priv)
return ERR_PTR(-EBUSY);

chan->con_priv = (void *)(uintptr_t)(1 << doorbell);

Expand Down
11 changes: 9 additions & 2 deletions drivers/misc/rp1-pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,8 +1277,10 @@ static int rp1_pio_probe(struct platform_device *pdev)
return dev_err_probe(dev, pdev->id, "alias is missing\n");

fw = devm_rp1_firmware_get(dev, dev->of_node);
if (IS_ERR_OR_NULL(fw))
return dev_err_probe(dev, -ENOENT, "failed to contact RP1 firmware\n");
if (!fw)
return dev_err_probe(dev, -EPROBE_DEFER, "failed to find RP1 firmware driver\n");
if (IS_ERR(fw))
return dev_err_probe(dev, PTR_ERR(fw), "failed to contact RP1 firmware\n");
ret = rp1_firmware_get_feature(fw, FOURCC_PIO, &op_base, &op_count);
if (ret < 0)
return ret;
Expand Down Expand Up @@ -1355,6 +1357,11 @@ static void rp1_pio_remove(struct platform_device *pdev)

if (g_pio == pio)
g_pio = NULL;

device_destroy(pio->dev_class, pio->dev_num);
cdev_del(&pio->cdev);
class_destroy(pio->dev_class);
unregister_chrdev_region(pio->dev_num, 1);
}

static const struct of_device_id rp1_pio_ids[] = {
Expand Down