@@ -86,6 +86,24 @@ static int ramoops_pstore_open(struct pstore_info *psi)
return 0;
}
+static struct persistent_ram_zone *
+ramoops_get_dump_prz(u64 id, enum pstore_type_id *type,
+ struct ramoops_context *cxt)
+{
+ struct persistent_ram_zone *prz;
+
+ if (id > cxt->max_dump_count)
+ return NULL;
+
+ prz = cxt->przs[id];
+ if (!persistent_ram_old_size(prz))
+ return NULL;
+
+ *type = PSTORE_TYPE_DMESG;
+
+ return prz;
+}
+
static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
struct timespec *time,
char **buf,
@@ -95,14 +113,12 @@ 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->read_count >= cxt->max_dump_count)
- return -EINVAL;
-
*id = cxt->read_count++;
- prz = cxt->przs[*id];
- /* Only supports dmesg output so far. */
- *type = PSTORE_TYPE_DMESG;
+ prz = ramoops_get_dump_prz(*id, type, cxt);
+ if (!prz)
+ return 0;
+
/* TODO(kees): Bogus time for the moment. */
time->tv_sec = 0;
time->tv_nsec = 0;
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> --- fs/pstore/ram.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)