Skip to content

Commit 6dbd532

Browse files
committed
filters: return error code
The scan helpers should also return the error code instead the generic -1. Fixes: f4c6eee ("rrc: return error codes directly") Signed-off-by: Daniel Wagner <[email protected]>
1 parent 442f1d6 commit 6dbd532

2 files changed

Lines changed: 46 additions & 12 deletions

File tree

libnvme/src/nvme/filters.c

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,37 +78,71 @@ int nvme_subsys_filter(const struct dirent *d)
7878
int nvme_scan_subsystems(struct dirent ***subsys)
7979
{
8080
const char *dir = nvme_subsys_sysfs_dir();
81+
int ret;
8182

82-
return scandir(dir, subsys, nvme_subsys_filter, alphasort);
83+
ret = scandir(dir, subsys, nvme_subsys_filter, alphasort);
84+
if (ret < 0)
85+
return -errno;
86+
87+
return ret;
8388
}
8489

8590
int nvme_scan_subsystem_namespaces(nvme_subsystem_t s, struct dirent ***ns)
8691
{
87-
return scandir(nvme_subsystem_get_sysfs_dir(s), ns,
92+
int ret;
93+
94+
ret = scandir(nvme_subsystem_get_sysfs_dir(s), ns,
8895
nvme_namespace_filter, alphasort);
96+
if (ret < 0)
97+
return -errno;
98+
99+
return ret;
89100
}
90101

91102
int nvme_scan_ctrls(struct dirent ***ctrls)
92103
{
93104
const char *dir = nvme_ctrl_sysfs_dir();
105+
int ret;
94106

95-
return scandir(dir, ctrls, nvme_ctrls_filter, alphasort);
107+
ret = scandir(dir, ctrls, nvme_ctrls_filter, alphasort);
108+
if (ret < 0)
109+
return -errno;
110+
111+
return ret;
96112
}
97113

98114
int nvme_scan_ctrl_namespace_paths(nvme_ctrl_t c, struct dirent ***paths)
99115
{
100-
return scandir(nvme_ctrl_get_sysfs_dir(c), paths,
116+
int ret;
117+
118+
ret = scandir(nvme_ctrl_get_sysfs_dir(c), paths,
101119
nvme_paths_filter, alphasort);
120+
if (ret < 0)
121+
return -errno;
122+
123+
return ret;
102124
}
103125

104126
int nvme_scan_ctrl_namespaces(nvme_ctrl_t c, struct dirent ***ns)
105127
{
106-
return scandir(nvme_ctrl_get_sysfs_dir(c), ns,
128+
int ret;
129+
130+
ret = scandir(nvme_ctrl_get_sysfs_dir(c), ns,
107131
nvme_namespace_filter, alphasort);
132+
if (ret < 0)
133+
return -errno;
134+
135+
return ret;
108136
}
109137

110138
int nvme_scan_ns_head_paths(nvme_ns_head_t head, struct dirent ***paths)
111139
{
112-
return scandir(nvme_ns_head_get_sysfs_dir(head), paths,
140+
int ret;
141+
142+
ret = scandir(nvme_ns_head_get_sysfs_dir(head), paths,
113143
nvme_paths_filter, alphasort);
144+
if (ret < 0)
145+
return -errno;
146+
147+
return ret;
114148
}

libnvme/src/nvme/filters.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int nvme_subsys_filter(const struct dirent *d);
5555
* nvme_scan_subsystems() - Scan for subsystems
5656
* @subsys: Pointer to array of dirents
5757
*
58-
* Return: number of entries in @subsys
58+
* Return: number of entries in @subsys or a negative error code
5959
*/
6060
int nvme_scan_subsystems(struct dirent ***subsys);
6161

@@ -64,15 +64,15 @@ int nvme_scan_subsystems(struct dirent ***subsys);
6464
* @s: Subsystem to scan
6565
* @ns: Pointer to array of dirents
6666
*
67-
* Return: number of entries in @ns
67+
* Return: number of entries in @ns or a negative error code
6868
*/
6969
int nvme_scan_subsystem_namespaces(nvme_subsystem_t s, struct dirent ***ns);
7070

7171
/**
7272
* nvme_scan_ctrls() - Scan for controllers
7373
* @ctrls: Pointer to array of dirents
7474
*
75-
* Return: number of entries in @ctrls
75+
* Return: number of entries in @ctrls or a negative error code
7676
*/
7777
int nvme_scan_ctrls(struct dirent ***ctrls);
7878

@@ -81,7 +81,7 @@ int nvme_scan_ctrls(struct dirent ***ctrls);
8181
* @c: Controller to scan
8282
* @paths: Pointer to array of dirents
8383
*
84-
* Return: number of entries in @paths
84+
* Return: number of entries in @paths or a negative error code
8585
*/
8686
int nvme_scan_ctrl_namespace_paths(nvme_ctrl_t c, struct dirent ***paths);
8787

@@ -90,7 +90,7 @@ int nvme_scan_ctrl_namespace_paths(nvme_ctrl_t c, struct dirent ***paths);
9090
* @c: Controller to scan
9191
* @ns: Pointer to array of dirents
9292
*
93-
* Return: number of entries in @ns
93+
* Return: number of entries in @ns or a negative error code
9494
*/
9595
int nvme_scan_ctrl_namespaces(nvme_ctrl_t c, struct dirent ***ns);
9696

@@ -99,7 +99,7 @@ int nvme_scan_ctrl_namespaces(nvme_ctrl_t c, struct dirent ***ns);
9999
* @head: Namespace head node to scan
100100
* @paths : Pointer to array of dirents
101101
*
102-
* Return: number of entries in @ents
102+
* Return: number of entries in @ents or a negative error code
103103
*/
104104
int nvme_scan_ns_head_paths(nvme_ns_head_t head, struct dirent ***paths);
105105

0 commit comments

Comments
 (0)