dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drm/i915/gem: Use list_entry to access list members
@ 2021-05-23 17:23 Guenter Roeck
  2021-06-01  8:28 ` Zhenyu Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2021-05-23 17:23 UTC (permalink / raw)
  To: Zhenyu Wang
  Cc: David Airlie, intel-gfx, linux-kernel, dri-devel, intel-gvt-dev,
	Guenter Roeck

Use list_entry() instead of container_of() to access list members.
Also drop unnecessary and misleading NULL checks on the result of
list_entry().

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v2: Checkpatch fixes:
    - Fix alignment
    - Replace comparison against NULL with !

 drivers/gpu/drm/i915/gvt/dmabuf.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
index d4f883f35b95..e3f488681484 100644
--- a/drivers/gpu/drm/i915/gvt/dmabuf.c
+++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
@@ -148,8 +148,7 @@ static void dmabuf_gem_object_free(struct kref *kref)
 
 	if (vgpu && vgpu->active && !list_empty(&vgpu->dmabuf_obj_list_head)) {
 		list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
-			dmabuf_obj = container_of(pos,
-					struct intel_vgpu_dmabuf_obj, list);
+			dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
 			if (dmabuf_obj == obj) {
 				list_del(pos);
 				intel_gvt_hypervisor_put_vfio_device(vgpu);
@@ -357,10 +356,8 @@ pick_dmabuf_by_info(struct intel_vgpu *vgpu,
 	struct intel_vgpu_dmabuf_obj *ret = NULL;
 
 	list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
-		dmabuf_obj = container_of(pos, struct intel_vgpu_dmabuf_obj,
-						list);
-		if ((dmabuf_obj == NULL) ||
-		    (dmabuf_obj->info == NULL))
+		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
+		if (!dmabuf_obj->info)
 			continue;
 
 		fb_info = (struct intel_vgpu_fb_info *)dmabuf_obj->info;
@@ -387,11 +384,7 @@ pick_dmabuf_by_num(struct intel_vgpu *vgpu, u32 id)
 	struct intel_vgpu_dmabuf_obj *ret = NULL;
 
 	list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
-		dmabuf_obj = container_of(pos, struct intel_vgpu_dmabuf_obj,
-						list);
-		if (!dmabuf_obj)
-			continue;
-
+		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
 		if (dmabuf_obj->dmabuf_id == id) {
 			ret = dmabuf_obj;
 			break;
@@ -600,8 +593,7 @@ void intel_vgpu_dmabuf_cleanup(struct intel_vgpu *vgpu)
 
 	mutex_lock(&vgpu->dmabuf_lock);
 	list_for_each_safe(pos, n, &vgpu->dmabuf_obj_list_head) {
-		dmabuf_obj = container_of(pos, struct intel_vgpu_dmabuf_obj,
-						list);
+		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
 		dmabuf_obj->vgpu = NULL;
 
 		idr_remove(&vgpu->object_idr, dmabuf_obj->dmabuf_id);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] drm/i915/gem: Use list_entry to access list members
  2021-05-23 17:23 [PATCH v2] drm/i915/gem: Use list_entry to access list members Guenter Roeck
@ 2021-06-01  8:28 ` Zhenyu Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Zhenyu Wang @ 2021-06-01  8:28 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: David Airlie, intel-gfx, linux-kernel, dri-devel, intel-gvt-dev

[-- Attachment #1: Type: text/plain, Size: 2707 bytes --]

On 2021.05.23 10:23:04 -0700, Guenter Roeck wrote:
> Use list_entry() instead of container_of() to access list members.
> Also drop unnecessary and misleading NULL checks on the result of
> list_entry().
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> v2: Checkpatch fixes:
>     - Fix alignment
>     - Replace comparison against NULL with !
> 
>  drivers/gpu/drm/i915/gvt/dmabuf.c | 18 +++++-------------
>  1 file changed, 5 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
> index d4f883f35b95..e3f488681484 100644
> --- a/drivers/gpu/drm/i915/gvt/dmabuf.c
> +++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
> @@ -148,8 +148,7 @@ static void dmabuf_gem_object_free(struct kref *kref)
>  
>  	if (vgpu && vgpu->active && !list_empty(&vgpu->dmabuf_obj_list_head)) {
>  		list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
> -			dmabuf_obj = container_of(pos,
> -					struct intel_vgpu_dmabuf_obj, list);
> +			dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
>  			if (dmabuf_obj == obj) {
>  				list_del(pos);
>  				intel_gvt_hypervisor_put_vfio_device(vgpu);
> @@ -357,10 +356,8 @@ pick_dmabuf_by_info(struct intel_vgpu *vgpu,
>  	struct intel_vgpu_dmabuf_obj *ret = NULL;
>  
>  	list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
> -		dmabuf_obj = container_of(pos, struct intel_vgpu_dmabuf_obj,
> -						list);
> -		if ((dmabuf_obj == NULL) ||
> -		    (dmabuf_obj->info == NULL))
> +		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
> +		if (!dmabuf_obj->info)
>  			continue;
>  
>  		fb_info = (struct intel_vgpu_fb_info *)dmabuf_obj->info;
> @@ -387,11 +384,7 @@ pick_dmabuf_by_num(struct intel_vgpu *vgpu, u32 id)
>  	struct intel_vgpu_dmabuf_obj *ret = NULL;
>  
>  	list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
> -		dmabuf_obj = container_of(pos, struct intel_vgpu_dmabuf_obj,
> -						list);
> -		if (!dmabuf_obj)
> -			continue;
> -
> +		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
>  		if (dmabuf_obj->dmabuf_id == id) {
>  			ret = dmabuf_obj;
>  			break;
> @@ -600,8 +593,7 @@ void intel_vgpu_dmabuf_cleanup(struct intel_vgpu *vgpu)
>  
>  	mutex_lock(&vgpu->dmabuf_lock);
>  	list_for_each_safe(pos, n, &vgpu->dmabuf_obj_list_head) {
> -		dmabuf_obj = container_of(pos, struct intel_vgpu_dmabuf_obj,
> -						list);
> +		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
>  		dmabuf_obj->vgpu = NULL;
>  
>  		idr_remove(&vgpu->object_idr, dmabuf_obj->dmabuf_id);
> -- 

Sorry for late reply! Looks good to me.

Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-01  8:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-23 17:23 [PATCH v2] drm/i915/gem: Use list_entry to access list members Guenter Roeck
2021-06-01  8:28 ` Zhenyu Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).