]> git.hungrycats.org Git - linux/commitdiff
nvmem: core: Check read_only flag for force_ro in bin_attr_nvmem_write()
authorMarek Vasut <marex@denx.de>
Wed, 30 Oct 2024 14:02:53 +0000 (14:02 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 9 Dec 2024 09:41:03 +0000 (10:41 +0100)
commit da9596955c05966768364ab1cad2f43fcddc6f06 upstream.

The bin_attr_nvmem_write() must check the read_only flag and block
writes on read-only devices, now that a nvmem device can be switched
between read-write and read-only mode at runtime using the force_ro
attribute. Add the missing check.

Fixes: 9d7eb234ac7a ("nvmem: core: Implement force_ro sysfs attribute")
Cc: Stable@vger.kernel.org
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20241030140253.40445-2-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvmem/core.c

index 33ffa2aa4c1152398ec66b8dd7b30384c5346a6e..e1a15fbc6ad025b6c5d51ae05545e299c37ad8bd 100644 (file)
@@ -267,7 +267,7 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
 
        count = round_down(count, nvmem->word_size);
 
-       if (!nvmem->reg_write)
+       if (!nvmem->reg_write || nvmem->read_only)
                return -EPERM;
 
        rc = nvmem_reg_write(nvmem, pos, buf, count);