media: mgb4: Fix debugfs error handling
authorMartin Tůma <martin.tuma@digiteqautomotive.com>
Mon, 26 Aug 2024 13:26:04 +0000 (15:26 +0200)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Sat, 12 Oct 2024 14:28:24 +0000 (16:28 +0200)
Fix broken handling of debugfs_create_dir() errors including errors
creating the parent mgb4(PCIe) device's debugfs directory.

Signed-off-by: Martin Tůma <martin.tuma@digiteqautomotive.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/pci/mgb4/mgb4_core.c
drivers/media/pci/mgb4/mgb4_core.h
drivers/media/pci/mgb4/mgb4_vin.c
drivers/media/pci/mgb4/mgb4_vin.h
drivers/media/pci/mgb4/mgb4_vout.c
drivers/media/pci/mgb4/mgb4_vout.h

index 2819bbdab4842f59018bce3b8b92b74148fb0aa6..bc63dc81bcae0d20924174be74b93a2139d5879f 100644 (file)
@@ -582,9 +582,7 @@ static int mgb4_probe(struct pci_dev *pdev, const struct pci_device_id *id)
                                                            NULL);
 #endif
 
-#ifdef CONFIG_DEBUG_FS
        mgbdev->debugfs = debugfs_create_dir(dev_name(&pdev->dev), NULL);
