Skip to content

Commit 24a6bfd

Browse files
ikegami-tigaw
authored andcommitted
nvme: change _cleanup_file_ to _cleanup_fd_
Add _cleanup_file_ to clean up file stream instead. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent fa5a46c commit 24a6bfd

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

nvme.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd,
880880

881881
_cleanup_free_ struct nvme_telemetry_log *log = NULL;
882882
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
883-
_cleanup_file_ int output = -1;
883+
_cleanup_fd_ int output = -1;
884884
int err = 0;
885885
size_t total_size;
886886
__u8 *data_ptr = NULL;
@@ -1808,7 +1808,7 @@ static int get_boot_part_log(int argc, char **argv, struct command *cmd, struct
18081808
_cleanup_free_ __u8 *bp_log = NULL;
18091809
nvme_print_flags_t flags;
18101810
int err = -1;
1811-
_cleanup_file_ int output = -1;
1811+
_cleanup_fd_ int output = -1;
18121812
__u32 bpsz = 0;
18131813

18141814
struct config {
@@ -2183,7 +2183,7 @@ static int io_mgmt_recv(int argc, char **argv, struct command *cmd, struct plugi
21832183
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
21842184
_cleanup_free_ void *buf = NULL;
21852185
int err = -1;
2186-
_cleanup_file_ int dfd = -1;
2186+
_cleanup_fd_ int dfd = -1;
21872187

21882188
struct config {
21892189
__u16 mos;
@@ -4903,7 +4903,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin
49034903

49044904
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
49054905
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
4906-
_cleanup_file_ int fw_fd = -1;
4906+
_cleanup_fd_ int fw_fd = -1;
49074907
unsigned int fw_size, pos;
49084908
int err;
49094909
struct stat sb;
@@ -6374,7 +6374,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
63746374

63756375
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
63766376
_cleanup_free_ void *buf = NULL;
6377-
_cleanup_file_ int ffd = STDIN_FILENO;
6377+
_cleanup_fd_ int ffd = STDIN_FILENO;
63786378
int err;
63796379
__u32 result;
63806380

@@ -6524,7 +6524,7 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p
65246524

65256525
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
65266526
_cleanup_free_ void *sec_buf = NULL;
6527-
_cleanup_file_ int sec_fd = -1;
6527+
_cleanup_fd_ int sec_fd = -1;
65286528
unsigned int sec_size;
65296529
int err;
65306530

@@ -6633,7 +6633,7 @@ static int dir_send(int argc, char **argv, struct command *cmd, struct plugin *p
66336633
_cleanup_free_ void *buf = NULL;
66346634
__u32 result;
66356635
__u32 dw12 = 0;
6636-
_cleanup_file_ int ffd = STDIN_FILENO;
6636+
_cleanup_fd_ int ffd = STDIN_FILENO;
66376637
int err;
66386638

66396639
struct config {
@@ -7720,7 +7720,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
77207720
void *buffer;
77217721
_cleanup_free_ void *mbuffer = NULL;
77227722
int err = 0;
7723-
_cleanup_file_ int dfd = -1, mfd = -1;
7723+
_cleanup_fd_ int dfd = -1, mfd = -1;
77247724
int flags;
77257725
int mode = 0644;
77267726
__u16 control = 0, nblocks = 0;
@@ -8728,7 +8728,7 @@ static int passthru(int argc, char **argv, bool admin,
87288728

87298729
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
87308730
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
8731-
_cleanup_file_ int dfd = -1, mfd = -1;
8731+
_cleanup_fd_ int dfd = -1, mfd = -1;
87328732
int flags;
87338733
int mode = 0644;
87348734
void *data = NULL;
@@ -9663,7 +9663,7 @@ static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc)
96639663
void *data = NULL;
96649664
int err = 0;
96659665
bool send;
9666-
_cleanup_file_ int fd = -1;
9666+
_cleanup_fd_ int fd = -1;
96679667
int flags;
96689668
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
96699669
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;

plugins/solidigm/solidigm-internal-logs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ struct log {
455455
static int log_save(struct log *log, const char *parent_dir_name, const char *subdir_name,
456456
const char *file_name, __u8 *buffer, size_t buf_size)
457457
{
458-
_cleanup_file_ int output = -1;
458+
_cleanup_fd_ int output = -1;
459459
char file_path[PATH_MAX] = {0};
460460
size_t bytes_remaining = 0;
461461
int err = 0;

util/cleanup.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ DECLARE_CLEANUP_FUNC(name, type) \
2323

2424
static inline void freep(void *p)
2525
{
26-
free(*(void**) p);
26+
free(*(void **)p);
2727
}
2828
#define _cleanup_free_ __cleanup__(freep)
2929

3030
#define _cleanup_huge_ __cleanup__(nvme_free_huge)
3131

32-
static inline void close_file(int *f)
32+
static inline void cleanup_fd(int *fd)
3333
{
34-
if (*f > STDERR_FILENO)
35-
close(*f);
34+
if (*fd > STDERR_FILENO)
35+
close(*fd);
3636
}
37-
#define _cleanup_file_ __cleanup__(close_file)
37+
#define _cleanup_fd_ __cleanup__(cleanup_fd)
3838

3939
static inline void cleanup_nvme_root(nvme_root_t *r)
4040
{
@@ -48,7 +48,9 @@ static inline void free_uri(struct nvme_fabrics_uri **uri)
4848
if (*uri)
4949
nvme_free_uri(*uri);
5050
}
51-
5251
#define _cleanup_uri_ __cleanup__(free_uri)
5352

54-
#endif
53+
static inline DEFINE_CLEANUP_FUNC(cleanup_file, FILE *, fclose)
54+
#define _cleanup_file_ __cleanup__(cleanup_file)
55+
56+
#endif /* __CLEANUP_H */

0 commit comments

Comments
 (0)