summaryrefslogtreecommitdiffstats
path: root/fs/pstore/ram.c
diff options
context:
space:
mode:
authorAnton Vorontsov <anton.vorontsov@linaro.org>2012-05-26 06:20:22 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-06-13 16:59:28 -0700
commit755d66b48fe5a1f2a07802fcc8704e8b9e775e7d (patch)
treeb89be654693337c57cac86de43666629bddb8d0d /fs/pstore/ram.c
parentf4c5d2423c64266ba0daa9cc803d1d5ba469fe36 (diff)
downloadblackbird-op-linux-755d66b48fe5a1f2a07802fcc8704e8b9e775e7d.tar.gz
blackbird-op-linux-755d66b48fe5a1f2a07802fcc8704e8b9e775e7d.zip
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.c41
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)
return 0;
}
+static struct persistent_ram_zone *
+ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
+ u64 *id,
+ enum pstore_type_id *typep, enum pstore_type_id type,
+ bool update)
+{
+ struct persistent_ram_zone *prz;
+ int i = (*c)++;
+
+ if (i >= max)
+ return NULL;
+
+ prz = przs[i];
+
+ if (update) {
+ /* Update old/shadowed buffer. */
+ persistent_ram_save_old(prz);
+ if (!persistent_ram_old_size(prz))
+ return NULL;
+ }
+
+ *typep = type;
+ *id = i;
+
+ return prz;
+}
+
static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
struct timespec *time,
char **buf,
@@ -94,20 +121,16 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
struct ramoops_context *cxt = psi->data;
struct persistent_ram_zone *prz;
- if (cxt->dump_read_cnt >= cxt->max_dump_cnt)
- return -EINVAL;
-
- *id = cxt->dump_read_cnt++;
- prz = cxt->przs[*id];
+ prz = ramoops_get_next_prz(cxt->przs, &cxt->dump_read_cnt,
+ cxt->max_dump_cnt, id, type,
+ PSTORE_TYPE_DMESG, 1);
+ if (!prz)
+ return 0;
- /* Only supports dmesg output so far. */
- *type = PSTORE_TYPE_DMESG;
/* TODO(kees): Bogus time for the moment. */
time->tv_sec = 0;
time->tv_nsec = 0;
- /* Update old/shadowed buffer. */
- persistent_ram_save_old(prz);
size = persistent_ram_old_size(prz);
*buf = kmalloc(size, GFP_KERNEL);
if (*buf == NULL)
OpenPOWER on IntegriCloud