From patchwork Mon Mar 18 21:17:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10858567 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 0C1341575 for ; Mon, 18 Mar 2019 21:17:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E832B28796 for ; Mon, 18 Mar 2019 21:17:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6B1F2905B; Mon, 18 Mar 2019 21:17:18 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 65A4C294F0 for ; Mon, 18 Mar 2019 21:17:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727422AbfCRVRQ (ORCPT ); Mon, 18 Mar 2019 17:17:16 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:51020 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727202AbfCRVRQ (ORCPT ); Mon, 18 Mar 2019 17:17:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LosKC8rr3Iby31JkBz3FPdvI2FsSt37/CGzxL6YJ0pU=; b=mQm0HEqjx7eo/pDP9QYyuGl+t dMNx44We2hu3z6ZqtF9/wEobLMj+np33xC3k/PyCV/szfUcRsPq/cur8OQMWaa/FTPCSINURdAlRq AixcjNhAtLcPnkPfQAULONKyxFO11qNaCrxP+3ULkgE+6EkEZ9gwr2XoGDwyb5fdf5XcQlSJ4O+dg 9Ro+agfoLwgn9aclXpTgsQcI2ntfyIHmXP334/gVf5YAozZmutWPtcq6eeq/zavdDUWodXCF07MqI sX3zthzwTl6V3K2TJiv2MT/3aqF9yT3bZH71Fm6qhZRx4xGVqmr6TSGEd63NdJjosIRch+B0sirIb M8vx4MU+w==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1h5zdE-0000v6-2l; Mon, 18 Mar 2019 21:17:16 +0000 From: Matthew Wilcox To: linux-usb@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH 4/4] usb/serial: Convert serial_minors to XArray Date: Mon, 18 Mar 2019 14:17:13 -0700 Message-Id: <20190318211713.3462-5-willy@infradead.org> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20190318211713.3462-1-willy@infradead.org> References: <20190318211713.3462-1-willy@infradead.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Matthew Wilcox --- drivers/usb/serial/usb-serial.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 7e89efbf2c28..ad8b9cb17ca5 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -49,7 +49,7 @@ drivers depend on it. */ -static DEFINE_IDR(serial_minors); +static DEFINE_XARRAY_ALLOC(serial_minors); static DEFINE_MUTEX(table_lock); static LIST_HEAD(usb_serial_driver_list); @@ -64,7 +64,7 @@ struct usb_serial_port *usb_serial_port_get_by_minor(unsigned minor) struct usb_serial_port *port; mutex_lock(&table_lock); - port = idr_find(&serial_minors, minor); + port = xa_load(&serial_minors, minor); if (!port) goto exit; @@ -85,18 +85,18 @@ static int allocate_minors(struct usb_serial *serial, int num_ports) { struct usb_serial_port *port; unsigned int i, j; - int minor; + int err; dev_dbg(&serial->interface->dev, "%s %d\n", __func__, num_ports); mutex_lock(&table_lock); for (i = 0; i < num_ports; ++i) { port = serial->port[i]; - minor = idr_alloc(&serial_minors, port, 0, - USB_SERIAL_TTY_MINORS, GFP_KERNEL); - if (minor < 0) + err = xa_alloc(&serial_minors, &port->minor, port, + XA_LIMIT(0, USB_SERIAL_TTY_MINORS - 1), + GFP_KERNEL); + if (err < 0) goto error; - port->minor = minor; port->port_number = i; } serial->minors_reserved = 1; @@ -105,9 +105,9 @@ static int allocate_minors(struct usb_serial *serial, int num_ports) error: /* unwind the already allocated minors */ for (j = 0; j < i; ++j) - idr_remove(&serial_minors, serial->port[j]->minor); + xa_erase(&serial_minors, serial->port[j]->minor); mutex_unlock(&table_lock); - return minor; + return err; } static void release_minors(struct usb_serial *serial) @@ -116,7 +116,7 @@ static void release_minors(struct usb_serial *serial) mutex_lock(&table_lock); for (i = 0; i < serial->num_ports; ++i) - idr_remove(&serial_minors, serial->port[i]->minor); + xa_erase(&serial_minors, serial->port[i]->minor); mutex_unlock(&table_lock); serial->minors_reserved = 0; } @@ -1271,7 +1271,6 @@ static void __exit usb_serial_exit(void) tty_unregister_driver(usb_serial_tty_driver); put_tty_driver(usb_serial_tty_driver); bus_unregister(&usb_serial_bus_type); - idr_destroy(&serial_minors); }