In order to be able to create multiple devices, the device name needs to
be unique.

Allow to set it in the VKMS configuration.

Signed-off-by: José Expósito <jose.exposit...@gmail.com>
---
 drivers/gpu/drm/vkms/tests/vkms_config_test.c |  7 ++++++-
 drivers/gpu/drm/vkms/vkms_config.c            | 14 ++++++++++++--
 drivers/gpu/drm/vkms/vkms_config.h            | 15 ++++++++++++++-
 drivers/gpu/drm/vkms/vkms_drv.c               |  4 +++-
 drivers/gpu/drm/vkms/vkms_drv.h               |  2 ++
 5 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/vkms/tests/vkms_config_test.c 
b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
index d8644a1e3e18..526800b1afb4 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_config_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
@@ -15,10 +15,15 @@ struct default_config_case {
 static void vkms_config_test_empty_config(struct kunit *test)
 {
        struct vkms_config *config;
+       const char *dev_name = "test";
 
-       config = vkms_config_create();
+       config = vkms_config_create(dev_name);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config);
 
+       /* The dev_name string and the config have different live times */
+       dev_name = NULL;
+       KUNIT_EXPECT_STREQ(test, vkms_config_get_device_name(config), "test");
+
        vkms_config_destroy(config);
 }
 
diff --git a/drivers/gpu/drm/vkms/vkms_config.c 
b/drivers/gpu/drm/vkms/vkms_config.c
index 30ce4b23553f..11b0e539920b 100644
--- a/drivers/gpu/drm/vkms/vkms_config.c
+++ b/drivers/gpu/drm/vkms/vkms_config.c
@@ -7,7 +7,7 @@
 
 #include "vkms_config.h"
 
-struct vkms_config *vkms_config_create(void)
+struct vkms_config *vkms_config_create(const char *dev_name)
 {
        struct vkms_config *config;
 
@@ -15,6 +15,12 @@ struct vkms_config *vkms_config_create(void)
        if (!config)
                return ERR_PTR(-ENOMEM);
 
+       config->dev_name = kstrdup_const(dev_name, GFP_KERNEL);
+       if (!config->dev_name) {
+               kfree(config);
+               return ERR_PTR(-ENOMEM);
+       }
+
        return config;
 }
 
@@ -24,7 +30,7 @@ struct vkms_config *vkms_config_default_create(bool 
enable_cursor,
 {
        struct vkms_config *config;
 
-       config = vkms_config_create();
+       config = vkms_config_create(DEFAULT_DEVICE_NAME);
        if (IS_ERR(config))
                return config;
 
@@ -37,6 +43,7 @@ struct vkms_config *vkms_config_default_create(bool 
enable_cursor,
 
 void vkms_config_destroy(struct vkms_config *config)
 {
+       kfree_const(config->dev_name);
        kfree(config);
 }
 
@@ -45,7 +52,10 @@ static int vkms_config_show(struct seq_file *m, void *data)
        struct drm_debugfs_entry *entry = m->private;
        struct drm_device *dev = entry->dev;
        struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
+       const char *dev_name;
 
+       dev_name = vkms_config_get_device_name((struct vkms_config 
*)vkmsdev->config);
+       seq_printf(m, "dev_name=%s\n", dev_name);
        seq_printf(m, "writeback=%d\n", vkmsdev->config->writeback);
        seq_printf(m, "cursor=%d\n", vkmsdev->config->cursor);
        seq_printf(m, "overlay=%d\n", vkmsdev->config->overlay);
diff --git a/drivers/gpu/drm/vkms/vkms_config.h 
b/drivers/gpu/drm/vkms/vkms_config.h
index d0868750826a..3e4f39cbe2e2 100644
--- a/drivers/gpu/drm/vkms/vkms_config.h
+++ b/drivers/gpu/drm/vkms/vkms_config.h
@@ -10,12 +10,14 @@
 /**
  * struct vkms_config - General configuration for VKMS driver
  *
+ * @dev_name: Name of the device
  * @writeback: If true, a writeback buffer can be attached to the CRTC
  * @cursor: If true, a cursor plane is created in the VKMS device
  * @overlay: If true, NUM_OVERLAY_PLANES will be created for the VKMS device
  * @dev: Used to store the current VKMS device. Only set when the device is 
instantiated.
  */
 struct vkms_config {
+       const char *dev_name;
        bool writeback;
        bool cursor;
        bool overlay;
@@ -24,12 +26,13 @@ struct vkms_config {
 
 /**
  * vkms_config_create() - Create a new VKMS configuration
+ * @dev_name: Name of the device
  *
  * Returns:
  * The new vkms_config or an error. Call vkms_config_destroy() to free the
  * returned configuration.
  */
-struct vkms_config *vkms_config_create(void);
+struct vkms_config *vkms_config_create(const char *dev_name);
 
 /**
  * vkms_config_default_create() - Create the configuration for the default 
device
@@ -51,6 +54,16 @@ struct vkms_config *vkms_config_default_create(bool 
enable_cursor,
  */
 void vkms_config_destroy(struct vkms_config *config);
 
+/**
+ * vkms_config_get_device_name() - Return the name of the device
+ * @config: Configuration to get the device name from
+ */
+static inline const char *
+vkms_config_get_device_name(struct vkms_config *config)
+{
+       return config->dev_name;
+}
+
 /**
  * vkms_config_register_debugfs() - Register a debugfs file to show the 
device's
  * configuration
diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index 700cf43389b7..f23ee1a053e9 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -151,8 +151,10 @@ static int vkms_create(struct vkms_config *config)
        int ret;
        struct platform_device *pdev;
        struct vkms_device *vkms_device;
+       const char *dev_name;
 
-       pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
+       dev_name = vkms_config_get_device_name(config);
+       pdev = platform_device_register_simple(dev_name, -1, NULL, 0);
        if (IS_ERR(pdev))
                return PTR_ERR(pdev);
 
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index af7081c940d6..a74a7fc3a056 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -12,6 +12,8 @@
 #include <drm/drm_encoder.h>
 #include <drm/drm_writeback.h>
 
+#define DEFAULT_DEVICE_NAME "vkms"
+
 #define XRES_MIN    10
 #define YRES_MIN    10
 
-- 
2.48.1

Reply via email to