Commit 62a96d805f6f212250f5590d6afadf3645837f36
Committed by
Lukasz Majewski
1 parent
7da6fa2716
Exists in
v2017.01-smarct4x
and in
37 other branches
gadget: f_thor: check pointers before use in download_tail()
Some pointers in function download_tail() were not checked before the use. This could possibly cause the data abort. To avoid this, check if the pointers are not null is added. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Tested-by: Lukasz Majewski <l.majewski@samsung.com> [TestHW: Exynos4412-Trats2]
Showing 1 changed file with 14 additions and 2 deletions Side-by-side Diff
drivers/usb/gadget/f_thor.c
... | ... | @@ -205,11 +205,23 @@ |
205 | 205 | |
206 | 206 | static int download_tail(long long int left, int cnt) |
207 | 207 | { |
208 | - struct dfu_entity *dfu_entity = dfu_get_entity(alt_setting_num); | |
209 | - void *transfer_buffer = dfu_get_buf(dfu_entity); | |
208 | + struct dfu_entity *dfu_entity; | |
209 | + void *transfer_buffer; | |
210 | 210 | int ret; |
211 | 211 | |
212 | 212 | debug("%s: left: %llu cnt: %d\n", __func__, left, cnt); |
213 | + | |
214 | + dfu_entity = dfu_get_entity(alt_setting_num); | |
215 | + if (!dfu_entity) { | |
216 | + error("Alt setting: %d entity not found!\n", alt_setting_num); | |
217 | + return -ENOENT; | |
218 | + } | |
219 | + | |
220 | + transfer_buffer = dfu_get_buf(dfu_entity); | |
221 | + if (!transfer_buffer) { | |
222 | + error("Transfer buffer not allocated!"); | |
223 | + return -ENXIO; | |
224 | + } | |
213 | 225 | |
214 | 226 | if (left) { |
215 | 227 | ret = dfu_write(dfu_entity, transfer_buffer, left, cnt++); |