drm/udl: Fix inconsistent urbs.count value during udl_free_urb_list()
authorTakashi Iwai <tiwai@suse.de>
Thu, 8 Sep 2022 09:51:13 +0000 (11:51 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Sat, 10 Sep 2022 19:45:52 +0000 (21:45 +0200)
commitc5c354a3a4728045e1342166394c615d75d45377
tree21028e170a6dd96f1ae4eec9375a559f1766bb8d
parent046f4f0af7fd1fad06793d863d288c6b2cd84e99
drm/udl: Fix inconsistent urbs.count value during udl_free_urb_list()

In the current design, udl_get_urb() may be called asynchronously
during the driver freeing its URL list via udl_free_urb_list().
The problem is that the sync is determined by comparing the urbs.count
and urbs.available fields, while we clear urbs.count field only once
after udl_free_urb_list() finishes, i.e. during udl_free_urb_list(),
the state becomes inconsistent.

For fixing this inconsistency and also for hardening the locking
scheme, this patch does a slight refactoring of the code around
udl_get_urb() and udl_free_urb_list().  Now urbs.count is updated in
the same spinlock at extracting a URB from the list in
udl_free_url_list().

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20220908095115.23396-11-tiwai@suse.de
drivers/gpu/drm/udl/udl_drv.h
drivers/gpu/drm/udl/udl_main.c