All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Keeping <john@metanate.com>
To: linux-usb@vger.kernel.org
Cc: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, John Keeping <john@metanate.com>
Subject: [PATCH 2/6] USB: gadget: f_hid: switch to IDR for tracking minors
Date: Thu, 24 Oct 2019 17:45:34 +0100	[thread overview]
Message-ID: <20191024164538.3161474-3-john@metanate.com> (raw)
In-Reply-To: <20191024164538.3161474-1-john@metanate.com>

In the following commits, we are going to move the cdev allocation up to
the module initialisation, and will look up the associated f_hidg
structure from the open operation.

Start preparing for this by switching from IDA to IDR.

Signed-off-by: John Keeping <john@metanate.com>
---
 drivers/usb/gadget/function/f_hid.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index e9e45f9eae80..838256086bd2 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -24,8 +24,8 @@
 
 static int major, minors;
 static struct class *hidg_class;
-static DEFINE_IDA(hidg_ida);
-static DEFINE_MUTEX(hidg_ida_lock); /* protects access to hidg_ida */
+static DEFINE_IDR(hidg_idr);
+static DEFINE_MUTEX(hidg_idr_lock); /* protects access to hidg_idr */
 
 /*-------------------------------------------------------------------------*/
 /*                            HID gadget struct                            */
@@ -851,9 +851,9 @@ static inline int hidg_get_minor(void)
 {
 	int ret;
 
-	ret = ida_simple_get(&hidg_ida, 0, 0, GFP_KERNEL);
+	ret = idr_alloc(&hidg_idr, NULL, 0, 0, GFP_KERNEL);
 	if (ret >= HIDG_MINORS) {
-		ida_simple_remove(&hidg_ida, ret);
+		idr_remove(&hidg_idr, ret);
 		ret = -ENODEV;
 	}
 
@@ -996,7 +996,7 @@ static const struct config_item_type hid_func_type = {
 
 static inline void hidg_put_minor(int minor)
 {
-	ida_simple_remove(&hidg_ida, minor);
+	idr_remove(&hidg_idr, minor);
 }
 
 static void hidg_free_inst(struct usb_function_instance *f)
@@ -1005,9 +1005,9 @@ static void hidg_free_inst(struct usb_function_instance *f)
 
 	opts = container_of(f, struct f_hid_opts, func_inst);
 
-	mutex_lock(&hidg_ida_lock);
+	mutex_lock(&hidg_idr_lock);
 	hidg_put_minor(opts->minor);
-	mutex_unlock(&hidg_ida_lock);
+	mutex_unlock(&hidg_idr_lock);
 
 	if (opts->report_desc_alloc)
 		kfree(opts->report_desc);
@@ -1027,7 +1027,7 @@ static struct usb_function_instance *hidg_alloc_inst(void)
 	opts->func_inst.free_func_inst = hidg_free_inst;
 	ret = &opts->func_inst;
 
-	mutex_lock(&hidg_ida_lock);
+	mutex_lock(&hidg_idr_lock);
 
 	opts->minor = hidg_get_minor();
 	if (opts->minor < 0) {
@@ -1038,7 +1038,7 @@ static struct usb_function_instance *hidg_alloc_inst(void)
 	config_group_init_type_name(&opts->func_inst.group, "", &hid_func_type);
 
 unlock:
-	mutex_unlock(&hidg_ida_lock);
+	mutex_unlock(&hidg_idr_lock);
 	return ret;
 }
 
-- 
2.23.0


  parent reply	other threads:[~2019-10-24 17:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24 16:45 [PATCH 0/6] USB: gadget: f_hid: fix lifetime issues John Keeping
2019-10-24 16:45 ` [PATCH 1/6] USB: gadget: f_hid: move chardev setup to module init John Keeping
2019-10-27 17:13   ` kbuild test robot
2019-10-27 17:13     ` kbuild test robot
2019-10-24 16:45 ` John Keeping [this message]
2019-10-24 16:45 ` [PATCH 3/6] USB: gadget: f_hid: find f_hidg by IDR lookup on open John Keeping
2019-10-24 16:45 ` [PATCH 4/6] USB: gadget: f_hid: decouple cdev from f_hidg lifetime John Keeping
2019-10-24 16:45 ` [PATCH 5/6] USB: gadget: f_hid: refcount f_hidg structure John Keeping
2019-10-24 16:45 ` [PATCH 6/6] USB: gadget: f_hid: return ENODEV from read/write after deletion John Keeping
2019-10-28 11:42 ` [PATCH v2 0/6] USB: gadget: f_hid: fix lifetime issues John Keeping
2019-10-28 11:42   ` [PATCH v2 1/6] USB: gadget: f_hid: move chardev setup to module init John Keeping
2019-10-28 11:42   ` [PATCH v2 2/6] USB: gadget: f_hid: switch to IDR for tracking minors John Keeping
2019-10-28 11:42   ` [PATCH v2 3/6] USB: gadget: f_hid: find f_hidg by IDR lookup on open John Keeping
2019-10-28 11:42   ` [PATCH v2 4/6] USB: gadget: f_hid: decouple cdev from f_hidg lifetime John Keeping
2019-10-28 11:42   ` [PATCH v2 5/6] USB: gadget: f_hid: refcount f_hidg structure John Keeping
2019-10-28 11:42   ` [PATCH v2 6/6] USB: gadget: f_hid: return ENODEV from read/write after deletion John Keeping

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191024164538.3161474-3-john@metanate.com \
    --to=john@metanate.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.