diff mbox series

[2/6] media: allegro: fix module removal if initialization failed

Message ID 20210908130315.3295253-3-m.tretter@pengutronix.de
State Accepted
Commit dacc21d638c427a53448d91bd976ee6762822911
Headers show
Series media: allegro: Add support for the Encoder Buffer | expand

Commit Message

Michael Tretter Sept. 8, 2021, 1:03 p.m. UTC
If the module probe finished, but the firmware initialization failed,
removing the module must not revert the firmware initialization.

Add a field to track the status of the firmware initialization and only
roll it back, if the firmware was successfully initialized.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 .../media/platform/allegro-dvt/allegro-core.c   | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
index 14a119b43bca..89d6de6082f6 100644
--- a/drivers/media/platform/allegro-dvt/allegro-core.c
+++ b/drivers/media/platform/allegro-dvt/allegro-core.c
@@ -142,6 +142,7 @@  struct allegro_dev {
 	struct allegro_buffer suballocator;
 
 	struct completion init_complete;
+	bool initialized;
 
 	/* The mailbox interface */
 	struct allegro_mbox *mbox_command;
@@ -3632,6 +3633,8 @@  static void allegro_fw_callback(const struct firmware *fw, void *context)
 		 "allegro codec registered as /dev/video%d\n",
 		 dev->video_dev.num);
 
+	dev->initialized = true;
+
 	release_firmware(fw_codec);
 	release_firmware(fw);
 
@@ -3678,6 +3681,8 @@  static int allegro_probe(struct platform_device *pdev)
 
 	mutex_init(&dev->lock);
 
+	dev->initialized = false;
+
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
 	if (!res) {
 		dev_err(&pdev->dev,
@@ -3748,11 +3753,13 @@  static int allegro_remove(struct platform_device *pdev)
 {
 	struct allegro_dev *dev = platform_get_drvdata(pdev);
 
-	video_unregister_device(&dev->video_dev);
-	if (dev->m2m_dev)
-		v4l2_m2m_release(dev->m2m_dev);
-	allegro_mcu_hw_deinit(dev);
-	allegro_free_fw_codec(dev);
+	if (dev->initialized) {
+		video_unregister_device(&dev->video_dev);
+		if (dev->m2m_dev)
+			v4l2_m2m_release(dev->m2m_dev);
+		allegro_mcu_hw_deinit(dev);
+		allegro_free_fw_codec(dev);
+	}
 
 	v4l2_device_unregister(&dev->v4l2_dev);