| File: | .build-ci/../src/nvme-pci-ids.c |
| Warning: | line 44, column 6 Potential leak of memory pointed to by 'ctrl_name' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | // SPDX-License-Identifier: GPL-2.0-or-later | |||
| 2 | /* | |||
| 3 | * Copyright (c) 2026 Micron Technology, Inc. | |||
| 4 | * | |||
| 5 | * Authors: Broc Going <bgoing@micron.com> | |||
| 6 | */ | |||
| 7 | ||||
| 8 | #include <errno(*__errno_location ()).h> | |||
| 9 | #include <stdio.h> | |||
| 10 | #include <stdlib.h> | |||
| 11 | #include <string.h> | |||
| 12 | ||||
| 13 | #include <libnvme.h> | |||
| 14 | ||||
| 15 | #include "nvme-pci-ids.h" | |||
| 16 | #include "nvme-print.h" | |||
| 17 | #include "cleanup.h" | |||
| 18 | ||||
| 19 | int nvme_get_pci_ids(struct libnvme_global_ctx *ctx, | |||
| 20 | struct libnvme_transport_handle *hdl, | |||
| 21 | __u32 *vid, __u32 *did, | |||
| 22 | __u32 *subsys_vid, __u32 *subsys_did, | |||
| 23 | __u32 *class_code) | |||
| 24 | { | |||
| 25 | int ret; | |||
| 26 | const char *name; | |||
| 27 | ||||
| 28 | __cleanup_free__attribute__((cleanup(shr_freep))) char *ctrl_name = NULL((void*)0); | |||
| 29 | __cleanup_free__attribute__((cleanup(shr_freep))) char *sysfs_dir = NULL((void*)0); | |||
| 30 | ||||
| 31 | name = libnvme_transport_handle_get_name(hdl); | |||
| 32 | if (libnvme_transport_handle_is_ctrl(hdl)) { | |||
| ||||
| 33 | ctrl_name = strdup(name); | |||
| 34 | } else { | |||
| 35 | /* Strip the 'nY' namespace suffix: "nvme0n1" -> "nvme0" */ | |||
| 36 | const char *p = strlen(name) > 4 ? strchr(name + 4, 'n')_Generic (0 ? (name + 4) : (void *) 1, const void *: (const char *) (strchr (name + 4, 'n')), default: strchr (name + 4, 'n') ) : NULL((void*)0); | |||
| 37 | ||||
| 38 | ctrl_name = p
| |||
| 39 | } | |||
| 40 | ||||
| 41 | if (!ctrl_name) | |||
| 42 | return -ENOMEM12; | |||
| 43 | ||||
| 44 | ret = __nvme_get_sysfs_dir(ctx, ctrl_name, &sysfs_dir); | |||
| ||||
| 45 | if (ret != 0) | |||
| 46 | return ret; | |||
| 47 | ||||
| 48 | return __nvme_get_pci_ids(sysfs_dir, vid, did, subsys_vid, subsys_did, | |||
| 49 | class_code); | |||
| 50 | } |