mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-06 16:49:22 +00:00
staging: rts5208: Fix "seg_no" calculation in reset_ms_card()
I get some static checker warnings like this:
drivers/staging/rts5208/ms.c:2607 ms_build_l2p_tbl()
error: buffer underflow 'ms_card->segment' (-1)-16
The problem is that we memset "ms_card" to zero at the start of the
reset_ms_card() function. That means that when we try to calculate
"ms_card->total_block / 512 - 1" then it's just always -1. The fix is
to calculate "seg_no" before doing the memset().
This is a static checker fix, and I am not able to test it. My theory
is that reset_ms_card() gets very little testing which is why this bug
exists.
Fixes: fa590c222f
("staging: rts5208: add support for rts5208 and rts5288")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
adb77ab0a1
commit
7f7aeea7cf
1 changed files with 2 additions and 1 deletions
|
@ -2821,6 +2821,7 @@ static int ms_build_l2p_tbl(struct rtsx_chip *chip, int seg_no)
|
||||||
int reset_ms_card(struct rtsx_chip *chip)
|
int reset_ms_card(struct rtsx_chip *chip)
|
||||||
{
|
{
|
||||||
struct ms_info *ms_card = &chip->ms_card;
|
struct ms_info *ms_card = &chip->ms_card;
|
||||||
|
int seg_no = ms_card->total_block / 512 - 1;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
memset(ms_card, 0, sizeof(struct ms_info));
|
memset(ms_card, 0, sizeof(struct ms_info));
|
||||||
|
@ -2863,7 +2864,7 @@ int reset_ms_card(struct rtsx_chip *chip)
|
||||||
/* Build table for the last segment,
|
/* Build table for the last segment,
|
||||||
* to check if L2P table block exists, erasing it
|
* to check if L2P table block exists, erasing it
|
||||||
*/
|
*/
|
||||||
retval = ms_build_l2p_tbl(chip, ms_card->total_block / 512 - 1);
|
retval = ms_build_l2p_tbl(chip, seg_no);
|
||||||
if (retval != STATUS_SUCCESS) {
|
if (retval != STATUS_SUCCESS) {
|
||||||
rtsx_trace(chip);
|
rtsx_trace(chip);
|
||||||
return STATUS_FAIL;
|
return STATUS_FAIL;
|
||||||
|
|
Loading…
Reference in a new issue