-#endif
 
        /* Get card serial number. On systems without MTD flash support we may
         * get an error thus ignore the return value. An invalid serial number
@@ -646,6 +644,8 @@ static void mgb4_remove(struct pci_dev *pdev)
        hwmon_device_unregister(mgbdev->hwmon_dev);
 #endif
 
+       debugfs_remove_recursive(mgbdev->debugfs);
+
        if (mgbdev->indio_dev)
                mgb4_trigger_free(mgbdev->indio_dev);
 
@@ -656,10 +656,6 @@ static void mgb4_remove(struct pci_dev *pdev)
                if (mgbdev->vin[i])
                        mgb4_vin_free(mgbdev->vin[i]);
 
-#ifdef CONFIG_DEBUG_FS
-       debugfs_remove_recursive(mgbdev->debugfs);
-#endif
-
        device_remove_groups(&mgbdev->pdev->dev, mgb4_pci_groups);
        free_spi(mgbdev);
        free_i2c(mgbdev);
index b52cd67270b56da3b5facd504518c008990cdc78..9aec62514c0be94a5fb9a8073455a21ecf0ad09d 100644 (file)
@@ -68,9 +68,7 @@ struct mgb4_dev {
        u8 module_version;
        u32 serial_number;
 
-#ifdef CONFIG_DEBUG_FS
        struct dentry *debugfs;
-#endif
 };
 
 #endif
index e9332abb31729eaae9b3ab22bb68bfd698f00c29..185fb28226b60c3253f64d78e945172c6321ac33 100644 (file)
@@ -853,14 +853,16 @@ static void fpga_init(struct mgb4_vin_dev *vindev)
        mgb4_write_reg(video, regs->config, 1U << 9);
 }
 
-#ifdef CONFIG_DEBUG_FS
-static void debugfs_init(struct mgb4_vin_dev *vindev)
+static void create_debugfs(struct mgb4_vin_dev *vindev)
 {
+#ifdef CONFIG_DEBUG_FS
        struct mgb4_regs *video = &vindev->mgbdev->video;
+       struct dentry *entry;
 
-       vindev->debugfs = debugfs_create_dir(vindev->vdev.name,
-                                            vindev->mgbdev->debugfs);
-       if (!vindev->debugfs)
+       if (IS_ERR_OR_NULL(vindev->mgbdev->debugfs))
+               return;
+       entry = debugfs_create_dir(vindev->vdev.name, vindev->mgbdev->debugfs);
+       if (IS_ERR(entry))
                return;
 
        vindev->regs[0].name = "CONFIG";
@@ -892,10 +894,9 @@ static void debugfs_init(struct mgb4_vin_dev *vindev)
        vindev->regset.base = video->membase;
        vindev->regset.regs = vindev->regs;
 
-       debugfs_create_regset32("registers", 0444, vindev->debugfs,
-                               &vindev->regset);
-}
+       debugfs_create_regset32("registers", 0444, entry, &vindev->regset);
 #endif
+}
 
 struct mgb4_vin_dev *mgb4_vin_create(struct mgb4_dev *mgbdev, int id)
 {
@@ -1001,9 +1002,7 @@ struct mgb4_vin_dev *mgb4_vin_create(struct mgb4_dev *mgbdev, int id)
                goto err_video_dev;
        }
 
-#ifdef CONFIG_DEBUG_FS
-       debugfs_init(vindev);
-#endif
+       create_debugfs(vindev);
 
        return vindev;
 
@@ -1034,10 +1033,6 @@ void mgb4_vin_free(struct mgb4_vin_dev *vindev)
        free_irq(vin_irq, vindev);
        free_irq(err_irq, vindev);
 
-#ifdef CONFIG_DEBUG_FS
-       debugfs_remove_recursive(vindev->debugfs);
-#endif
-
        groups = MGB4_IS_GMSL(vindev->mgbdev)
          ? mgb4_gmsl_in_groups : mgb4_fpdl3_in_groups;
        device_remove_groups(&vindev->vdev.dev, groups);
index 9693bd0ce180608c5f9c8bc4710dfc979265393e..8fd10c0a55546a9fbecee575e230f315f57aa504 100644 (file)
@@ -58,7 +58,6 @@ struct mgb4_vin_dev {
        const struct mgb4_vin_config *config;
 
 #ifdef CONFIG_DEBUG_FS
-       struct dentry *debugfs;
        struct debugfs_regset32 regset;
        struct debugfs_reg32 regs[sizeof(struct mgb4_vin_regs) / 4];
 #endif
index 998edcbd972387d6fa084f105479d94dc9096531..133110aac68808fa956ae7da8cb2e6bd27cf7447 100644 (file)
@@ -676,14 +676,16 @@ static void fpga_init(struct mgb4_vout_dev *voutdev)
                       (voutdev->config->id + MGB4_VIN_DEVICES) << 2 | 1 << 4);
 }
 
-#ifdef CONFIG_DEBUG_FS
-static void debugfs_init(struct mgb4_vout_dev *voutdev)
+static void create_debugfs(struct mgb4_vout_dev *voutdev)
 {
+#ifdef CONFIG_DEBUG_FS
        struct mgb4_regs *video = &voutdev->mgbdev->video;
+       struct dentry *entry;
 
-       voutdev->debugfs = debugfs_create_dir(voutdev->vdev.name,
-                                             voutdev->mgbdev->debugfs);
-       if (!voutdev->debugfs)
+       if (IS_ERR_OR_NULL(voutdev->mgbdev->debugfs))
+               return;
+       entry = debugfs_create_dir(voutdev->vdev.name, voutdev->mgbdev->debugfs);
+       if (IS_ERR(entry))
                return;
 
        voutdev->regs[0].name = "CONFIG";
@@ -711,10 +713,9 @@ static void debugfs_init(struct mgb4_vout_dev *voutdev)
        voutdev->regset.base = video->membase;
        voutdev->regset.regs = voutdev->regs;
 
-       debugfs_create_regset32("registers", 0444, voutdev->debugfs,
-                               &voutdev->regset);
-}
+       debugfs_create_regset32("registers", 0444, entry, &voutdev->regset);
 #endif
+}
 
 struct mgb4_vout_dev *mgb4_vout_create(struct mgb4_dev *mgbdev, int id)
 {
@@ -808,9 +809,7 @@ struct mgb4_vout_dev *mgb4_vout_create(struct mgb4_dev *mgbdev, int id)
                goto err_video_dev;
        }
 
-#ifdef CONFIG_DEBUG_FS
-       debugfs_init(voutdev);
-#endif
+       create_debugfs(voutdev);
 
        return voutdev;
 
@@ -833,10 +832,6 @@ void mgb4_vout_free(struct mgb4_vout_dev *voutdev)
 
        free_irq(irq, voutdev);
 
-#ifdef CONFIG_DEBUG_FS
-       debugfs_remove_recursive(voutdev->debugfs);
-#endif
-
        groups = MGB4_IS_GMSL(voutdev->mgbdev)
          ? mgb4_gmsl_out_groups : mgb4_fpdl3_out_groups;
        device_remove_groups(&voutdev->vdev.dev, groups);
index adc8fe1e7ae68b3b619cbce481067e77761ed15e..a07eeabdcf342bedcd78c591e1004d41cea12bd6 100644 (file)
@@ -54,7 +54,6 @@ struct mgb4_vout_dev {
        const struct mgb4_vout_config *config;
 
 #ifdef CONFIG_DEBUG_FS
-       struct dentry *debugfs;
        struct debugfs_regset32 regset;
        struct debugfs_reg32 regs[sizeof(struct mgb4_vout_regs) / 4];
 #endif