c
#define SAFE_INDEX_START 1000
#define SAFE_INDEX_END 1000000

static int alloc_safe_index(void) {
    int index;
    do {
        index = ida_alloc_range(&ida_index, SAFE_INDEX_START, SAFE_INDEX_END, GFP_KERNEL);
    } while (index == -ENOSPC);
    return index;
}

// Then use this function:
index = alloc_safe_index();
if (index < 0) {
    pr_warn("%s: failed to allocate safe index!\n", name);
    rc = -ENOMEM;
    goto err;
}
