pstore: Replace arguments for erase() API
authorKees Cook <keescook@chromium.org>
Sun, 5 Mar 2017 07:31:19 +0000 (23:31 -0800)
committerKees Cook <keescook@chromium.org>
Tue, 7 Mar 2017 22:01:00 +0000 (14:01 -0800)
This removes the argument list for the erase() callback and replaces it
with a pointer to the backend record details to be removed.

Signed-off-by: Kees Cook <keescook@chromium.org>
drivers/acpi/apei/erst.c
drivers/firmware/efi/efi-pstore.c
fs/pstore/inode.c
fs/pstore/ram.c
include/linux/pstore.h

index 440588d189e78f6b59e8847f29ce84702076dfa2..7207e5fc9d3d3e7aa7db77838585440686ad4c62 100644 (file)
@@ -927,8 +927,7 @@ static int erst_open_pstore(struct pstore_info *psi);
 static int erst_close_pstore(struct pstore_info *psi);
 static ssize_t erst_reader(struct pstore_record *record);
 static int erst_writer(struct pstore_record *record);
-static int erst_clearer(enum pstore_type_id type, u64 id, int count,
-                       struct timespec time, struct pstore_info *psi);
+static int erst_clearer(struct pstore_record *record);
 
 static struct pstore_info erst_info = {
        .owner          = THIS_MODULE,
@@ -1100,10 +1099,9 @@ static int erst_writer(struct pstore_record *record)
        return ret;
 }
 
-static int erst_clearer(enum pstore_type_id type, u64 id, int count,
-                       struct timespec time, struct pstore_info *psi)
+static int erst_clearer(struct pstore_record *record)
 {
-       return erst_clear(id);
+       return erst_clear(record->id);
 }
 
 static int __init erst_init(void)
index f81e3ec6f1c01d5d69bbf7ca2c04616862ea94b8..93d8cdbe7ef49361bd28a49083eb86478e0a0f4f 100644 (file)
@@ -266,10 +266,7 @@ static int efi_pstore_write(struct pstore_record *record)
 };
 
 struct pstore_erase_data {
-       u64 id;
-       enum pstore_type_id type;
-       int count;
-       struct timespec time;
+       struct pstore_record *record;
        efi_char16_t *name;
 };
 
@@ -295,8 +292,9 @@ static int efi_pstore_erase_func(struct efivar_entry *entry, void *data)
                 * Check if an old format, which doesn't support
                 * holding multiple logs, remains.
                 */
-               sprintf(name_old, "dump-type%u-%u-%lu", ed->type,
-                       (unsigned int)ed->id, ed->time.tv_sec);
+               snprintf(name_old, sizeof(name_old), "dump-type%u-%u-%lu",
+                       ed->record->type, (unsigned int)ed->record->id,
+                       ed->record->time.tv_sec);
 
                for (i = 0; i < DUMP_NAME_LEN; i++)
                        efi_name_old[i] = name_old[i];
@@ -321,8 +319,7 @@ static int efi_pstore_erase_func(struct efivar_entry *entry, void *data)
        return 1;
 }
 
-static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
-                           struct timespec time, struct pstore_info *psi)
+static int efi_pstore_erase(struct pstore_record *record)
 {
        struct pstore_erase_data edata;
        struct efivar_entry *entry = NULL;
@@ -331,17 +328,16 @@ static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
        int found, i;
        unsigned int part;
 
-       do_div(id, 1000);
-       part = do_div(id, 100);
-       sprintf(name, "dump-type%u-%u-%d-%lu", type, part, count, time.tv_sec);
+       do_div(record->id, 1000);
+       part = do_div(record->id, 100);
+       snprintf(name, sizeof(name), "dump-type%u-%u-%d-%lu",
+                record->type, record->part, record->count,
+                record->time.tv_sec);
 
        for (i = 0; i < DUMP_NAME_LEN; i++)
                efi_name[i] = name[i];
 
-       edata.id = part;
-       edata.type = type;
-       edata.count = count;
-       edata.time = time;
+       edata.record = record;
        edata.name = efi_name;
 
        if (efivar_entry_iter_begin())
index 0ea281b457face89153fa4c713222c11a350b0a0..06504b69575bfb742aa5fc9779c86a1e9aeda73c 100644 (file)
@@ -210,14 +210,12 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
        if (err)
                return err;
 
-       if (record->psi->erase) {
-               mutex_lock(&record->psi->read_mutex);
-               record->psi->erase(record->type, record->id, record->count,
-                             d_inode(dentry)->i_ctime, record->psi);
-               mutex_unlock(&record->psi->read_mutex);
-       } else {
+       if (!record->psi->erase)
                return -EPERM;
-       }
+
+       mutex_lock(&record->psi->read_mutex);
+       record->psi->erase(record);
+       mutex_unlock(&record->psi->read_mutex);
 
        return simple_unlink(dir, dentry);
 }
index ca6e2a814e37b2ec22e63b96738f7e5dc5167bcc..a18575fe32e99c9c4b7a63e09cd9cb9df2ef0744 100644 (file)
@@ -469,25 +469,24 @@ static int notrace ramoops_pstore_write_buf_user(enum pstore_type_id type,
        return -EINVAL;
 }
 
-static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, int count,
-                               struct timespec time, struct pstore_info *psi)
+static int ramoops_pstore_erase(struct pstore_record *record)
 {
-       struct ramoops_context *cxt = psi->data;
+       struct ramoops_context *cxt = record->psi->data;
        struct persistent_ram_zone *prz;
 
-       switch (type) {
+       switch (record->type) {
        case PSTORE_TYPE_DMESG:
-               if (id >= cxt->max_dump_cnt)
+               if (record->id >= cxt->max_dump_cnt)
                        return -EINVAL;
-               prz = cxt->dprzs[id];
+               prz = cxt->dprzs[record->id];
                break;
        case PSTORE_TYPE_CONSOLE:
                prz = cxt->cprz;
                break;
        case PSTORE_TYPE_FTRACE:
-               if (id >= cxt->max_ftrace_cnt)
+               if (record->id >= cxt->max_ftrace_cnt)
                        return -EINVAL;
-               prz = cxt->fprzs[id];
+               prz = cxt->fprzs[record->id];
                break;
        case PSTORE_TYPE_PMSG:
                prz = cxt->mprz;
index 9335f75c3ddbe5d9b021053897a9275ee533b2ed..2cd1979d1f9af119f89180c7bc6f4c3623bd4cc7 100644 (file)
@@ -177,15 +177,11 @@ struct pstore_record {
  *
  * @erase:
  *     Delete a record from backend storage.  Different backends
- *     identify records differently, so all possible methods of
- *     identification are included to help the backend locate the
- *     record to remove.
+ *     identify records differently, so entire original record is
+ *     passed back to assist in identification of what the backend
+ *     should remove from storage.
  *
- *     @type:  in: pstore record type to write
- *     @id:    in: per-type unique identifier for the record
- *     @count: in: Oops count
- *     @time:  in: timestamp for the record
- *     @psi:   in: pointer to the struct pstore_info for the backend
+ *     @record:        pointer to record metadata.
  *
  *     Returns 0 on success, and non-zero on error.
  *
@@ -215,9 +211,7 @@ struct pstore_info {
                        enum kmsg_dump_reason reason, u64 *id,
                        unsigned int part, const char __user *buf,
                        bool compressed, size_t size, struct pstore_info *psi);
-       int             (*erase)(enum pstore_type_id type, u64 id,
-                       int count, struct timespec time,
-                       struct pstore_info *psi);
+       int             (*erase)(struct pstore_record *record);
 };
 
 /* Supported frontends */