1 | The sdio_read32() calls sd_read(), but does not handle the error if | 1 | The sdio_read32() calls sd_read(), but does not handle the error if |
---|---|---|---|
2 | sd_read() fails. This could lead to subsequent operations processing | 2 | sd_read() fails. This could lead to subsequent operations processing |
3 | invalid data. A proper implementation can be found in sdio_readN(). | 3 | invalid data. A proper implementation can be found in sdio_readN(), |
4 | which has an error handling for the sd_read(). | ||
4 | 5 | ||
5 | Add error handling for the sd_read() to free tmpbuf and return error | 6 | Add error handling for the sd_read() to free tmpbuf and return error |
6 | code if sd_read() fails. This ensure that the memcpy() is only performed | 7 | code if sd_read() fails. This ensure that the memcpy() is only performed |
7 | when the read operation is successful. | 8 | when the read operation is successful. |
8 | 9 | ||
10 | Since none of the callers check for the errors, there is no need to | ||
11 | return the error code propagated from sd_read(). Returning SDIO_ERR_VAL32 | ||
12 | might be a better choice, which is a specialized error code for SDIO. | ||
13 | |||
14 | Another problem of returning propagated error code is that the error | ||
15 | code is a s32 type value, which is not fit with the u32 type return value | ||
16 | of the sdio_read32(). | ||
17 | |||
18 | An practical option would be to go through all the callers and add error | ||
19 | handling, which need to pass a pointer to u32 *val and return zero on | ||
20 | success or negative on failure. It is not a better choice since will cost | ||
21 | unnecessary effort on the error code. | ||
22 | |||
23 | The other opion is to replace sd_read() by sd_read32(), which return an | ||
24 | u32 type error code that can be directly used as the return value of | ||
25 | sdio_read32(). But, it is also a bad choice to use sd_read32() in a | ||
26 | alignment failed branch. | ||
27 | |||
9 | Fixes: 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver") | 28 | Fixes: 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver") |
10 | Cc: stable@vger.kernel.org # v4.12+ | 29 | Cc: stable@vger.kernel.org # v4.12+ |
11 | Signed-off-by: Wentao Liang <vulab@iscas.ac.cn> | 30 | Signed-off-by: Wentao Liang <vulab@iscas.ac.cn> |
12 | --- | 31 | --- |
32 | v7: Fix error code and add patch explanation | ||
33 | v6: Fix improper code to propagate error code | ||
13 | v5: Fix error code | 34 | v5: Fix error code |
14 | v4: Add change log and fix error code | 35 | v4: Add change log and fix error code |
15 | v3: Add Cc flag | 36 | v3: Add Cc flag |
16 | v2: Change code to initialize val | 37 | v2: Change code to initialize val |
17 | 38 | ||
... | ... | diff view generated by jsdifflib |