9e5d6198b7f3368680d5ecfa0e6125b74baa233f
[openwrt/staging/xback.git] /
1 From 7a0a6d0a7c805f9380381f4deedffdf87b93f408 Mon Sep 17 00:00:00 2001
2 From: Joy Chakraborty <joychakr@google.com>
3 Date: Fri, 28 Jun 2024 12:37:02 +0100
4 Subject: [PATCH] nvmem: meson-efuse: Fix return value of nvmem callbacks
5
6 Read/write callbacks registered with nvmem core expect 0 to be returned
7 on success and a negative value to be returned on failure.
8
9 meson_efuse_read() and meson_efuse_write() call into
10 meson_sm_call_read() and meson_sm_call_write() respectively which return
11 the number of bytes read or written on success as per their api
12 description.
13
14 Fix to return error if meson_sm_call_read()/meson_sm_call_write()
15 returns an error else return 0.
16
17 Fixes: a29a63bdaf6f ("nvmem: meson-efuse: simplify read callback")
18 Cc: stable@vger.kernel.org
19 Signed-off-by: Joy Chakraborty <joychakr@google.com>
20 Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
21 Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
22 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
23 Link: https://lore.kernel.org/r/20240628113704.13742-3-srinivas.kandagatla@linaro.org
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25 ---
26 drivers/nvmem/meson-efuse.c | 14 ++++++++++----
27 1 file changed, 10 insertions(+), 4 deletions(-)
28
29 --- a/drivers/nvmem/meson-efuse.c
30 +++ b/drivers/nvmem/meson-efuse.c
31 @@ -18,18 +18,24 @@ static int meson_efuse_read(void *contex
32 void *val, size_t bytes)
33 {
34 struct meson_sm_firmware *fw = context;
35 + int ret;
36
37 - return meson_sm_call_read(fw, (u8 *)val, bytes, SM_EFUSE_READ, offset,
38 - bytes, 0, 0, 0);
39 + ret = meson_sm_call_read(fw, (u8 *)val, bytes, SM_EFUSE_READ, offset,
40 + bytes, 0, 0, 0);
41 +
42 + return ret < 0 ? ret : 0;
43 }
44
45 static int meson_efuse_write(void *context, unsigned int offset,
46 void *val, size_t bytes)
47 {
48 struct meson_sm_firmware *fw = context;
49 + int ret;
50 +
51 + ret = meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
52 + bytes, 0, 0, 0);
53
54 - return meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
55 - bytes, 0, 0, 0);
56 + return ret < 0 ? ret : 0;
57 }
58
59 static const struct of_device_id meson_efuse_match[] = {