|
23 | 23 |
|
24 | 24 | #include <ccan/endian/endian.h> |
25 | 25 |
|
| 26 | +#include "cleanup.h" |
26 | 27 | #include "private.h" |
27 | 28 | #include "util.h" |
28 | 29 | #include "log.h" |
@@ -427,7 +428,7 @@ void nvme_init_copy_range_f1(struct nvme_copy_range_f1 *copy, __u16 *nlbs, |
427 | 428 | copy[i].elbatm = cpu_to_le16(elbatms[i]); |
428 | 429 | copy[i].elbat = cpu_to_le16(elbats[i]); |
429 | 430 | nvme_init_copy_range_elbt(copy[i].elbt, eilbrts[i]); |
430 | | - } |
| 431 | + } |
431 | 432 | } |
432 | 433 |
|
433 | 434 | void nvme_init_copy_range_f2(struct nvme_copy_range_f2 *copy, __u32 *snsids, |
@@ -756,15 +757,14 @@ char *kv_keymatch(const char *kv, const char *key) |
756 | 757 | static size_t read_file(const char * fname, char *buffer, size_t *bufsz) |
757 | 758 | { |
758 | 759 | char *p; |
759 | | - FILE *file; |
| 760 | + _cleanup_file_ FILE *file; |
760 | 761 | size_t len; |
761 | 762 |
|
762 | 763 | file = fopen(fname, "re"); |
763 | 764 | if (!file) |
764 | 765 | return 0; |
765 | 766 |
|
766 | 767 | p = fgets(buffer, *bufsz, file); |
767 | | - fclose(file); |
768 | 768 |
|
769 | 769 | if (!p) |
770 | 770 | return 0; |
@@ -806,7 +806,7 @@ size_t get_entity_name(char *buffer, size_t bufsz) |
806 | 806 |
|
807 | 807 | size_t get_entity_version(char *buffer, size_t bufsz) |
808 | 808 | { |
809 | | - FILE *file; |
| 809 | + _cleanup_file_ FILE *file; |
810 | 810 | size_t num_bytes = 0; |
811 | 811 |
|
812 | 812 | /* /proc/sys/kernel/ostype typically contains the string "Linux" */ |
@@ -856,7 +856,6 @@ size_t get_entity_version(char *buffer, size_t bufsz) |
856 | 856 | if (s) |
857 | 857 | ver_id_len = copy_value(ver_id, sizeof(ver_id), s); |
858 | 858 | } |
859 | | - fclose(file); |
860 | 859 |
|
861 | 860 | if (name_len) { |
862 | 861 | /* Append a space */ |
@@ -929,14 +928,13 @@ int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]) |
929 | 928 |
|
930 | 929 | int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN]) |
931 | 930 | { |
932 | | - int f; |
| 931 | + _cleanup_fd_ int f; |
933 | 932 | ssize_t n; |
934 | 933 |
|
935 | 934 | f = open("/dev/urandom", O_RDONLY); |
936 | 935 | if (f < 0) |
937 | 936 | return -errno; |
938 | 937 | n = read(f, uuid, NVME_UUID_LEN); |
939 | | - close(f); |
940 | 938 | if (n < 0) |
941 | 939 | return -errno; |
942 | 940 | else if (n != NVME_UUID_LEN) |
|
0 commit comments