From patchwork Mon Apr 18 11:43:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 66021 Delivered-To: patches@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1233958qge; Mon, 18 Apr 2016 04:44:14 -0700 (PDT) X-Received: by 10.112.7.137 with SMTP id j9mr13567605lba.4.1460979851619; Mon, 18 Apr 2016 04:44:11 -0700 (PDT) Return-Path: Received: from mail-lf0-x230.google.com (mail-lf0-x230.google.com. [2a00:1450:4010:c07::230]) by mx.google.com with ESMTPS id t126si19548771lfd.95.2016.04.18.04.44.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Apr 2016 04:44:11 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::230 as permitted sender) client-ip=2a00:1450:4010:c07::230; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::230 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x230.google.com with SMTP id g184so213136500lfb.3 for ; Mon, 18 Apr 2016 04:44:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=z6omt0wfecyFvi7m8qU3XLHzigOcV6ShNET/zAg94KY=; b=HpJQONRfizBgY6EWXzMTfoKcThewLSp3bUo/gd6JBLIsqbqbqAOz8fePg4Tv7TgM8Q HSv6zdM2GJYT+PftREDPz8b8LKXOhI40h+9weWLWl17PtOL5Ll9YhhYvb0JuE/qtdWz+ iwAsPTsOk0X3groiDS3a4OoKvCdcLW23E4qn4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=z6omt0wfecyFvi7m8qU3XLHzigOcV6ShNET/zAg94KY=; b=mOFlWtAnWO+0RqFICJ/AUIzL/DfdVH/8qG2RRMrrvROgayFFCzqKQhWkd3ofNEX8MS eYoibWSj1usllOJx8PjmgM7DXXmoh73WA3lANNYvXLmNDukS2E+c6MeeeqkeXd7S/77e ZnOzczSg6qEfk7ek5wro9Nolb3KjTdLhvYGytU/H2DtJaKp3rhOuhpOZJ/RIvCXDiBvw frGfXSlBaF4RSuk+LKM4OikVl+kKOAc0Hg+eh4cTCh/1gjtAFm2Fgmz9AhWn/bA2yYMN BUFeazunksPITWgRhPjNZx01EL7hXhvhtIJMyj7UblbBcz5fu6UNC5Vj6FpmRCdxiwjJ L3Sw== X-Gm-Message-State: AOPr4FVEcDmYZpueI+2dsGMc9UVwwnoAhOYt/0qPXh4oHvUXHD2/YGfMmzv6cAWUz5xeXsnZ6L4= X-Received: by 10.112.63.196 with SMTP id i4mr14264869lbs.93.1460979851319; Mon, 18 Apr 2016 04:44:11 -0700 (PDT) Return-Path: Received: from uffe-Latitude-E6430s.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id jo1sm10010232lbc.3.2016.04.18.04.44.09 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 18 Apr 2016 04:44:10 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Subject: [PATCH 3/3] mmc: block: Convert to IDA for partition device indexes Date: Mon, 18 Apr 2016 13:43:54 +0200 Message-Id: <1460979834-24582-3-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460979834-24582-1-git-send-email-ulf.hansson@linaro.org> References: <1460979834-24582-1-git-send-email-ulf.hansson@linaro.org> Instead of using an mmc specific implementation to deal with indexes through a BITMAP, let's convert to use the IDA library. Signed-off-by: Ulf Hansson --- drivers/mmc/card/block.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) -- 1.9.1 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index 9aaf22e..9ce6792 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -78,14 +79,14 @@ static int perdev_minors = CONFIG_MMC_BLOCK_MINORS; /* * We've only got one major, so number of mmcblk devices is * limited to (1 << 20) / number of minors per device. It is also - * currently limited by the size of the static bitmaps below. + * limited by the MAX_DEVICES below. */ static int max_devices; #define MAX_DEVICES 256 -/* TODO: Replace these with struct ida */ -static DECLARE_BITMAP(dev_use, MAX_DEVICES); +static DEFINE_IDA(mmc_blk_ida); +static DEFINE_SPINLOCK(mmc_blk_lock); /* * There is one mmc_blk_data per slot. @@ -178,7 +179,9 @@ static void mmc_blk_put(struct mmc_blk_data *md) int devidx = mmc_get_devidx(md->disk); blk_cleanup_queue(md->queue.queue); - __clear_bit(devidx, dev_use); + spin_lock(&mmc_blk_lock); + ida_remove(&mmc_blk_ida, devidx); + spin_unlock(&mmc_blk_lock); put_disk(md->disk); kfree(md); @@ -2189,10 +2192,23 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, struct mmc_blk_data *md; int devidx, ret; - devidx = find_first_zero_bit(dev_use, max_devices); - if (devidx >= max_devices) - return ERR_PTR(-ENOSPC); - __set_bit(devidx, dev_use); +again: + if (!ida_pre_get(&mmc_blk_ida, GFP_KERNEL)) + return ERR_PTR(-ENOMEM); + + spin_lock(&mmc_blk_lock); + ret = ida_get_new(&mmc_blk_ida, &devidx); + spin_unlock(&mmc_blk_lock); + + if (ret == -EAGAIN) + goto again; + else if (ret) + return ERR_PTR(ret); + + if (devidx >= max_devices) { + ret = -ENOSPC; + goto out; + } md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL); if (!md) { @@ -2289,7 +2305,9 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, err_kfree: kfree(md); out: - __clear_bit(devidx, dev_use); + spin_lock(&mmc_blk_lock); + ida_remove(&mmc_blk_ida, devidx); + spin_unlock(&mmc_blk_lock); return ERR_PTR(ret); }