Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: block: Initialize ret in mmc_blk_issue_drv_op() for MMC_DRV_OP_IOCTL

With gcc 4.1.2:

drivers/mmc/core/block.c: In function ‘mmc_blk_issue_drv_op’:
drivers/mmc/core/block.c:1178: warning: ‘ret’ may be used uninitialized in this function

Indeed, for MMC_DRV_OP_IOCTL, if mq_rq->ioc_count is zero, an
uninitialized value will be stored in mq_rq->drv_op_result and passed to
blk_end_request_all().

Can mq_rq->ioc_count be zero?
- mmc_blk_ioctl_cmd() sets ioc_count to 1, so this is safe,
- mmc_blk_ioctl_multi_cmd() obtains ioc_count from user space in
response to the MMC_IOC_MULTI_CMD ioctl, and does allow zero.

Initialize ret to zero to fix this for current and future callers.

Fixes: 0493f6fe5bdee8ac ("mmc: block: Move boot partition locking into a driver op")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Geert Uytterhoeven and committed by
Ulf Hansson
7432b49b 17753d16

+1 -1
+1 -1
drivers/mmc/core/block.c
··· 1182 1182 1183 1183 switch (mq_rq->drv_op) { 1184 1184 case MMC_DRV_OP_IOCTL: 1185 - for (i = 0; i < mq_rq->ioc_count; i++) { 1185 + for (i = 0, ret = 0; i < mq_rq->ioc_count; i++) { 1186 1186 ret = __mmc_blk_ioctl_cmd(card, md, mq_rq->idata[i]); 1187 1187 if (ret) 1188 1188 break;