mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-02 07:00:42 -04:00
power: reset: nvmem-reboot-mode: respect cell size for nvmem_cell_write
Some platforms expose reboot mode cells that are smaller than an
unsigned int, in which cases lead to write failures. Read the cell
first to determine actual size and only write the number of bytes the
cell can hold.
Fixes: 7a78a7f769 ("power: reset: nvmem-reboot-mode: use NVMEM as reboot mode write interface")
Signed-off-by: Alexander Koskovich <akoskovich@pm.me>
Link: https://patch.msgid.link/20251214191529.2470580-1-akoskovich@pm.me
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
committed by
Sebastian Reichel
parent
8d59cf3887
commit
36b0562922
@@ -10,6 +10,7 @@
|
||||
#include <linux/nvmem-consumer.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/reboot-mode.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
struct nvmem_reboot_mode {
|
||||
struct reboot_mode_driver reboot;
|
||||
@@ -19,12 +20,22 @@ struct nvmem_reboot_mode {
|
||||
static int nvmem_reboot_mode_write(struct reboot_mode_driver *reboot,
|
||||
unsigned int magic)
|
||||
{
|
||||
int ret;
|
||||
struct nvmem_reboot_mode *nvmem_rbm;
|
||||
size_t buf_len;
|
||||
void *buf;
|
||||
int ret;
|
||||
|
||||
nvmem_rbm = container_of(reboot, struct nvmem_reboot_mode, reboot);
|
||||
|
||||
ret = nvmem_cell_write(nvmem_rbm->cell, &magic, sizeof(magic));
|
||||
buf = nvmem_cell_read(nvmem_rbm->cell, &buf_len);
|
||||
if (IS_ERR(buf))
|
||||
return PTR_ERR(buf);
|
||||
kfree(buf);
|
||||
|
||||
if (buf_len > sizeof(magic))
|
||||
return -EINVAL;
|
||||
|
||||
ret = nvmem_cell_write(nvmem_rbm->cell, &magic, buf_len);
|
||||
if (ret < 0)
|
||||
dev_err(reboot->dev, "update reboot mode bits failed\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user