@@ -686,6 +686,21 @@ void media_device_init(struct media_device *mdev)
}
EXPORT_SYMBOL_GPL(media_device_init);
+struct media_device *media_device_alloc(struct device *dev)
+{
+ struct media_device *mdev;
+
+ mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
+ if (!mdev)
+ return NULL;
+
+ mdev->dev = dev;
+ media_device_init(mdev);
+
+ return mdev;
+}
+EXPORT_SYMBOL_GPL(media_device_alloc);
+
void media_device_cleanup(struct media_device *mdev)
{
ida_destroy(&mdev->entity_internal_idx);
@@ -197,6 +197,15 @@ static inline __must_check int media_entity_enum_init(
void media_device_init(struct media_device *mdev);
/**
+ * media_device_alloc() - Allocate and initialise a media device
+ *
+ * @dev: The associated struct device pointer
+ *
+ * Allocate and initialise a media device. Returns a media device.
+ */
+struct media_device *media_device_alloc(struct device *dev);
+
+/**
* media_device_cleanup() - Cleanups a media device element
*
* @mdev: pointer to struct &media_device
@@ -425,6 +434,10 @@ void __media_device_usb_init(struct media_device *mdev,
const char *driver_name);
#else
+static inline struct media_device *media_device_alloc(struct device *dev)
+{
+ return NULL;
+}
static inline int media_device_register(struct media_device *mdev)
{
return 0;