From 77253a8d8139e49afaf4774bccef95e813fb9f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 25 Jan 2024 20:22:28 +0800 Subject: [PATCH] GPU (FreeBSD): better name detection --- src/detection/gpu/gpu_bsd.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/detection/gpu/gpu_bsd.c b/src/detection/gpu/gpu_bsd.c index 3d26022d1..a75f6cc27 100644 --- a/src/detection/gpu/gpu_bsd.c +++ b/src/detection/gpu/gpu_bsd.c @@ -50,7 +50,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) for (uint32_t i = 0; i < pcio.num_matches; ++i) { - const struct pci_conf* pc = &confs[i]; + struct pci_conf* pc = &confs[i]; FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus); ffStrbufInitStatic(&gpu->vendor, ffGetGPUVendorString(pc->pc_vendor)); @@ -102,7 +102,17 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) end = memchr(start, '\n', (uint32_t) (end - start)); if (!end) end = pciids.chars + pciids.length; - ffStrbufSetNS(&gpu->name, (uint32_t) (end - start), start); + + char* openingBracket = memchr(start, '[', (uint32_t) (end - start)); + if (openingBracket) + { + openingBracket++; + char* closingBracket = memchr(openingBracket, ']', (uint32_t) (end - openingBracket)); + if (closingBracket) + ffStrbufSetNS(&gpu->name, (uint32_t) (closingBracket - openingBracket), openingBracket); + } + if (!gpu->name.length) + ffStrbufSetNS(&gpu->name, (uint32_t) (end - start), start); } } }