[Intel-gfx] [PATCH v6 1/7] drm/client: Do not acquire module reference
Thomas Zimmermann
tzimmermann at suse.de
Wed Nov 15 13:07:17 UTC 2023
Am 02.11.23 um 14:08 schrieb Thomas Zimmermann:
> Do not acquire a reference on the module that provides a client's
> callback functions in drm_client_init(). The additional reference
> prevents the user from unloading the callback functions' module and
> thus creating dangling pointers.
>
> This is only necessary if there is no direct dependency between the
> caller of drm_client_init() and the provider of the callbacks in
> struct drm_client_funcs. If this case ever existed, it has been
> removed from the DRM code. Callers of drm_client_init() also provide
> the callback implementation. The lifetime of the clients is tied to
> the dependency chain's outer-most module, which is the hardware's
> DRM driver. Before client helpers could be unloaded, the driver module
> would have to be unloaded, which also unregisters all clients.
>
> Driver modules that set up DRM clients can now be unloaded.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann at suse.de>
> Acked-by: Javier Martinez Canillas <javierm at redhat.com>
I've added this patch to drm-misc-next.
> ---
> drivers/gpu/drm/drm_client.c | 12 +-----------
> 1 file changed, 1 insertion(+), 11 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
> index c3027115d0552..9403b3f576f7b 100644
> --- a/drivers/gpu/drm/drm_client.c
> +++ b/drivers/gpu/drm/drm_client.c
> @@ -5,7 +5,6 @@
>
> #include <linux/iosys-map.h>
> #include <linux/list.h>
> -#include <linux/module.h>
> #include <linux/mutex.h>
> #include <linux/seq_file.h>
> #include <linux/slab.h>
> @@ -84,16 +83,13 @@ int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
> if (!drm_core_check_feature(dev, DRIVER_MODESET) || !dev->driver->dumb_create)
> return -EOPNOTSUPP;
>
> - if (funcs && !try_module_get(funcs->owner))
> - return -ENODEV;
> -
> client->dev = dev;
> client->name = name;
> client->funcs = funcs;
>
> ret = drm_client_modeset_create(client);
> if (ret)
> - goto err_put_module;
> + return ret;
>
> ret = drm_client_open(client);
> if (ret)
> @@ -105,10 +101,6 @@ int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
>
> err_free:
> drm_client_modeset_free(client);
> -err_put_module:
> - if (funcs)
> - module_put(funcs->owner);
> -
> return ret;
> }
> EXPORT_SYMBOL(drm_client_init);
> @@ -177,8 +169,6 @@ void drm_client_release(struct drm_client_dev *client)
> drm_client_modeset_free(client);
> drm_client_close(client);
> drm_dev_put(dev);
> - if (client->funcs)
> - module_put(client->funcs->owner);
> }
> EXPORT_SYMBOL(drm_client_release);
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/intel-gfx/attachments/20231115/e30a6e40/attachment.sig>
More information about the Intel-gfx
mailing list