Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/xe/xe_gt: Guard against fopen failure in xe_gt_stats_get_count
@ 2024-12-03 20:26 Jonathan Cavitt
  2024-12-03 22:23 ` ✓ i915.CI.BAT: success for " Patchwork
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Jonathan Cavitt @ 2024-12-03 20:26 UTC (permalink / raw)
  To: igt-dev; +Cc: jonathan.cavitt, saurabhg.gupta, alex.zuo, sai.gowtham.ch

The function xe_gt_stats_get_count currently performs an fopen on the
/sys/kernel/debug/dri/0/gt*/stats directory without checking that the
fopen is successful.  This can cause a system crash when trying to
perform fgets on a NULL pointer on unsuccessful cases.

Check the results of fopen and guard against this.

Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/3212
Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
---
 lib/xe/xe_gt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/xe/xe_gt.c b/lib/xe/xe_gt.c
index cee892af96..101b887a41 100644
--- a/lib/xe/xe_gt.c
+++ b/lib/xe/xe_gt.c
@@ -159,6 +159,8 @@ int xe_gt_stats_get_count(int fd, int gt, const char *stat)
 	sprintf(path, "/sys/kernel/debug/dri/0/gt%d/stats", gt);
 	f = fopen(path, "r");
 
+	igt_assert_f(f, "Failed to open /sys/kernel/debug/dri/0/gt%d/stats", gt);
+
 	while (fgets(tlb_path, sizeof(tlb_path), f)) {
 		if (strstr(tlb_path, stat) != NULL) {
 			sscanf(tlb_path, "%*[^:]: %d", &count);
-- 
2.43.0


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

end of thread, other threads:[~2024-12-04 15:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-03 20:26 [PATCH] lib/xe/xe_gt: Guard against fopen failure in xe_gt_stats_get_count Jonathan Cavitt
2024-12-03 22:23 ` ✓ i915.CI.BAT: success for " Patchwork
2024-12-03 22:43 ` ✓ Xe.CI.BAT: " Patchwork
2024-12-03 23:47 ` ✗ Xe.CI.Full: failure " Patchwork
2024-12-04 15:00   ` Cavitt, Jonathan
2024-12-03 23:48 ` ✗ i915.CI.Full: " Patchwork
2024-12-04 15:00   ` Cavitt, Jonathan
2024-12-04 12:51 ` [PATCH] " Kamil Konieczny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox