diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2016-11-29 12:09:11 +0200 |
---|---|---|
committer | Leonard Crestez <leonard.crestez@nxp.com> | 2018-08-24 12:41:33 +0300 |
commit | 22d5f715bd869d42f9fc5537a378d240e9d4da79 (patch) | |
tree | f79b4bd515d78770160c64f13df9e72e952c26c0 | |
parent | 95337927f82bdedb9633c2d36e924eaf89fbc6b6 (diff) |
mmc: queue: Factor out mmc_queue_alloc_bounce_bufs()
In preparation for supporting a queue of requests, factor out
mmc_queue_alloc_bounce_bufs().
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Harjani Ritesh <riteshh@codeaurora.org>
[Ulf: Fixed compiler warning]
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
(cherry picked from commit c853982ece93da10e508a5dab621478623deb324)
-rw-r--r-- | drivers/mmc/card/queue.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c index 010888d8d97c..cca143afd12f 100644 --- a/drivers/mmc/card/queue.c +++ b/drivers/mmc/card/queue.c @@ -186,6 +186,33 @@ static void mmc_queue_setup_discard(struct request_queue *q, queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, q); } +#ifdef CONFIG_MMC_BLOCK_BOUNCE +static bool mmc_queue_alloc_bounce_bufs(struct mmc_queue *mq, + unsigned int bouncesz) +{ + struct mmc_queue_req *mqrq_cur = mq->mqrq_cur; + struct mmc_queue_req *mqrq_prev = mq->mqrq_prev; + + mqrq_cur->bounce_buf = kmalloc(bouncesz, GFP_KERNEL); + if (!mqrq_cur->bounce_buf) { + pr_warn("%s: unable to allocate bounce cur buffer\n", + mmc_card_name(mq->card)); + return false; + } + + mqrq_prev->bounce_buf = kmalloc(bouncesz, GFP_KERNEL); + if (!mqrq_prev->bounce_buf) { + pr_warn("%s: unable to allocate bounce prev buffer\n", + mmc_card_name(mq->card)); + kfree(mqrq_cur->bounce_buf); + mqrq_cur->bounce_buf = NULL; + return false; + } + + return true; +} +#endif + /** * mmc_init_queue - initialise a queue structure. * @mq: mmc queue @@ -235,24 +262,8 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, if (bouncesz > (host->max_blk_count * 512)) bouncesz = host->max_blk_count * 512; - if (bouncesz > 512) { - mqrq_cur->bounce_buf = kmalloc(bouncesz, GFP_KERNEL); - if (!mqrq_cur->bounce_buf) { - pr_warn("%s: unable to allocate bounce cur buffer\n", - mmc_card_name(card)); - } else { - mqrq_prev->bounce_buf = - kmalloc(bouncesz, GFP_KERNEL); - if (!mqrq_prev->bounce_buf) { - pr_warn("%s: unable to allocate bounce prev buffer\n", - mmc_card_name(card)); - kfree(mqrq_cur->bounce_buf); - mqrq_cur->bounce_buf = NULL; - } - } - } - - if (mqrq_cur->bounce_buf && mqrq_prev->bounce_buf) { + if (bouncesz > 512 && + mmc_queue_alloc_bounce_bufs(mq, bouncesz)) { blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_ANY); blk_queue_max_hw_sectors(mq->queue, bouncesz / 512); blk_queue_max_segments(mq->queue, bouncesz / 512); |