[media] media_device: move allocation out of media_device_*_init
authorMauro Carvalho Chehab <mchehab@osg.samsung.com>
Mon, 22 Feb 2016 15:10:49 +0000 (12:10 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Tue, 23 Feb 2016 10:19:39 +0000 (07:19 -0300)
Right now, media_device_pci_init and media_device_usb_init does
media_device allocation internaly. That preents its usage when
the media_device struct is embedded on some other structure.

Move memory allocation outside it, to make it more generic.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/media-device.c
drivers/media/pci/saa7134/saa7134-core.c
drivers/media/usb/au0828/au0828-core.c
drivers/media/usb/cx231xx/cx231xx-cards.c
drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
drivers/media/usb/dvb-usb/dvb-usb-dvb.c
drivers/media/usb/em28xx/em28xx-cards.c
drivers/media/usb/siano/smsusb.c
include/media/media-device.h

index fe376b6b5244f99be9ea3f750fab196523da138c..6613723f5eb8efc744ea6b7091e30f160a3e8bfc 100644 (file)
@@ -755,16 +755,11 @@ struct media_device *media_device_find_devres(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(media_device_find_devres);
 
-struct media_device *media_device_pci_init(struct pci_dev *pci_dev,
-                                          const char *name)
+void media_device_pci_init(struct media_device *mdev,
+                          struct pci_dev *pci_dev,
+                          const char *name)
 {
 #ifdef CONFIG_PCI
-       struct media_device *mdev;
-
-       mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
-       if (!mdev)
-               return NULL;
-
        mdev->dev = &pci_dev->dev;
 
        if (name)
@@ -780,25 +775,16 @@ struct media_device *media_device_pci_init(struct pci_dev *pci_dev,
        mdev->driver_version = LINUX_VERSION_CODE;
 
        media_device_init(mdev);
-
-       return mdev;
-#else
-       return NULL;
 #endif
 }
 EXPORT_SYMBOL_GPL(media_device_pci_init);
 
-struct media_device *__media_device_usb_init(struct usb_device *udev,
-                                            const char *board_name,
-                                            const char *driver_name)
+void __media_device_usb_init(struct media_device *mdev,
+                            struct usb_device *udev,
+                            const char *board_name,
+                            const char *driver_name)
 {
 #ifdef CONFIG_USB
-       struct media_device *mdev;
-
-       mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
-       if (!mdev)
-               return NULL;
-
        mdev->dev = &udev->dev;
 
        if (driver_name)
@@ -818,10 +804,6 @@ struct media_device *__media_device_usb_init(struct usb_device *udev,
        mdev->driver_version = LINUX_VERSION_CODE;
 
        media_device_init(mdev);
-
-       return mdev;
-#else
-       return NULL;
 #endif
 }
 EXPORT_SYMBOL_GPL(__media_device_usb_init);
index 8ae65bb320a3e36c8be24cc076d46d2b1a3b74ad..2e77a5a8011907468e3ee68524accdf0e03e5157 100644 (file)
@@ -1043,11 +1043,12 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
        sprintf(dev->name, "saa%x[%d]", pci_dev->device, dev->nr);
 
 #ifdef CONFIG_MEDIA_CONTROLLER
-       dev->media_dev = media_device_pci_init(pci_dev, dev->name);
+       dev->media_dev = kzalloc(sizeof(*dev->media_dev), GFP_KERNEL);
        if (!dev->media_dev) {
                err = -ENOMEM;
                goto fail0;
        }
+       media_device_pci_init(dev->media_dev, pci_dev, dev->name);
        dev->v4l2_dev.mdev = dev->media_dev;
 #endif
 
index cfcd08ec388f3c94f9117e74afd744ee5639d86b..5fea4adef90be7f5f93d2419c89b92d7aa8c58fe 100644 (file)
@@ -191,13 +191,15 @@ static int au0828_media_device_init(struct au0828_dev *dev,
 #ifdef CONFIG_MEDIA_CONTROLLER
        struct media_device *mdev;
 
-       if (!dev->board.name)
-               mdev = media_device_usb_init(udev, "unknown au0828");
-       else
-               mdev = media_device_usb_init(udev, dev->board.name);
+       mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
        if (!mdev)
                return -ENOMEM;
 
+       if (!dev->board.name)
+               media_device_usb_init(mdev, udev, "unknown au0828");
+       else
+               media_device_usb_init(mdev, udev, dev->board.name);
+
        dev->media_dev = mdev;
 #endif
        return 0;
index 29bd7536feedab2da17f66a132db2ab3e1ad6cb2..c63248a188239971f8670f8687d6bf328191b016 100644 (file)
@@ -1212,10 +1212,12 @@ static int cx231xx_media_device_init(struct cx231xx *dev,
 #ifdef CONFIG_MEDIA_CONTROLLER
        struct media_device *mdev;
 
-       mdev = media_device_usb_init(udev, dev->board.name);
+       mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
        if (!mdev)
                return -ENOMEM;
 
+       media_device_usb_init(mdev, udev, dev->board.name);
+
        dev->media_dev = mdev;
 #endif
        return 0;
index 58250250a4432bea642820e8278fcd081e0de278..3fbb2cd19f5e2a2e145d5d3860d3e5c04354b91c 100644 (file)
@@ -408,10 +408,12 @@ static int dvb_usbv2_media_device_init(struct dvb_usb_adapter *adap)
        struct dvb_usb_device *d = adap_to_d(adap);
        struct usb_device *udev = d->udev;
 
-       mdev = media_device_usb_init(udev, d->name);
+       mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
        if (!mdev)
                return -ENOMEM;
 
+       media_device_usb_init(mdev, udev, d->name);
+
        dvb_register_media_controller(&adap->dvb_adap, mdev);
 
        dev_info(&d->udev->dev, "media controller created\n");
index 7509408b0b8e36372c1756e59d6a1c86f2fa6999..6477b04e95c748cc1a538049950d7d79c45d5dd7 100644 (file)
@@ -103,7 +103,11 @@ static int dvb_usb_media_device_init(struct dvb_usb_adapter *adap)
        struct dvb_usb_device *d = adap->dev;
        struct usb_device *udev = d->udev;
 
-       mdev = media_device_usb_init(udev, d->desc->name);
+       mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
+       if (!mdev)
+               return -ENOMEM;
+
+       media_device_usb_init(mdev, udev, d->desc->name);
 
        dvb_register_media_controller(&adap->dvb_adap, mdev);
 
index 0bae263252535164e9aefe13c01eac760e20b2c6..1f4047b3f3f77cb351d54592cb8748b3748d5317 100644 (file)
@@ -3019,17 +3019,17 @@ static int em28xx_media_device_init(struct em28xx *dev,
 #ifdef CONFIG_MEDIA_CONTROLLER
        struct media_device *mdev;
 
-       if (udev->product) {
-               mdev = media_device_usb_init(udev, udev->product);
-       } else if (udev->manufacturer) {
-               mdev = media_device_usb_init(udev, udev->manufacturer);
-       } else {
-               mdev = media_device_usb_init(udev, dev->name);
-       }
-
+       mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
        if (!mdev)
                return -ENOMEM;
 
+       if (udev->product)
+               media_device_usb_init(mdev, udev, udev->product);
+       else if (udev->manufacturer)
+               media_device_usb_init(mdev, udev, udev->manufacturer);
+       else
+               media_device_usb_init(mdev, udev, dev->name);
+
        dev->media_dev = mdev;
 #endif
        return 0;
index 4a0def1e15287d3b8dfdfc31a5b455e04982bfad..c2e25876e93b266e6e450296e9f2510d18c95364 100644 (file)
@@ -367,10 +367,12 @@ static void *siano_media_device_register(struct smsusb_device_t *dev,
        struct sms_board *board = sms_get_board(board_id);
        int ret;
 
-       mdev = media_device_usb_init(udev, board->name);
+       mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
        if (!mdev)
                return NULL;
 
+       media_device_usb_init(mdev, udev, board->name);
+
        ret = media_device_register(mdev);
        if (ret) {
                media_device_cleanup(mdev);
index 2d144fed936e59b7dda12c8fcc1fcb6381c93f24..49dda6c7e6645bd39633e99253cece62c274eb81 100644 (file)
@@ -550,16 +550,19 @@ struct media_device *media_device_find_devres(struct device *dev);
  * media_device_pci_init() - create and initialize a
  *     struct &media_device from a PCI device.
  *
+ * @mdev:      pointer to struct &media_device
  * @pci_dev:   pointer to struct pci_dev
  * @name:      media device name. If %NULL, the routine will use the default
  *             name for the pci device, given by pci_name() macro.
  */
-struct media_device *media_device_pci_init(struct pci_dev *pci_dev,
-                                          const char *name);
+void media_device_pci_init(struct media_device *mdev,
+                          struct pci_dev *pci_dev,
+                          const char *name);
 /**
  * __media_device_usb_init() - create and initialize a
  *     struct &media_device from a PCI device.
  *
+ * @mdev:      pointer to struct &media_device
  * @udev:      pointer to struct usb_device
  * @board_name:        media device name. If %NULL, the routine will use the usb
  *             product name, if available.
@@ -570,9 +573,10 @@ struct media_device *media_device_pci_init(struct pci_dev *pci_dev,
  * NOTE: It is better to call media_device_usb_init() instead, as
  * such macro fills driver_name with %KBUILD_MODNAME.
  */
-struct media_device *__media_device_usb_init(struct usb_device *udev,
-                                            const char *board_name,
-                                            const char *driver_name);
+void __media_device_usb_init(struct media_device *mdev,
+                            struct usb_device *udev,
+                            const char *board_name,
+                            const char *driver_name);
 
 #else
 static inline int media_device_register(struct media_device *mdev)
@@ -599,24 +603,24 @@ static inline struct media_device *media_device_find_devres(struct device *dev)
        return NULL;
 }
 
-static inline
-struct media_device *media_device_pci_init(struct pci_dev *pci_dev,
-                                          char *name)
+static inline void media_device_pci_init(struct media_device *mdev,
+                                        struct pci_dev *pci_dev,
+                                        char *name)
 {
        return NULL;
 }
 
-static inline
-struct media_device *__media_device_usb_init(struct usb_device *udev,
-                                            char *board_name,
-                                            char *driver_name)
+static inline void __media_device_usb_init(struct media_device *mdev,
+                                          struct usb_device *udev,
+                                          char *board_name,
+                                          char *driver_name)
 {
        return NULL;
 }
 
 #endif /* CONFIG_MEDIA_CONTROLLER */
 
-#define media_device_usb_init(udev, name) \
-       __media_device_usb_init(udev, name, KBUILD_MODNAME)
+#define media_device_usb_init(mdev, udev, name) \
+       __media_device_usb_init(mdev, udev, name, KBUILD_MODNAME)
 
 #endif