Skip to contentSkip to conversation

drm/i915/gem: Use list_entry to access list members

PATCH In review Guenter Roeck 3 participants 3 messages May 23, 2021 – Jun 1, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/i915/gem: Use list_entry to access list members

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

---
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(-)
drivers/gpu/drm/i915/gvt/dmabuf.c +5 -13
index d4f883f35b95..e3f488681484 100644
@@ -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);
Signature · 6 lines
2.25.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

[Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915/gem: Use list_entry to access list members (rev2)

== Series Details ==

== Series Details ==

Series: drm/i915/gem: Use list_entry to access list members (rev2)
URL : https://patchwork.freedesktop.org/series/90449/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_10123 -> Patchwork_20177
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20177/index.html

Known issues
------------

Here are the changes found in Patchwork_20177 that come from known issues:

### IGT changes ###

#### Warnings ####

* igt@i915_selftest@live@execlists:
- fi-cfl-8109u: [DMESG-FAIL][1] ([i915#3462]) -> [INCOMPLETE][2] ([i915#3462])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10123/fi-cfl-8109u/igt@i915_selftest@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20177/fi-cfl-8109u/igt@i915_selftest@[email protected]
- fi-bsw-nick: [INCOMPLETE][3] ([i915#2782] / [i915#2940] / [i915#3462]) -> [DMESG-FAIL][4] ([i915#3462])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10123/fi-bsw-nick/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20177/fi-bsw-nick/igt@i915_selftest@[email protected]
- fi-bsw-kefka: [DMESG-FAIL][5] ([i915#3462]) -> [INCOMPLETE][6] ([i915#2782] / [i915#2940] / [i915#3462])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10123/fi-bsw-kefka/igt@i915_selftest@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20177/fi-bsw-kefka/igt@i915_selftest@[email protected]

* igt@runner@aborted:
- fi-bsw-kefka: [FAIL][7] ([i915#1436]) -> [FAIL][8] ([fdo#109271] / [i915#1436])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10123/fi-bsw-kefka/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20177/fi-bsw-kefka/igt@[email protected]
- fi-cfl-8109u: [FAIL][9] ([i915#2426] / [i915#3363]) -> [FAIL][10] ([i915#3363])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10123/fi-cfl-8109u/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20177/fi-cfl-8109u/igt@[email protected]
- fi-bsw-nick: [FAIL][11] ([i915#1436]) -> [FAIL][12] ([fdo#109271] / [i915#1436])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10123/fi-bsw-nick/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20177/fi-bsw-nick/igt@[email protected]
- fi-kbl-soraka: [FAIL][13] ([i915#1436] / [i915#3363]) -> [FAIL][14] ([i915#1436] / [i915#2426] / [i915#3363])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10123/fi-kbl-soraka/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20177/fi-kbl-soraka/igt@[email protected]
- fi-kbl-7567u: [FAIL][15] ([i915#1436] / [i915#3363]) -> [FAIL][16] ([i915#1436] / [i915#2426] / [i915#3363])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10123/fi-kbl-7567u/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20177/fi-kbl-7567u/igt@[email protected]

[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[i915#1436]: https://gitlab.freedesktop.org/drm/intel/issues/1436
[i915#2426]: https://gitlab.freedesktop.org/drm/intel/issues/2426
[i915#2782]: https://gitlab.freedesktop.org/drm/intel/issues/2782
[i915#2940]: https://gitlab.freedesktop.org/drm/intel/issues/2940
[i915#3363]: https://gitlab.freedesktop.org/drm/intel/issues/3363
[i915#3462]: https://gitlab.freedesktop.org/drm/intel/issues/3462

Participating hosts (42 -> 39)
------------------------------

Missing (3): fi-bsw-cyan fi-bdw-samus fi-hsw-4200u

Build changes
-------------

* Linux: CI_DRM_10123 -> Patchwork_20177

CI-20190529: 20190529
CI_DRM_10123: 6b2a86ddd31f336e2d0884889bd642650f1d805f @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_6092: d87087c321da07035d4f96d98c34e451b3ccb809 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_20177: 3fc93a4dedb1738f73c16ff301a6cc66a7412cbe @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

3fc93a4dedb1 drm/i915/gem: Use list_entry to access list members

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20177/index.html

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reviewed-by on v2 1/1
#2 lore raw
In reply to Guenter Roeck
Quoted 55 lines · 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().

---
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(-)
drivers/gpu/drm/i915/gvt/dmabuf.c +4 -11
index d4f883f35b95..e3f488681484 100644
@@ -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;

drivers/gpu/drm/i915/gvt/dmabuf.c void intel_vgpu_dmabuf_cleanup(struct intel_vgpu *vgpu) · line 599

Quoted 9 lines
drivers/gpu/drm/i915/gvt/dmabuf.c +1 -2
@@ -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.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx