Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6cf5dad1 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab
Browse files

[media] media_device: move allocation out of media_device_*_init



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: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 41b44e35
Loading
Loading
Loading
Loading
+7 −25
Original line number Diff line number Diff line
@@ -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,
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,
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);
+2 −1
Original line number Diff line number Diff line
@@ -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

+6 −4
Original line number Diff line number Diff line
@@ -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;
+3 −1
Original line number Diff line number Diff line
@@ -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;
+3 −1
Original line number Diff line number Diff line
@@ -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");
Loading