Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- linux-5.10.64/drivers/firmware/raspberrypi.c 2021-09-29 23:19:57.006485785 +0200
- +++ build_dir/target-aarch64_cortex-a53_musl/linux-bcm27xx_bcm2710/linux-5.10.69/drivers/firmware/raspberrypi.c 2021-09-29 23:26:45.117905773 +0200
- @@ -7,6 +7,7 @@
- */
- #include <linux/dma-mapping.h>
- +#include <linux/kref.h>
- #include <linux/mailbox_client.h>
- #include <linux/module.h>
- #include <linux/of_platform.h>
- @@ -29,6 +30,8 @@
- struct completion c;
- u32 enabled;
- u32 get_throttled;
- +
- + struct kref consumers;
- };
- static struct platform_device *g_pdev;
- @@ -340,12 +343,31 @@
- -1, NULL, 0);
- }
- +static void rpi_firmware_delete(struct kref *kref)
- +{
- + struct rpi_firmware *fw = container_of(kref, struct rpi_firmware,
- + consumers);
- +
- + mbox_free_channel(fw->chan);
- + kfree(fw);
- +}
- +
- +void rpi_firmware_put(struct rpi_firmware *fw)
- +{
- + kref_put(&fw->consumers, rpi_firmware_delete);
- +}
- +EXPORT_SYMBOL_GPL(rpi_firmware_put);
- +
- static int rpi_firmware_probe(struct platform_device *pdev)
- {
- struct device *dev = &pdev->dev;
- struct rpi_firmware *fw;
- - fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
- + /*
- + * Memory will be freed by rpi_firmware_delete() once all users have
- + * released their firmware handles. Don't use devm_kzalloc() here.
- + */
- + fw = kzalloc(sizeof(*fw), GFP_KERNEL);
- if (!fw)
- return -ENOMEM;
- @@ -362,6 +384,7 @@
- }
- init_completion(&fw->c);
- + kref_init(&fw->consumers);
- platform_set_drvdata(pdev, fw);
- g_pdev = pdev;
- @@ -392,7 +415,9 @@
- rpi_hwmon = NULL;
- platform_device_unregister(rpi_clk);
- rpi_clk = NULL;
- - mbox_free_channel(fw->chan);
- +
- + rpi_firmware_put(fw);
- +
- g_pdev = NULL;
- return 0;
- @@ -402,16 +427,32 @@
- * rpi_firmware_get - Get pointer to rpi_firmware structure.
- * @firmware_node: Pointer to the firmware Device Tree node.
- *
- + * The reference to rpi_firmware has to be released with rpi_firmware_put().
- + *
- * Returns NULL is the firmware device is not ready.
- */
- struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)
- {
- struct platform_device *pdev = g_pdev;
- + struct rpi_firmware *fw;
- if (!pdev)
- return NULL;
- - return platform_get_drvdata(pdev);
- + fw = platform_get_drvdata(pdev);
- + if (!fw)
- + goto err_put_device;
- +
- + if (!kref_get_unless_zero(&fw->consumers))
- + goto err_put_device;
- +
- + put_device(&pdev->dev);
- +
- + return fw;
- +
- +err_put_device:
- + put_device(&pdev->dev);
- + return NULL;
- }
- EXPORT_SYMBOL_GPL(rpi_firmware_get);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement