diff options
Diffstat (limited to 'drivers/firmware/meson/meson_sm.c')
-rw-r--r-- | drivers/firmware/meson/meson_sm.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c index b0d254930ed3..ff204421117b 100644 --- a/drivers/firmware/meson/meson_sm.c +++ b/drivers/firmware/meson/meson_sm.c | |||
@@ -127,6 +127,7 @@ EXPORT_SYMBOL(meson_sm_call); | |||
127 | * meson_sm_call_read - retrieve data from secure-monitor | 127 | * meson_sm_call_read - retrieve data from secure-monitor |
128 | * | 128 | * |
129 | * @buffer: Buffer to store the retrieved data | 129 | * @buffer: Buffer to store the retrieved data |
130 | * @bsize: Size of the buffer | ||
130 | * @cmd_index: Index of the SMC32 function ID | 131 | * @cmd_index: Index of the SMC32 function ID |
131 | * @arg0: SMC32 Argument 0 | 132 | * @arg0: SMC32 Argument 0 |
132 | * @arg1: SMC32 Argument 1 | 133 | * @arg1: SMC32 Argument 1 |
@@ -135,11 +136,14 @@ EXPORT_SYMBOL(meson_sm_call); | |||
135 | * @arg4: SMC32 Argument 4 | 136 | * @arg4: SMC32 Argument 4 |
136 | * | 137 | * |
137 | * Return: size of read data on success, a negative value on error | 138 | * Return: size of read data on success, a negative value on error |
139 | * When 0 is returned there is no guarantee about the amount of | ||
140 | * data read and bsize bytes are copied in buffer. | ||
138 | */ | 141 | */ |
139 | int meson_sm_call_read(void *buffer, unsigned int cmd_index, u32 arg0, | 142 | int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index, |
140 | u32 arg1, u32 arg2, u32 arg3, u32 arg4) | 143 | u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4) |
141 | { | 144 | { |
142 | u32 size; | 145 | u32 size; |
146 | int ret; | ||
143 | 147 | ||
144 | if (!fw.chip) | 148 | if (!fw.chip) |
145 | return -ENOENT; | 149 | return -ENOENT; |
@@ -147,16 +151,24 @@ int meson_sm_call_read(void *buffer, unsigned int cmd_index, u32 arg0, | |||
147 | if (!fw.chip->cmd_shmem_out_base) | 151 | if (!fw.chip->cmd_shmem_out_base) |
148 | return -EINVAL; | 152 | return -EINVAL; |
149 | 153 | ||
154 | if (bsize > fw.chip->shmem_size) | ||
155 | return -EINVAL; | ||
156 | |||
150 | if (meson_sm_call(cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0) | 157 | if (meson_sm_call(cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0) |
151 | return -EINVAL; | 158 | return -EINVAL; |
152 | 159 | ||
153 | if (!size || size > fw.chip->shmem_size) | 160 | if (size > bsize) |
154 | return -EINVAL; | 161 | return -EINVAL; |
155 | 162 | ||
163 | ret = size; | ||
164 | |||
165 | if (!size) | ||
166 | size = bsize; | ||
167 | |||
156 | if (buffer) | 168 | if (buffer) |
157 | memcpy(buffer, fw.sm_shmem_out_base, size); | 169 | memcpy(buffer, fw.sm_shmem_out_base, size); |
158 | 170 | ||
159 | return size; | 171 | return ret; |
160 | } | 172 | } |
161 | EXPORT_SYMBOL(meson_sm_call_read); | 173 | EXPORT_SYMBOL(meson_sm_call_read); |
162 | 174 | ||