Reduces the size of the probe function by adding zoran_i2c_init/zoran_i2c_exit
functions.

Signed-off-by: Corentin Labbe <cla...@baylibre.com>
---
 drivers/staging/media/zoran/zoran_card.c | 67 ++++++++++++++++++------
 1 file changed, 51 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 9bc5af34d909..fe4d867bf341 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -874,6 +874,53 @@ static int zoran_init_video_devices(struct zoran *zr)
        return err;
 }
 
+/*
+ * v4l2_device_unregister() will care about removing zr->encoder/zr->decoder
+ * via v4l2_i2c_subdev_unregister()
+ */
+static int zoran_i2c_init(struct zoran *zr)
+{
+       int err;
+
+       pci_info(zr->pci_dev, "Initializing i2c bus...\n");
+
+       err = zoran_register_i2c(zr);
+       if (err) {
+               pci_err(zr->pci_dev, "%s - cannot initialize i2c bus\n", 
__func__);
+               return err;
+       }
+
+       zr->decoder = v4l2_i2c_new_subdev(&zr->v4l2_dev, &zr->i2c_adapter,
+                                         zr->card.i2c_decoder, 0,
+                                         zr->card.addrs_decoder);
+       if (!zr->decoder) {
+               pci_err(zr->pci_dev, "Fail to get decoder\n");
+               err = -EINVAL;
+               goto error_decoder;
+       }
+
+       if (zr->card.i2c_encoder) {
+               zr->encoder = v4l2_i2c_new_subdev(&zr->v4l2_dev, 
&zr->i2c_adapter,
+                                                 zr->card.i2c_encoder, 0,
+                                                 zr->card.addrs_encoder);
+               if (!zr->encoder) {
+                       pci_err(zr->pci_dev, "Fail to get encoder\n");
+                       err = -EINVAL;
+                       goto error_decoder;
+               }
+       }
+       return 0;
+
+error_decoder:
+       zoran_unregister_i2c(zr);
+       return err;
+}
+
+static void zoran_i2c_exit(struct zoran *zr)
+{
+       zoran_unregister_i2c(zr);
+}
+
 void zoran_open_init_params(struct zoran *zr)
 {
        int i;
@@ -1001,7 +1048,7 @@ static void zoran_remove(struct pci_dev *pdev)
                videocodec_detach(zr->vfe);
 
        /* unregister i2c bus */
-       zoran_unregister_i2c(zr);
+       zoran_i2c_exit(zr);
        /* disable PCI bus-mastering */
        zoran_set_pci_master(zr, 0);
        /* put chip into reset */
@@ -1285,22 +1332,10 @@ static int zoran_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
        }
 
        zr36057_restart(zr);
-       /* i2c */
-       pci_info(zr->pci_dev, "Initializing i2c bus...\n");
 
-       if (zoran_register_i2c(zr) < 0) {
-               pci_err(pdev, "%s - can't initialize i2c bus\n", __func__);
+       err = zoran_i2c_init(zr);
+       if (err)
                goto zr_free_irq;
-       }
-
-       zr->decoder = v4l2_i2c_new_subdev(&zr->v4l2_dev, &zr->i2c_adapter,
-                                         zr->card.i2c_decoder, 0,
-                                         zr->card.addrs_decoder);
-
-       if (zr->card.i2c_encoder)
-               zr->encoder = v4l2_i2c_new_subdev(&zr->v4l2_dev, 
&zr->i2c_adapter,
-                                                 zr->card.i2c_encoder, 0,
-                                                 zr->card.addrs_encoder);
 
        pci_info(zr->pci_dev, "Initializing videocodec bus...\n");
 
@@ -1377,7 +1412,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 zr_detach_codec:
        videocodec_detach(zr->codec);
 zr_unreg_i2c:
-       zoran_unregister_i2c(zr);
+       zoran_i2c_exit(zr);
 zr_free_irq:
        btwrite(0, ZR36057_SPGPPCR);
        pci_free_irq(zr->pci_dev, 0, zr);
-- 
2.32.0



_______________________________________________
Mjpeg-users mailing list
Mjpeg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mjpeg-users

Reply via email to