9b6251b919eba90123afbb96ac5cd0a46422826d
[openwrt/staging/thess.git] /
1 From 588773802c386d38f9c4e91acd47369e89d95a30 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
3 Date: Fri, 5 Jul 2024 08:48:48 +0100
4 Subject: [PATCH] nvmem: core: drop unnecessary range checks in sysfs callbacks
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 The same checks have already been done in sysfs_kf_bin_write() and
10 sysfs_kf_bin_read() just before the callbacks are invoked.
11
12 Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
13 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
14 Link: https://lore.kernel.org/r/20240705074852.423202-12-srinivas.kandagatla@linaro.org
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 ---
17 drivers/nvmem/core.c | 14 --------------
18 1 file changed, 14 deletions(-)
19
20 --- a/drivers/nvmem/core.c
21 +++ b/drivers/nvmem/core.c
22 @@ -204,19 +204,12 @@ static ssize_t bin_attr_nvmem_read(struc
23 dev = kobj_to_dev(kobj);
24 nvmem = to_nvmem_device(dev);
25
26 - /* Stop the user from reading */
27 - if (pos >= nvmem->size)
28 - return 0;
29 -
30 if (!IS_ALIGNED(pos, nvmem->stride))
31 return -EINVAL;
32
33 if (count < nvmem->word_size)
34 return -EINVAL;
35
36 - if (pos + count > nvmem->size)
37 - count = nvmem->size - pos;
38 -
39 count = round_down(count, nvmem->word_size);
40
41 if (!nvmem->reg_read)
42 @@ -244,19 +237,12 @@ static ssize_t bin_attr_nvmem_write(stru
43 dev = kobj_to_dev(kobj);
44 nvmem = to_nvmem_device(dev);
45
46 - /* Stop the user from writing */
47 - if (pos >= nvmem->size)
48 - return -EFBIG;
49 -
50 if (!IS_ALIGNED(pos, nvmem->stride))
51 return -EINVAL;
52
53 if (count < nvmem->word_size)
54 return -EINVAL;
55
56 - if (pos + count > nvmem->size)
57 - count = nvmem->size - pos;
58 -
59 count = round_down(count, nvmem->word_size);
60
61 if (!nvmem->reg_write)