diff options
author | Anton Vorontsov <anton.vorontsov@linaro.org> | 2012-05-26 09:20:22 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-06-13 19:59:28 -0400 |
commit | 755d66b48fe5a1f2a07802fcc8704e8b9e775e7d (patch) | |
tree | b89be654693337c57cac86de43666629bddb8d0d /fs/pstore/ram.c | |
parent | f4c5d2423c64266ba0daa9cc803d1d5ba469fe36 (diff) |
pstore/ram: Factor ramoops_get_next_prz() out of ramoops_pstore_read()
This will help make code clearer when we'll add support for other
message types.
The patch also changes return value from -EINVAL to 0 in case of
end-of-records. The exact value doesn't matter for pstore (it should
be just <= 0), but 0 feels more correct.
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/pstore/ram.c')
-rw-r--r-- | fs/pstore/ram.c | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 6b7676738493..d770d7266e96 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c | |||
@@ -85,6 +85,33 @@ static int ramoops_pstore_open(struct pstore_info *psi) | |||
85 | return 0; | 85 | return 0; |
86 | } | 86 | } |
87 | 87 | ||
88 | static struct persistent_ram_zone * | ||
89 | ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max, | ||
90 | u64 *id, | ||
91 | enum pstore_type_id *typep, enum pstore_type_id type, | ||
92 | bool update) | ||
93 | { | ||
94 | struct persistent_ram_zone *prz; | ||
95 | int i = (*c)++; | ||
96 | |||
97 | if (i >= max) | ||
98 | return NULL; | ||
99 | |||
100 | prz = przs[i]; | ||
101 | |||
102 | if (update) { | ||
103 | /* Update old/shadowed buffer. */ | ||
104 | persistent_ram_save_old(prz); | ||
105 | if (!persistent_ram_old_size(prz)) | ||
106 | return NULL; | ||
107 | } | ||
108 | |||
109 | *typep = type; | ||
110 | *id = i; | ||
111 | |||
112 | return prz; | ||
113 | } | ||
114 | |||
88 | static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, | 115 | static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, |
89 | struct timespec *time, | 116 | struct timespec *time, |
90 | char **buf, | 117 | char **buf, |
@@ -94,20 +121,16 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, | |||
94 | struct ramoops_context *cxt = psi->data; | 121 | struct ramoops_context *cxt = psi->data; |
95 | struct persistent_ram_zone *prz; | 122 | struct persistent_ram_zone *prz; |
96 | 123 | ||
97 | if (cxt->dump_read_cnt >= cxt->max_dump_cnt) | 124 | prz = ramoops_get_next_prz(cxt->przs, &cxt->dump_read_cnt, |
98 | return -EINVAL; | 125 | cxt->max_dump_cnt, id, type, |
99 | 126 | PSTORE_TYPE_DMESG, 1); | |
100 | *id = cxt->dump_read_cnt++; | 127 | if (!prz) |
101 | prz = cxt->przs[*id]; | 128 | return 0; |
102 | 129 | ||
103 | /* Only supports dmesg output so far. */ | ||
104 | *type = PSTORE_TYPE_DMESG; | ||
105 | /* TODO(kees): Bogus time for the moment. */ | 130 | /* TODO(kees): Bogus time for the moment. */ |
106 | time->tv_sec = 0; | 131 | time->tv_sec = 0; |
107 | time->tv_nsec = 0; | 132 | time->tv_nsec = 0; |
108 | 133 | ||
109 | /* Update old/shadowed buffer. */ | ||
110 | persistent_ram_save_old(prz); | ||
111 | size = persistent_ram_old_size(prz); | 134 | size = persistent_ram_old_size(prz); |
112 | *buf = kmalloc(size, GFP_KERNEL); | 135 | *buf = kmalloc(size, GFP_KERNEL); |
113 | if (*buf == NULL) | 136 | if (*buf == NULL) |