<p dir="ltr">Hi, Chris</p>
<p dir="ltr">See comment below</p>
<p dir="ltr">BR<br>
Nils<br>
On 27 May 2016 7:01 a.m., "Chris Wilson" <<a href="mailto:chris@chris-wilson.co.uk">chris@chris-wilson.co.uk</a>> wrote:<br>
><br>
> In order to allow drivers to pack their privates and drm_device into one<br>
> struct (e.g. for subclassing), export the initialisation routines for<br>
> struct drm_device.<br>
><br>
> Signed-off-by: Chris Wilson <<a href="mailto:chris@chris-wilson.co.uk">chris@chris-wilson.co.uk</a>><br>
> Cc: Daniel Vetter <<a href="mailto:daniel.vetter@ffwll.ch">daniel.vetter@ffwll.ch</a>><br>
> Cc: <a href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.org</a><br>
> ---<br>
>  drivers/gpu/drm/drm_drv.c | 63 ++++++++++++++++++++++++++++++++++++-----------<br>
>  include/drm/drmP.h        |  3 +++<br>
>  2 files changed, 52 insertions(+), 14 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c<br>
> index bff89226a344..ceb85e611a07 100644<br>
> --- a/drivers/gpu/drm/drm_drv.c<br>
> +++ b/drivers/gpu/drm/drm_drv.c<br>
> @@ -549,11 +549,12 @@ static void drm_fs_inode_free(struct inode *inode)<br>
>  }<br>
><br>
>  /**<br>
> - * drm_dev_alloc - Allocate new DRM device<br>
> - * @driver: DRM driver to allocate device for<br>
> + * drm_dev_init - Initialise new DRM device<br>
> + * @dev: DRM device<br>
> + * @driver: DRM driver<br>
>   * @parent: Parent device object<br>
>   *<br>
> - * Allocate and initialize a new DRM device. No device registration is done.<br>
> + * Initialize a new DRM device. No device registration is done.<br>
>   * Call drm_dev_register() to advertice the device to user space and register it<br>
>   * with other core subsystems. This should be done last in the device<br>
>   * initialization sequence to make sure userspace can't access an inconsistent<br>
> @@ -565,18 +566,14 @@ static void drm_fs_inode_free(struct inode *inode)<br>
>   * Note that for purely virtual devices @parent can be NULL.<br>
>   *<br>
>   * RETURNS:<br>
> - * Pointer to new DRM device, or NULL if out of memory.<br>
> + * 0 on success, or error code on failure.<br>
>   */<br>
> -struct drm_device *drm_dev_alloc(struct drm_driver *driver,<br>
> -                                struct device *parent)<br>
> +int drm_dev_init(struct drm_device *dev,<br>
> +                struct drm_driver *driver,<br>
> +                struct device *parent)<br>
>  {<br>
> -       struct drm_device *dev;<br>
>         int ret;<br>
><br>
> -       dev = kzalloc(sizeof(*dev), GFP_KERNEL);<br>
> -       if (!dev)<br>
> -               return NULL;<br>
> -<br>
>         kref_init(&dev->ref);<br>
>         dev->dev = parent;<br>
>         dev->driver = driver;<br>
> @@ -638,7 +635,7 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,<br>
>                         goto err_setunique;<br>
>         }<br>
><br>
> -       return dev;<br>
> +       return 0;<br>
><br>
>  err_setunique:<br>
>         if (drm_core_check_feature(dev, DRIVER_GEM))<br>
> @@ -653,8 +650,46 @@ err_minors:<br>
>         drm_fs_inode_free(dev->anon_inode);<br>
>  err_free:<br>
>         mutex_destroy(&dev->master_mutex);<br>
> -       kfree(dev);<br>
> -       return NULL;<br>
> +       return 0;</p>
<p dir="ltr">Shouldn't this return != 0?</p>
<p dir="ltr">> +}<br>
> +EXPORT_SYMBOL(drm_dev_init);<br>
> +<br>
> +/**<br>
> + * drm_dev_alloc - Allocate new DRM device<br>
> + * @driver: DRM driver to allocate device for<br>
> + * @parent: Parent device object<br>
> + *<br>
> + * Allocate and initialize a new DRM device. No device registration is done.<br>
> + * Call drm_dev_register() to advertice the device to user space and register it<br>
> + * with other core subsystems. This should be done last in the device<br>
> + * initialization sequence to make sure userspace can't access an inconsistent<br>
> + * state.<br>
> + *<br>
> + * The initial ref-count of the object is 1. Use drm_dev_ref() and<br>
> + * drm_dev_unref() to take and drop further ref-counts.<br>
> + *<br>
> + * Note that for purely virtual devices @parent can be NULL.<br>
> + *<br>
> + * RETURNS:<br>
> + * Pointer to new DRM device, or NULL if out of memory.<br>
> + */<br>
> +struct drm_device *drm_dev_alloc(struct drm_driver *driver,<br>
> +                                struct device *parent)<br>
> +{<br>
> +       struct drm_device *dev;<br>
> +       int ret;<br>
> +<br>
> +       dev = kzalloc(sizeof(*dev), GFP_KERNEL);<br>
> +       if (!dev)<br>
> +               return NULL;<br>
> +<br>
> +       ret = drm_dev_init(dev, driver, parent);<br>
> +       if (ret) {<br>
> +               kfree(dev);<br>
> +               return NULL;<br>
> +       }<br>
> +<br>
> +       return dev;<br>
>  }<br>
>  EXPORT_SYMBOL(drm_dev_alloc);<br>
><br>
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h<br>
> index c5d29505f937..12dc5f9cad89 100644<br>
> --- a/include/drm/drmP.h<br>
> +++ b/include/drm/drmP.h<br>
> @@ -1075,6 +1075,9 @@ extern void drm_sysfs_hotplug_event(struct drm_device *dev);<br>
><br>
>  struct drm_device *drm_dev_alloc(struct drm_driver *driver,<br>
>                                  struct device *parent);<br>
> +int drm_dev_init(struct drm_device *dev,<br>
> +                struct drm_driver *driver,<br>
> +                struct device *parent);<br>
>  void drm_dev_ref(struct drm_device *dev);<br>
>  void drm_dev_unref(struct drm_device *dev);<br>
>  int drm_dev_register(struct drm_device *dev, unsigned long flags);<br>
> --<br>
> 2.8.1<br>
><br>
> _______________________________________________<br>
> dri-devel mailing list<br>
> <a href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel">https://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br>
</p>