[Bug 267606] x11-drivers/xf86-video-nv: Segmentation Fault post update from 1.20.14,1 to 21.1.4

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 30 Jan 2024 08:06:27 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=267606

--- Comment #49 from Yusuf Khan <yusisamerican@gmail.com> ---
(In reply to Sergiy from comment #48)
I think I will have to work on it myself on hardware as I dont have enough X
knowledge to do this without a high amount of trial and error. Your OpenBSD
logs are showing that your pruning more than just bad panel dimensions(which I
probably should have expected), so the small hack job diff I sent you last time
wont work.

As you seem to have emptied your OpenBSD drive, I have a diff that is simply
just what the intel driver uses to do it but its *simply copied code from the
intel driver* and is by *no means recommended to use on your computer* due to
my inexperience with X. I will hopefully get hardware to test this later on and
fix it up.

The bellow is a diff that should, if the above warnings are read, be run
without any other modifications to mode validation.

From 6f0ec68b9fc4c0f062e483a96665fbcb378408ea Mon Sep 17 00:00:00 2001
From: Yusuf Khan <yusisamerican@gmail.com>
Date: Mon, 29 Jan 2024 23:52:34 -0800
Subject: [PATCH xf86-video-nv] Intel import fix

---
 src/nv_driver.c | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/src/nv_driver.c b/src/nv_driver.c
index 134da6a..6c40ebe 100644
--- a/src/nv_driver.c
+++ b/src/nv_driver.c
@@ -1976,14 +1976,39 @@ NVPreInit(ScrnInfoPtr pScrn, int flags)
         if (i > 0)
             VBESetModeParameters(pScrn, pNv->pVbe);
     } else {
-        i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
-                              pScrn->display->modes, clockRanges,
-                              NULL, 256, max_width,
-                              512, 128, max_height,
-                              pScrn->display->virtualX,
-                              pScrn->display->virtualY,
-                              pNv->ScratchBufferStart,
-                              LOOKUP_BEST_REFRESH);
+        DisplayModePtr i, m, p = NULL;
+       int max_x = 0, max_y = 0;
+        float max_vrefresh = 0.0;
+
+       for (m = pScrn->monitor->Modes; m; m = m->next) {
+               if (m->type & M_T_PREFERRED)
+                        p = m;
+               max_x = max(max_x, m->HDisplay);
+               max_y = max(max_y, m->VDisplay);
+               max_vrefresh = max(max_vrefresh, xf86ModeVRefresh(m));
+         }
+
+         max_vrefresh = max(max_vrefresh, 60.0);
+         max_vrefresh *= (1 + SYNC_TOLERANCE);
+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,6,99,0,0)
+        pScrn->modePool = xf86GetDefaultModes();
+#else
+        pScrn->modePool = xf86GetDefaultModes(0,0);
+#endif
+       xf86ValidateModesSize(pScrn, pScrn->modePool, max_width, max_height,
0);
+
+        for (i = m; i; i = i->next) {
+               if (xf86ModeVRefresh(i) > max_vrefresh)
+                       i->status = MODE_VSYNC;
+               if (p && i->HDisplay >= p->HDisplay &&
+                    i->VDisplay >= p->VDisplay &&
+                    xf86ModeVRefresh(i) >= xf86ModeVRefresh(p))
+                        i->status = MODE_VSYNC;
+        }
+
+        xf86PruneInvalidModes(pScrn, &m, FALSE);
+
+        pScrn->monitor->Modes = xf86ModesAdd(pScrn->monitor->Modes, m);
     }

     if (i < 1 && pNv->FBDev) {
--
2.43.0




TLDR; Patch wont work on FreeBSD based on your OpenBSD output, potential
diff(probably something wrong with it due to my X experience) that you probably
shouldnt apply unless your actually desperate, and I will hopefully try to
reproduce the issue myself.

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are on the CC list for the bug.