Skip to contentSkip to conversation

drm/xe: make kobject type struct as constant

PATCH In review Tejas Upadhyay 4 participants 8 messages Jul 3, 2023 – Jul 4, 2023

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

PATCH 1/2 drm/xe: make kobject type struct as constant

Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") the driver core allows the usage of const struct kobj_type.

Take advantage of this to constify the structure definition to prevent modification at runtime.

---
 drivers/gpu/drm/xe/xe_gt_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_gt_sysfs.c +1 -1
index 13570987a756..2c47059bef42 100644
@@ -17,7 +17,7 @@ static void xe_gt_sysfs_kobj_release(struct kobject *kobj)
 	kfree(kobj);
 }
 
-static struct kobj_type xe_gt_sysfs_kobj_type = {
+static const struct kobj_type xe_gt_sysfs_kobj_type = {
 	.release = xe_gt_sysfs_kobj_release,
 	.sysfs_ops = &kobj_sysfs_ops,
 };
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 drm/xe: make GT sysfs init return void

As we dont use return from xe_gt_sysfs_init, we should make it return void to make it proper return type.

---
 drivers/gpu/drm/xe/xe_gt_sysfs.c | 10 ++++------
 drivers/gpu/drm/xe/xe_gt_sysfs.h |  2 +-
 2 files changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_gt_sysfs.c +4 -6
index 2c47059bef42..4ecbd972e6a1 100644
@@ -29,7 +29,7 @@ static void gt_sysfs_fini(struct drm_device *drm, void *arg)
 	kobject_put(gt->sysfs);
 }
 
-int xe_gt_sysfs_init(struct xe_gt *gt)
+void xe_gt_sysfs_init(struct xe_gt *gt)
 {
 	struct xe_tile *tile = gt_to_tile(gt);
 	struct kobj_gt *kg;
@@ -37,7 +37,7 @@ int xe_gt_sysfs_init(struct xe_gt *gt)
 
 	kg = kzalloc(sizeof(*kg), GFP_KERNEL);
 	if (!kg)
-		return -ENOMEM;
+		return;
 
 	kobject_init(&kg->base, &xe_gt_sysfs_kobj_type);
 	kg->gt = gt;
@@ -45,14 +45,12 @@ int xe_gt_sysfs_init(struct xe_gt *gt)
 	err = kobject_add(&kg->base, tile->sysfs, "gt%d", gt->info.id);
 	if (err) {
 		kobject_put(&kg->base);
-		return err;
+		return;
 	}
 
 	gt->sysfs = &kg->base;
 
 	err = drmm_add_action_or_reset(&gt_to_xe(gt)->drm, gt_sysfs_fini, gt);
 	if (err)
-		return err;
-
-	return 0;
+		return;
 }
drivers/gpu/drm/xe/xe_gt_sysfs.h +1 -1
index ecbfcc5c7d42..e3ec278ca0be 100644
@@ -8,7 +8,7 @@
 
 #include "xe_gt_sysfs_types.h"
 
-int xe_gt_sysfs_init(struct xe_gt *gt);
+void xe_gt_sysfs_init(struct xe_gt *gt);
 
 static inline struct xe_gt *
 kobj_to_gt(struct kobject *kobj)
Signature · 1 line
2.25.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [Intel-xe] [PATCH 2/2] drm/xe: make GT sysfs init return void

Quoted 3 lines · Tejas Upadhyay

As we dont use return from xe_gt_sysfs_init, we should make it return void to make it proper return type.

May be "Currently return from xe_gt_sysfs_init() is ignored and also

 a failure in xe_gt_sysfs_init() isn't fatal so make it return void. "

Quoted 2 lines

otherwise

Quoted 57 lines
---
  drivers/gpu/drm/xe/xe_gt_sysfs.c | 10 ++++------
  drivers/gpu/drm/xe/xe_gt_sysfs.h |  2 +-
  2 files changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_gt_sysfs.c +4 -6
index 2c47059bef42..4ecbd972e6a1 100644
@@ -29,7 +29,7 @@ static void gt_sysfs_fini(struct drm_device *drm, void *arg)
  	kobject_put(gt->sysfs);
  }
 
-int xe_gt_sysfs_init(struct xe_gt *gt)
+void xe_gt_sysfs_init(struct xe_gt *gt)
  {
  	struct xe_tile *tile = gt_to_tile(gt);
  	struct kobj_gt *kg;
@@ -37,7 +37,7 @@ int xe_gt_sysfs_init(struct xe_gt *gt)
 
  	kg = kzalloc(sizeof(*kg), GFP_KERNEL);
  	if (!kg)
-		return -ENOMEM;
+		return;
 
  	kobject_init(&kg->base, &xe_gt_sysfs_kobj_type);
  	kg->gt = gt;
@@ -45,14 +45,12 @@ int xe_gt_sysfs_init(struct xe_gt *gt)
  	err = kobject_add(&kg->base, tile->sysfs, "gt%d", gt->info.id);
  	if (err) {
  		kobject_put(&kg->base);
-		return err;
+		return;
  	}
 
  	gt->sysfs = &kg->base;
 
  	err = drmm_add_action_or_reset(&gt_to_xe(gt)->drm, gt_sysfs_fini, gt);
  	if (err)
-		return err;
-
-	return 0;
+		return;
  }
drivers/gpu/drm/xe/xe_gt_sysfs.h +1 -1
index ecbfcc5c7d42..e3ec278ca0be 100644
@@ -8,7 +8,7 @@
 
  #include "xe_gt_sysfs_types.h"
 
-int xe_gt_sysfs_init(struct xe_gt *gt);
+void xe_gt_sysfs_init(struct xe_gt *gt);
 
  static inline struct xe_gt *
  kobj_to_gt(struct kobject *kobj)
Reviewed-by on v1 2/2
#3 lore raw

Re: [Intel-xe] [PATCH 2/2] drm/xe: make GT sysfs init return void

In reply to Tejas Upadhyay

Hi Tejas,

Quoted 9 lines

-----Original Message-----
From: Intel-xe <[email protected]> On Behalf Of Tejas Upadhyay
Sent: 03 July 2023 14:50
To: [email protected]
Subject: [Intel-xe] [PATCH 2/2] drm/xe: make GT sysfs init return void

As we dont use return from xe_gt_sysfs_init, we should make it return void to make it proper return type.

In case of failures add drm_warn with possible reasons explore strerror. Don't return silently.

With above changes LGTM.

BR
Himal

Quoted 23 lines
---
 drivers/gpu/drm/xe/xe_gt_sysfs.c | 10 ++++------
drivers/gpu/drm/xe/xe_gt_sysfs.h |  2 +-
 2 files changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_gt_sysfs.c +1 -1
index 2c47059bef42..4ecbd972e6a1 100644
@@ -29,7 +29,7 @@ static void gt_sysfs_fini(struct drm_device *drm, void
 *arg)
 	kobject_put(gt->sysfs);
 }
 
-int xe_gt_sysfs_init(struct xe_gt *gt)
+void xe_gt_sysfs_init(struct xe_gt *gt)
 {
 	struct xe_tile *tile = gt_to_tile(gt);
drivers/gpu/drm/xe/xe_gt_sysfs.c +0 -0
 	struct kobj_gt *kg;

drivers/gpu/drm/xe/xe_gt_sysfs.c int xe_gt_sysfs_init(struct xe_gt *gt) · line 40

Quoted 4 lines
drivers/gpu/drm/xe/xe_gt_sysfs.c +0 -1
@@ -37,7 +37,7 @@ int xe_gt_sysfs_init(struct xe_gt *gt)
 
 	kg = kzalloc(sizeof(*kg), GFP_KERNEL);
 	if (!kg)
-		return -ENOMEM;

drm_warn due to OOM.

Quoted 38 lines
drivers/gpu/drm/xe/xe_gt_sysfs.c +3 -4
+		return;
 
 	kobject_init(&kg->base, &xe_gt_sysfs_kobj_type);
 	kg->gt = gt;
@@ -45,14 +45,12 @@ int xe_gt_sysfs_init(struct xe_gt *gt)
 	err = kobject_add(&kg->base, tile->sysfs, "gt%d", gt->info.id);
 	if (err) {
 		kobject_put(&kg->base);
-		return err;
+		return;
 	}
 
 	gt->sysfs = &kg->base;
 
 	err = drmm_add_action_or_reset(&gt_to_xe(gt)->drm,
 gt_sysfs_fini, gt);
 	if (err)
-		return err;
-
-	return 0;
+		return;

}

