Skip to content

Commit b238b8f

Browse files
Chen Gongaegl
authored andcommitted
pstore: make pstore write function return normal success/fail value
Currently pstore write interface employs record id as return value, but it is not enough because it can't tell caller if the write operation is successful. Pass the record id back via an argument pointer and return zero for success, non-zero for failure. Signed-off-by: Chen Gong <gong.chen@linux.intel.com> Signed-off-by: Tony Luck <tony.luck@intel.com>
1 parent abd4d55 commit b238b8f

4 files changed

Lines changed: 23 additions & 19 deletions

File tree

‎drivers/acpi/apei/erst.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ static int erst_open_pstore(struct pstore_info *psi);
933933
static int erst_close_pstore(struct pstore_info *psi);
934934
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
935935
struct timespec *time, struct pstore_info *psi);
936-
static u64 erst_writer(enum pstore_type_id type, unsigned int part,
936+
static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part,
937937
size_t size, struct pstore_info *psi);
938938
static int erst_clearer(enum pstore_type_id type, u64 id,
939939
struct pstore_info *psi);
@@ -1040,11 +1040,12 @@ static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
10401040
return (rc < 0) ? rc : (len - sizeof(*rcd));
10411041
}
10421042

1043-
static u64 erst_writer(enum pstore_type_id type, unsigned int part,
1043+
static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part,
10441044
size_t size, struct pstore_info *psi)
10451045
{
10461046
struct cper_pstore_record *rcd = (struct cper_pstore_record *)
10471047
(erst_info.buf - sizeof(*rcd));
1048+
int ret;
10481049

10491050
memset(rcd, 0, sizeof(*rcd));
10501051
memcpy(rcd->hdr.signature, CPER_SIG_RECORD, CPER_SIG_SIZE);
@@ -1079,9 +1080,10 @@ static u64 erst_writer(enum pstore_type_id type, unsigned int part,
10791080
}
10801081
rcd->sec_hdr.section_severity = CPER_SEV_FATAL;
10811082

1082-
erst_write(&rcd->hdr);
1083+
ret = erst_write(&rcd->hdr);
1084+
*id = rcd->hdr.record_id;
10831085

1084-
return rcd->hdr.record_id;
1086+
return ret;
10851087
}
10861088

10871089
static int erst_clearer(enum pstore_type_id type, u64 id,

‎drivers/firmware/efivars.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,16 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
490490
return 0;
491491
}
492492

493-
static u64 efi_pstore_write(enum pstore_type_id type, unsigned int part,
494-
size_t size, struct pstore_info *psi)
493+
static int efi_pstore_write(enum pstore_type_id type, u64 *id,
494+
unsigned int part, size_t size, struct pstore_info *psi)
495495
{
496496
char name[DUMP_NAME_LEN];
497497
char stub_name[DUMP_NAME_LEN];
498498
efi_char16_t efi_name[DUMP_NAME_LEN];
499499
efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
500500
struct efivars *efivars = psi->data;
501501
struct efivar_entry *entry, *found = NULL;
502-
int i;
502+
int i, ret = 0;
503503

504504
sprintf(stub_name, "dump-type%u-%u-", type, part);
505505
sprintf(name, "%s%lu", stub_name, get_seconds());
@@ -548,18 +548,19 @@ static u64 efi_pstore_write(enum pstore_type_id type, unsigned int part,
548548
efivar_unregister(found);
549549

550550
if (size)
551-
efivar_create_sysfs_entry(efivars,
551+
ret = efivar_create_sysfs_entry(efivars,
552552
utf16_strsize(efi_name,
553553
DUMP_NAME_LEN * 2),
554554
efi_name, &vendor);
555555

556-
return part;
556+
*id = part;
557+
return ret;
557558
};
558559

559560
static int efi_pstore_erase(enum pstore_type_id type, u64 id,
560561
struct pstore_info *psi)
561562
{
562-
efi_pstore_write(type, id, 0, psi);
563+
efi_pstore_write(type, &id, (unsigned int)id, 0, psi);
563564

564565
return 0;
565566
}
@@ -580,8 +581,8 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
580581
return -1;
581582
}
582583

583-
static u64 efi_pstore_write(enum pstore_type_id type, unsigned int part,
584-
size_t size, struct pstore_info *psi)
584+
static int efi_pstore_write(enum pstore_type_id type, u64 *id,
585+
unsigned int part, size_t size, struct pstore_info *psi)
585586
{
586587
return 0;
587588
}

‎fs/pstore/platform.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
8787
unsigned long size, total = 0;
8888
char *dst, *why;
8989
u64 id;
90-
int hsize;
90+
int hsize, ret;
9191
unsigned int part = 1;
9292
unsigned long flags = 0;
9393
int is_locked = 0;
@@ -122,9 +122,9 @@ static void pstore_dump(struct kmsg_dumper *dumper,
122122
memcpy(dst, s1 + s1_start, l1_cpy);
123123
memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy);
124124

125-
id = psinfo->write(PSTORE_TYPE_DMESG, part,
125+
ret = psinfo->write(PSTORE_TYPE_DMESG, &id, part,
126126
hsize + l1_cpy + l2_cpy, psinfo);
127-
if (reason == KMSG_DUMP_OOPS && pstore_is_mounted())
127+
if (ret == 0 && reason == KMSG_DUMP_OOPS && pstore_is_mounted())
128128
pstore_new_entry = 1;
129129
l1 -= l1_cpy;
130130
l2 -= l2_cpy;
@@ -247,6 +247,7 @@ static void pstore_timefunc(unsigned long dummy)
247247
int pstore_write(enum pstore_type_id type, char *buf, size_t size)
248248
{
249249
u64 id;
250+
int ret;
250251
unsigned long flags;
251252

252253
if (!psinfo)
@@ -257,8 +258,8 @@ int pstore_write(enum pstore_type_id type, char *buf, size_t size)
257258

258259
spin_lock_irqsave(&psinfo->buf_lock, flags);
259260
memcpy(psinfo->buf, buf, size);
260-
id = psinfo->write(type, 0, size, psinfo);
261-
if (pstore_is_mounted())
261+
ret = psinfo->write(type, &id, 0, size, psinfo);
262+
if (ret == 0 && pstore_is_mounted())
262263
pstore_mkfile(PSTORE_TYPE_DMESG, psinfo->name, id, psinfo->buf,
263264
size, CURRENT_TIME, psinfo);
264265
spin_unlock_irqrestore(&psinfo->buf_lock, flags);

‎include/linux/pstore.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct pstore_info {
3939
int (*close)(struct pstore_info *psi);
4040
ssize_t (*read)(u64 *id, enum pstore_type_id *type,
4141
struct timespec *time, struct pstore_info *psi);
42-
u64 (*write)(enum pstore_type_id type, unsigned int part,
43-
size_t size, struct pstore_info *psi);
42+
int (*write)(enum pstore_type_id type, u64 *id,
43+
unsigned int part, size_t size, struct pstore_info *psi);
4444
int (*erase)(enum pstore_type_id type, u64 id,
4545
struct pstore_info *psi);
4646
void *data;

0 commit comments

Comments
 (0)