From patchwork Mon Feb 4 21:17:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10796647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5457913B4 for ; Mon, 4 Feb 2019 21:18:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 451C92B1EB for ; Mon, 4 Feb 2019 21:18:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 396A32B5AE; Mon, 4 Feb 2019 21:18:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7D302B1EB for ; Mon, 4 Feb 2019 21:18:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729501AbfBDVSE (ORCPT ); Mon, 4 Feb 2019 16:18:04 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44254 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729343AbfBDVSD (ORCPT ); Mon, 4 Feb 2019 16:18:03 -0500 Received: by mail-pl1-f196.google.com with SMTP id p4so503471plq.11 for ; Mon, 04 Feb 2019 13:18:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iyT4w/yRYWxwv+HPRN3tEUx7ear6GsieNYA5NP+ZN+Q=; b=dpd2ftUET9PKDMYtzOxU3wGjGGuQ1ped0QMUs7dmVF6ArXxxV+YYEwFEE9uj5AAll9 /hUqmRoz/WBq4AXw1GRDnl8WiNsPiK3gnjwsQ3Z34gsjIocRT305g27kJcA7Rb1bXnj1 P3mvl4z1cyWSgfB3QQVrRnzN/lzfbw3OpzCI7QtGuNXWoR3OkMLJm4fdFxTBetsdEoVe N2QFJnLKvJw52uUlrbu+66jRQUwyAPmwisjpAs5leBy8P+sQs3C+p0AlESC0IbbE99vv k/6sOgE08VDVlmLH+ZFAPO5dcT76ZTBJ5QrcthLVPvayMKBiybLnME/TPi1u2UX0PuW6 kkXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iyT4w/yRYWxwv+HPRN3tEUx7ear6GsieNYA5NP+ZN+Q=; b=mNupOGspcLesKtbTiaW4gP1+hMJc6zY54tUD1o/Zs0mL94OsCa6lyBsymEuAGqJlln Jywuje0To5c0MPRfNYMcIfLVSAy8MY0+cBGhuYQ0oe+G9XwuCrMDdnWFpzdcqThijMzF MeCuc+JYOtml37bx2aBXGisDAsdo8jkihwQGMuk/U3vWpg3zxsJqg2UR7VE5I0Knf4YQ TI8+FZ1/LVQCoewqKHQrVaafDYASSGS6pv3LOVnB8ihNk0zhak8GhBpBKfI4Kl0O7ySZ uCLJR0jE0l+KazSoDdW64qFeHgC3wwW34zcOT6FkFMzNrQvamqIQU7vaORZHsQ8YbrqT FeFA== X-Gm-Message-State: AHQUAubI2ZBnVw2DL00w3Zz9miaOmfV70XhUfUokSB9MeiQebAYa63oM GzkP5D6lK5ZXxXBn8/tpgSeA4TponJQ= X-Google-Smtp-Source: AHgI3Iax3YnEEIavQo0jZztSONl9T60qYWIa5sqr579g/dWs0Q5zHh5pfbhyO9yYmXvNQTObtwp4ww== X-Received: by 2002:a17:902:7044:: with SMTP id h4mr1440797plt.35.1549315082313; Mon, 04 Feb 2019 13:18:02 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id q75sm1284517pfa.38.2019.02.04.13.18.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 13:18:00 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1gqlct-0005Kf-HT; Mon, 04 Feb 2019 14:17:59 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH 5/8] RDMA/device: Use an ida instead of a free page in alloc_name Date: Mon, 4 Feb 2019 14:17:48 -0700 Message-Id: <20190204211751.19001-6-jgg@ziepe.ca> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204211751.19001-1-jgg@ziepe.ca> References: <20190204211751.19001-1-jgg@ziepe.ca> MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jason Gunthorpe ida is the proper data structure to hold list of clustered small integers and then allocate an unused integer. Get rid of the convoluted and limited open-coded bitmap. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/core/device.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index c846b5f7abb9d8..300a36beaa300c 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -213,30 +213,36 @@ int ib_device_rename(struct ib_device *ibdev, const char *name) static int alloc_name(struct ib_device *ibdev, const char *name) { - unsigned long *inuse; struct ib_device *device; + struct ida inuse; + int rc; int i; - inuse = (unsigned long *) get_zeroed_page(GFP_KERNEL); - if (!inuse) - return -ENOMEM; - + ida_init(&inuse); list_for_each_entry(device, &device_list, core_list) { char buf[IB_DEVICE_NAME_MAX]; if (sscanf(dev_name(&device->dev), name, &i) != 1) continue; - if (i < 0 || i >= PAGE_SIZE * 8) + if (i < 0 || i >= INT_MAX) continue; snprintf(buf, sizeof buf, name, i); - if (!strcmp(buf, dev_name(&device->dev))) - set_bit(i, inuse); + if (strcmp(buf, dev_name(&device->dev)) != 0) + continue; + + rc = ida_alloc_range(&inuse, i, i, GFP_KERNEL); + if (rc < 0) + goto out; } - i = find_first_zero_bit(inuse, PAGE_SIZE * 8); - free_page((unsigned long) inuse); + rc = ida_alloc(&inuse, GFP_KERNEL); + if (rc < 0) + goto out; - return dev_set_name(&ibdev->dev, name, i); + rc = dev_set_name(&ibdev->dev, name, rc); +out: + ida_destroy(&inuse); + return rc; } static void ib_device_release(struct device *device)