drivers/gpu/drm/xe/xe_gt_sysfs.h +1 -2
index ecbfcc5c7d42..e3ec278ca0be 100644
@@ -8,7 +8,7 @@
 
 #include "xe_gt_sysfs_types.h"
 
-int xe_gt_sysfs_init(struct xe_gt *gt);
+void xe_gt_sysfs_init(struct xe_gt *gt);
 
 static inline struct xe_gt *
 kobj_to_gt(struct kobject *kobj)
--

2.25.1

#4 lore raw

[Intel-xe] ✓ CI.Patch_applied: success for series starting with [1/2] drm/xe: make kobject type struct as constant

In reply to Tejas Upadhyay
== Series Details ==

== Series Details ==

Series: series starting with [1/2] drm/xe: make kobject type struct as constant
URL : https://patchwork.freedesktop.org/series/120132/
State : success

== Summary ==

=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: 53bd6056f drm/xe/display: Append dma_buf fences to framebuffer fences === git am output follows ===
Applying: drm/xe: make kobject type struct as constant
Applying: drm/xe: make GT sysfs init return void

#5 lore raw

[Intel-xe] ✗ CI.checkpatch: warning for series starting with [1/2] drm/xe: make kobject type struct as constant

In reply to Tejas Upadhyay
== Series Details ==

== Series Details ==

Series: series starting with [1/2] drm/xe: make kobject type struct as constant
URL : https://patchwork.freedesktop.org/series/120132/
State : warning

== Summary ==

+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master c7d32770e3cd31d9fc134ce41f329b10aa33ee15
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 1baaac2f94df50397700631e7813602d02dd1706

Author: Tejas Upadhyay <[email protected]>
Date:   Mon Jul 3 14:49:33 2023 +0530

drm/xe: make GT sysfs init return void

As we dont use return from xe_gt_sysfs_init, we should make it return void to make it proper return type.

+ /mt/dim checkpatch 53bd6056f6ec9a4f6c341d4f24122ede47a43de9 drm-intel 42acafd24 drm/xe: make kobject type struct as constant
-:6: WARNING:UNKNOWN_COMMIT_ID: Unknown commit id 'ee6d3dd4ed48', maybe rebased or not pulled? #6:
Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.")

total: 0 errors, 1 warnings, 0 checks, 8 lines checked 1baaac2f9 drm/xe: make GT sysfs init return void

#6 lore raw

[Intel-xe] ✗ CI.KUnit: failure for series starting with [1/2] drm/xe: make kobject type struct as constant

In reply to Tejas Upadhyay
== Series Details ==

== Series Details ==

Series: series starting with [1/2] drm/xe: make kobject type struct as constant
URL : https://patchwork.freedesktop.org/series/120132/
State : failure

== Summary ==

+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig Traceback (most recent call last):
File "/kernel/tools/testing/kunit/kunit.py", line 24, in <module>
import kunit_kernel
File "/kernel/tools/testing/kunit/kunit_kernel.py", line 42, in <module>
class LinuxSourceTreeOperations:
File "/kernel/tools/testing/kunit/kunit_kernel.py", line 95, in LinuxSourceTreeOperations

    def start(self, params: List[str], build_dir: str) -> subprocess.Popen[str]:

TypeError: 'type' object is not subscriptable
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel

Reviewed-by on v1 1/2
#7 lore raw
In reply to Tejas Upadhyay
Quoted 7 lines · Tejas Upadhyay

Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") the driver core allows the usage of const struct kobj_type.

Take advantage of this to constify the structure definition to prevent modification at runtime.

Quoted 17 lines
---
  drivers/gpu/drm/xe/xe_gt_sysfs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_gt_sysfs.c +1 -1
index 13570987a756..2c47059bef42 100644
@@ -17,7 +17,7 @@ static void xe_gt_sysfs_kobj_release(struct kobject *kobj)
  	kfree(kobj);
  }
 
-static struct kobj_type xe_gt_sysfs_kobj_type = {
+static const struct kobj_type xe_gt_sysfs_kobj_type = {
  	.release = xe_gt_sysfs_kobj_release,
  	.sysfs_ops = &kobj_sysfs_ops,
  };