Re: [PATCH] mmc: core: Remove usage of the deprecated ida_simple_xx() API

From: Ulf Hansson
Date: Tue Jan 30 2024 - 07:15:30 EST


On Sun, 14 Jan 2024 at 16:02, Christophe JAILLET
<christophe.jaillet@xxxxxxxxxx> wrote:
>
> ida_alloc() and ida_free() should be preferred to the deprecated
> ida_simple_get() and ida_simple_remove().
>
> Note that the upper limit of ida_simple_get() is exclusive, but the one of
> ida_alloc_range()/ida_alloc_max() is inclusive. So a -1 has been added when
> needed.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>

Applied for next, thanks!

Kind regards
Uffe


> ---
> drivers/mmc/core/block.c | 12 ++++++------
> drivers/mmc/core/host.c | 5 +++--
> 2 files changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 32d49100dff5..a9b60b91e32f 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -206,7 +206,7 @@ static void mmc_blk_kref_release(struct kref *ref)
> int devidx;
>
> devidx = mmc_get_devidx(md->disk);
> - ida_simple_remove(&mmc_blk_ida, devidx);
> + ida_free(&mmc_blk_ida, devidx);
>
> mutex_lock(&open_lock);
> md->disk->private_data = NULL;
> @@ -2467,7 +2467,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
> bool cache_enabled = false;
> bool fua_enabled = false;
>
> - devidx = ida_simple_get(&mmc_blk_ida, 0, max_devices, GFP_KERNEL);
> + devidx = ida_alloc_max(&mmc_blk_ida, max_devices - 1, GFP_KERNEL);
> if (devidx < 0) {
> /*
> * We get -ENOSPC because there are no more any available
> @@ -2577,7 +2577,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
> err_kfree:
> kfree(md);
> out:
> - ida_simple_remove(&mmc_blk_ida, devidx);
> + ida_free(&mmc_blk_ida, devidx);
> return ERR_PTR(ret);
> }
>
> @@ -2703,7 +2703,7 @@ static void mmc_blk_rpmb_device_release(struct device *dev)
> {
> struct mmc_rpmb_data *rpmb = dev_get_drvdata(dev);
>
> - ida_simple_remove(&mmc_rpmb_ida, rpmb->id);
> + ida_free(&mmc_rpmb_ida, rpmb->id);
> kfree(rpmb);
> }
>
> @@ -2719,13 +2719,13 @@ static int mmc_blk_alloc_rpmb_part(struct mmc_card *card,
> struct mmc_rpmb_data *rpmb;
>
> /* This creates the minor number for the RPMB char device */
> - devidx = ida_simple_get(&mmc_rpmb_ida, 0, max_devices, GFP_KERNEL);
> + devidx = ida_alloc_max(&mmc_rpmb_ida, max_devices - 1, GFP_KERNEL);
> if (devidx < 0)
> return devidx;
>
> rpmb = kzalloc(sizeof(*rpmb), GFP_KERNEL);
> if (!rpmb) {
> - ida_simple_remove(&mmc_rpmb_ida, devidx);
> + ida_free(&mmc_rpmb_ida, devidx);
> return -ENOMEM;
> }
>
> diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
> index cf396e8f34e9..7cc9a33d28ca 100644
> --- a/drivers/mmc/core/host.c
> +++ b/drivers/mmc/core/host.c
> @@ -76,7 +76,7 @@ static void mmc_host_classdev_release(struct device *dev)
> struct mmc_host *host = cls_dev_to_mmc_host(dev);
> wakeup_source_unregister(host->ws);
> if (of_alias_get_id(host->parent->of_node, "mmc") < 0)
> - ida_simple_remove(&mmc_host_ida, host->index);
> + ida_free(&mmc_host_ida, host->index);
> kfree(host);
> }
>
> @@ -538,7 +538,8 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
> min_idx = mmc_first_nonreserved_index();
> max_idx = 0;
>
> - index = ida_simple_get(&mmc_host_ida, min_idx, max_idx, GFP_KERNEL);
> + index = ida_alloc_range(&mmc_host_ida, min_idx, max_idx - 1,
> + GFP_KERNEL);
> if (index < 0) {
> kfree(host);
> return NULL;
> --
> 2.43.0
>