Skip to content

Commit 88e193e

Browse files
committed
GPU: fix code smell
1 parent e474a47 commit 88e193e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/detection/gpu/gpu_bsd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
1414
{
1515
FF_AUTO_CLOSE_FD int fd = open("/dev/pci", O_RDONLY, 0);
16+
if (fd < 0)
17+
return "open(\"/dev/pci\", O_RDONLY, 0) failed";
18+
1619
struct pci_conf confs[128];
1720
struct pci_match_conf match = {
1821
.pc_class = PCIC_DISPLAY,
@@ -78,7 +81,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
7881
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
7982
ffGPUQueryAmdGpuName(pc->pc_device, pc->pc_revid, gpu);
8083
if (gpu->name.length == 0)
81-
ffGPUFillVendorAndName(pc->pc_subclass, pc->pc_vendor, pc->pc_device, gpu);
84+
ffGPUFillVendorAndName(pc->pc_subclass, pc->pc_vendor, pc->pc_device, gpu);
8285
}
8386

8487
if (gpu->type == FF_GPU_TYPE_UNKNOWN)

src/detection/gpu/gpu_linux.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,9 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
426426
}
427427
else
428428
{
429-
pPciPath = memrchr(deviceDir->chars, '/', deviceDir->length) + 1;
429+
pPciPath = memrchr(deviceDir->chars, '/', deviceDir->length);
430+
assert(pPciPath);
431+
pPciPath++;
430432
}
431433

432434
uint32_t pciDomain, pciBus, pciDevice, pciFunc;

src/detection/gpu/gpu_sunos.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
3535
{
3636
// find the start of device entry
3737
const char* pstart = memrchr(buffer.chars, '\n', (size_t) (pclass - buffer.chars));
38+
if (pstart == NULL)
39+
return "PCI info not found, invalid scanpci result";
3840
while (pstart[1] != 'p')
41+
{
3942
pstart = memrchr(buffer.chars, '\n', (size_t) (pstart - buffer.chars - 1));
43+
if (pstart == NULL)
44+
return "PCI info not found, invalid scanpci result";
45+
}
4046
++pstart;
4147

4248
uint32_t vendorId, deviceId;

0 commit comments

Comments
 (0)