[PATCH] drm/amdgpu: Fix blocking in RCU critical section(v2)

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

 



Hi Alex,

On 20 July 2017 at 03:46, Alex Xie <AlexBin.Xie at amd.com> wrote:
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -198,12 +198,18 @@ amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id)
>         result = idr_find(&fpriv->bo_list_handles, id);
>
>         if (result) {
> -               if (kref_get_unless_zero(&result->refcount))
> +               if (kref_get_unless_zero(&result->refcount)) {
> +                       rcu_read_unlock();
>                         mutex_lock(&result->lock);
> -               else
> +               }
> +               else {
> +                       rcu_read_unlock();
>                         result = NULL;
> +               }
> +       }
> +       else {
> +               rcu_read_unlock();
>         }
> -       rcu_read_unlock();
>
>         return result;
A drive-by suggestion - feel free to ignore.

The "return early" approach seems great IMHO. The code will be
shorter, indentation - less, no {}/else to track plus overall it seems
clearer.
Namely:

   result = idr_find(&fpriv->bo_list_handles, id);

   if (!result || !kref_get_unless_zero(&result->refcount)) {
         rcu_read_unlock();
         return NULL;
   }

   rcu_read_unlock();
   mutex_lock(&result->lock);
   return result;
}

HTH
Emil


[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux