drm/gud: Free buffers on device removal

Free transfer and compression buffers on device removal instead of at
DRM device removal time. This ensures that the usual 2x8MB buffers are
released when the device is unplugged and not kept around should
userspace keep the DRM device fd open.

At least Ubuntu 20.04 doesn't release the DRM device on unplug.

The damage_lock mutex is not destroyed because it is used outside the
drm_dev_enter/exit block in gud_pipe_update(). AFAICT it's possible for
an open fbdev descriptor to trigger a commit after the USB device is gone.

v2: Don't destroy damage_lock

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20210701170748.58009-1-noralf@tronnes.org
This commit is contained in:
Noralf Trønnes 2021-07-01 19:07:47 +02:00
parent 39a364a19e
commit f8ac863b6a

View File

@ -393,14 +393,15 @@ static const struct drm_driver gud_drm_driver = {
.minor = 0,
};
static void gud_free_buffers_and_mutex(struct drm_device *drm, void *unused)
static void gud_free_buffers_and_mutex(void *data)
{
struct gud_device *gdrm = to_gud_device(drm);
struct gud_device *gdrm = data;
vfree(gdrm->compress_buf);
gdrm->compress_buf = NULL;
kfree(gdrm->bulk_buf);
gdrm->bulk_buf = NULL;
mutex_destroy(&gdrm->ctrl_lock);
mutex_destroy(&gdrm->damage_lock);
}
static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)
@ -454,7 +455,7 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)
INIT_WORK(&gdrm->work, gud_flush_work);
gud_clear_damage(gdrm);
ret = drmm_add_action_or_reset(drm, gud_free_buffers_and_mutex, NULL);
ret = devm_add_action(dev, gud_free_buffers_and_mutex, gdrm);
if (ret)
return ret;