Re: [PATCH] kunit: Make kunit_remove_resource() idempotent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 18, 2022 at 2:50 AM David Gow <davidgow@xxxxxxxxxx> wrote:
>
> The kunit_remove_resource() function is used to unlink a resource from
> the list of resources in the test, making it no longer show up in
> kunit_find_resource().
>
> However, this could lead to a race condition if two threads called
> kunit_remove_resource() on the same resource at the same time: the
> resource would be removed from the list twice (causing a crash at the
> second list_del()), and the refcount for the resource would be
> decremented twice (instead of once, for the reference held by the
> resource list).
>
> Fix both problems, the first by using list_del_init(), and the second by
> checking if the resource has already been removed using list_empty(),
> and only decrementing its refcount if it has not.
>
> Also add a KUnit test for the kunit_remove_resource() function which
> tests this behaviour.
>
> Reported-by: Daniel Latypov <dlatypov@xxxxxxxxxx>
> Signed-off-by: David Gow <davidgow@xxxxxxxxxx>

Reviewed-by: Brendan Higgins <brendanhiggins@xxxxxxxxxx>



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux