mmc: block: return errorcode from mmc_sd_num_wr_blocks()
mmc_sd_num_wr_blocks() has an interesting construction that saves one return argument by casting (u32)-1 as error code if something goes wrong. This is however a bit confusing when the normal kernel pattern is to return an int error code on success. So instead pass a variable "blocks" that the function can fill in with the number of successfully transferred blocks and return an integer as error code. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> [Ulf: Changed a return code to -EIO, reported by Dan Carpenter and fixed by Linus Walleij]
This commit is contained in:
parent
9491be5ff0
commit
169f03a064
|
@ -763,7 +763,7 @@ static inline int mmc_blk_part_switch(struct mmc_card *card,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
|
static int mmc_sd_num_wr_blocks(struct mmc_card *card, u32 *written_blocks)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
u32 result;
|
u32 result;
|
||||||
|
@ -781,9 +781,9 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
|
||||||
|
|
||||||
err = mmc_wait_for_cmd(card->host, &cmd, 0);
|
err = mmc_wait_for_cmd(card->host, &cmd, 0);
|
||||||
if (err)
|
if (err)
|
||||||
return (u32)-1;
|
return err;
|
||||||
if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
|
if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
|
||||||
return (u32)-1;
|
return -EIO;
|
||||||
|
|
||||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||||
|
|
||||||
|
@ -803,7 +803,7 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
|
||||||
|
|
||||||
blocks = kmalloc(4, GFP_KERNEL);
|
blocks = kmalloc(4, GFP_KERNEL);
|
||||||
if (!blocks)
|
if (!blocks)
|
||||||
return (u32)-1;
|
return -ENOMEM;
|
||||||
|
|
||||||
sg_init_one(&sg, blocks, 4);
|
sg_init_one(&sg, blocks, 4);
|
||||||
|
|
||||||
|
@ -813,9 +813,11 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
|
||||||
kfree(blocks);
|
kfree(blocks);
|
||||||
|
|
||||||
if (cmd.error || data.error)
|
if (cmd.error || data.error)
|
||||||
result = (u32)-1;
|
return -EIO;
|
||||||
|
|
||||||
return result;
|
*written_blocks = result;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_card_status(struct mmc_card *card, u32 *status, int retries)
|
static int get_card_status(struct mmc_card *card, u32 *status, int retries)
|
||||||
|
@ -1576,9 +1578,10 @@ static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
|
||||||
*/
|
*/
|
||||||
if (mmc_card_sd(card)) {
|
if (mmc_card_sd(card)) {
|
||||||
u32 blocks;
|
u32 blocks;
|
||||||
|
int err;
|
||||||
|
|
||||||
blocks = mmc_sd_num_wr_blocks(card);
|
err = mmc_sd_num_wr_blocks(card, &blocks);
|
||||||
if (blocks != (u32)-1) {
|
if (!err) {
|
||||||
ret = blk_end_request(req, 0, blocks << 9);
|
ret = blk_end_request(req, 0, blocks << 9);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue