All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Nazarewicz <m.nazarewicz@samsung.com>
To: linux-usb@vger.kernel.org, linux-usb@vger.kernel.org
Cc: David Brownell <dbrownell@users.sourceforge.net>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCHv4 04/13] USB: gadget: composite: usb_string_ids_*() functions added
Date: Mon, 07 Jun 2010 14:39:51 +0200	[thread overview]
Message-ID: <b34cbaab37bf0590cb254a03478c5297bc4a1723.1275906835.git.m.nazarewicz@samsung.com> (raw)
In-Reply-To: <897d8ae37d4fa2fdb7dad8787add81c720581313.1275906835.git.m.nazarewicz@samsung.com>

usb_string_ids_tab() and usb_string_ids_n() functions added to
the composite framework.  The first accepts an array of
usb_string object and for each registeres a string id and the
second registeres a given number of ids and returns the first.

This may simplify string ids registration since gadgets and
composite functions won't have to call usb_string_id() several
times and each time check for errer status -- all this will be
done with a single call.

Signed-off-by: Michal Nazarewicz <m.nazarewicz@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 drivers/usb/gadget/composite.c |   71 +++++++++++++++++++++++++++++++++++++--
 include/linux/usb/composite.h  |    4 ++
 2 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 391d169..125167e 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -673,20 +673,83 @@ static int get_string(struct usb_composite_dev *cdev,
  * string IDs.  Drivers for functions, configurations, or gadgets will
  * then store that ID in the appropriate descriptors and string table.
  *
- * All string identifier should be allocated using this routine, to
- * ensure that for example different functions don't wrongly assign
- * different meanings to the same identifier.
+ * All string identifier should be allocated using this,
+ * @usb_string_ids_tab() or @usb_string_ids_n() routine, to ensure
+ * that for example different functions don't wrongly assign different
+ * meanings to the same identifier.
  */
 int usb_string_id(struct usb_composite_dev *cdev)
 {
 	if (cdev->next_string_id < 254) {
-		/* string id 0 is reserved */
+		/* string id 0 is reserved by USB spec for list of
+		 * supported languages */
+		/* 255 reserved as well? -- mina86 */
 		cdev->next_string_id++;
 		return cdev->next_string_id;
 	}
 	return -ENODEV;
 }
 
+/**
+ * usb_string_ids() - allocate unused string IDs in batch
+ * @cdev: the device whose string descriptor IDs are being allocated
+ * @str: an array of usb_string objects to assign numbers to
+ * Context: single threaded during gadget setup
+ *
+ * @usb_string_ids() is called from bind() callbacks to allocate
+ * string IDs.  Drivers for functions, configurations, or gadgets will
+ * then copy IDs from the string table to the appropriate descriptors
+ * and string table for other languages.
+ *
+ * All string identifier should be allocated using this,
+ * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
+ * example different functions don't wrongly assign different meanings
+ * to the same identifier.
+ */
+int usb_string_ids_tab(struct usb_composite_dev *cdev, struct usb_string *str)
+{
+	int next = cdev->next_string_id;
+
+	for (; str->s; ++str) {
+		if (unlikely(next >= 254))
+			return -ENODEV;
+		str->id = ++next;
+	}
+
+	cdev->next_string_id = next;
+
+	return 0;
+}
+
+/**
+ * usb_string_ids_n() - allocate unused string IDs in batch
+ * @cdev: the device whose string descriptor IDs are being allocated
+ * @n: number of string IDs to allocate
+ * Context: single threaded during gadget setup
+ *
+ * Returns the first requested ID.  This ID and next @n-1 IDs are now
+ * valid IDs.  At least providind that @n is non zore because if it
+ * is, returns last requested ID which is now very useful information.
+ *
+ * @usb_string_ids_n() is called from bind() callbacks to allocate
+ * string IDs.  Drivers for functions, configurations, or gadgets will
+ * then store that ID in the appropriate descriptors and string table.
+ *
+ * All string identifier should be allocated using this,
+ * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
+ * example different functions don't wrongly assign different meanings
+ * to the same identifier.
+ */
+int usb_string_ids_n(struct usb_composite_dev *c, unsigned n)
+{
+	unsigned next = c->next_string_id;
+	if (unlikely(n > 254 || (unsigned)next + n > 254))
+		return -ENODEV;
+	c->next_string_id += n;
+	return next + 1;
+}
+
+
 /*-------------------------------------------------------------------------*/
 
 static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req)
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 139353e..f378075 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -342,6 +342,10 @@ struct usb_composite_dev {
 };
 
 extern int usb_string_id(struct usb_composite_dev *c);
+extern int usb_string_ids_tab(struct usb_composite_dev *c,
+			      struct usb_string *str);
+extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n);
+
 
 /* messaging utils */
 #define DBG(d, fmt, args...) \
-- 
1.7.1


  reply	other threads:[~2010-06-07 12:41 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-07 12:39 [PATCHv4 00/13] USB improvements and cleanpus, g_multi install mode Michal Nazarewicz
2010-06-07 12:39 ` [PATCHv4 01/13] USB: gadget: g_mass_storage: static data instead of dynamic allocation Michal Nazarewicz
2010-06-07 12:39   ` [PATCHv4 02/13] USB: gadget: f_mass_storage: fsg_add() renamed to fsg_bind_config() Michal Nazarewicz
2010-06-07 12:39     ` [PATCHv4 03/13] USB: gadget: f_fs: functionfs_add() renamed to functionfs_bind_config() Michal Nazarewicz
2010-06-07 12:39       ` Michal Nazarewicz [this message]
2010-06-07 12:39         ` [PATCHv4 05/13] USB: gadget: f_fs: use usb_string_ids_n() Michal Nazarewicz
2010-06-07 12:39           ` [PATCHv4 06/13] USB: gadget: g_multi: code clean up and refactoring Michal Nazarewicz
2010-06-07 12:39             ` [PATCHv4 07/13] USB: gadget: g_ether: updated INF file Michal Nazarewicz
2010-06-07 12:39               ` [PATCHv4 08/13] USB: gadget: g_serial: INF file updated Michal Nazarewicz
2010-06-07 12:39                 ` [PATCHv4 09/13] USB: gadget: g_multi: added documentation and INF files Michal Nazarewicz
2010-06-07 12:39                   ` [PATCHv4 10/13] USB: gadget: g_multi: more configurable Michal Nazarewicz
2010-06-07 12:39                     ` [PATCHv4 11/13] USB: gadget: composite: addad disconnect callback Michal Nazarewicz
2010-06-07 12:39                       ` [PATCHv4 12/13] USB: gadget: f_mass_storage: added eject callback Michal Nazarewicz
2010-06-07 12:40                         ` [PATCHv4 13/13] USB: gadget: g_multi: Install Mode added Michal Nazarewicz
2010-06-14  8:43                         ` [PATCHv4.1 12/13] USB: gadget: f_mass_storage: added eject callback Michal Nazarewicz
2010-06-08 14:02                       ` [PATCHv4 11/13] USB: gadget: composite: addad disconnect callback David Brownell
2010-06-08 13:37                     ` [PATCHv4 10/13] USB: gadget: g_multi: more configurable David Brownell
2010-06-09 10:15                       ` Michał Nazarewicz
2010-06-08 13:13                 ` [PATCHv4 08/13] USB: gadget: g_serial: INF file updated David Brownell
2010-06-08 13:20                   ` Xiaofan Chen
2010-06-09  8:55                   ` Michał Nazarewicz
2010-06-09  9:29                     ` Xiaofan Chen
2010-06-09 10:01                       ` Michał Nazarewicz
2010-06-09 14:59                         ` Greg KH
2010-06-09 15:22                           ` Michał Nazarewicz
2010-06-09 15:33                             ` Greg KH
2010-06-09 15:53                               ` Michał Nazarewicz
2010-06-08 12:57               ` [PATCHv4 07/13] USB: gadget: g_ether: updated INF file David Brownell
2010-06-08 13:17                 ` Xiaofan Chen
2010-06-14  8:43               ` [PATCHv4.1 " Michal Nazarewicz
2010-06-14 11:32                 ` Xiaofan Chen
2010-06-14 19:42                   ` David Brownell
2010-06-14 20:04                     ` Michał Nazarewicz
2010-06-14  8:43         ` [PATCH] USB: gadget: g_fs: code cleanup and bug fixes Michal Nazarewicz
2010-06-14  8:43   ` [PATCHv4.1 01/13] USB: gadget: g_mass_storage: static data instead of dynamic allocation Michal Nazarewicz
2010-06-15 18:55 ` [PATCHv4 00/13] USB improvements and cleanpus, g_multi install mode Greg KH
2010-06-16 10:07   ` [PATCHv5 00/11] g_multi & other improvements and cleanpus Michal Nazarewicz
2010-06-16 10:07     ` [PATCHv5 01/11] USB: gadget: g_mass_storage: static data instead of dynamic allocation Michal Nazarewicz
2010-06-16 10:07       ` [PATCHv5 02/11] USB: gadget: f_mass_storage: fsg_add() renamed to fsg_bind_config() Michal Nazarewicz
2010-06-16 10:07         ` [PATCHv5 03/11] USB: gadget: f_fs: functionfs_add() renamed to functionfs_bind_config() Michal Nazarewicz
2010-06-16 10:07           ` [PATCHv5 04/11] USB: gadget: composite: usb_string_ids_*() functions added Michal Nazarewicz
2010-06-16 10:08             ` [PATCHv5 05/11] USB: gadget: f_fs: use usb_string_ids_n() Michal Nazarewicz
2010-06-16 10:08               ` [PATCHv5 06/11] USB: gadget: g_multi: code clean up and refactoring Michal Nazarewicz
2010-06-16 10:08                 ` [PATCHv5 07/11] USB: gadget: g_ether: updated INF file Michal Nazarewicz
2010-06-16 10:08                   ` [PATCHv5 08/11] USB: gadget: g_serial: INF file updated Michal Nazarewicz
2010-06-16 10:08                     ` [PATCHv5 09/11] USB: gadget: g_multi: added documentation and INF files Michal Nazarewicz
2010-06-16 10:08                       ` [PATCHv5 10/11] USB: gadget: composite: addad disconnect callback Michal Nazarewicz
2010-06-16 10:08                         ` [PATCHv5 11/11] USB: gadget: f_mass_storage: added eject callback Michal Nazarewicz
2010-06-17 11:04                         ` [PATCHv5 10/11] USB: gadget: composite: addad disconnect callback Sergei Shtylyov
2010-06-18 14:19                           ` Sergei Shtylyov
2010-06-16 13:56                     ` [PATCHv5 08/11] USB: gadget: g_serial: INF file updated David Brownell
2010-06-16 14:12                   ` [PATCHv5 07/11] USB: gadget: g_ether: updated INF file David Brownell
2010-06-16 14:41                     ` [PATCHv5.1 " Michal Nazarewicz
2010-06-17 17:51                 ` [PATCHv5 06/11] USB: gadget: g_multi: code clean up and refactoring Greg KH
2010-06-18 10:31                   ` Michał Nazarewicz
2010-06-18 14:39                     ` Greg KH
2010-06-17 17:52     ` [PATCHv5 00/11] g_multi & other improvements and cleanpus Greg KH
2010-06-18 10:31       ` Michał Nazarewicz
     [not found]       ` <2809a031d19ac6ef793d7fe343e225b8d80099c3.1276864406.git.m.nazarewicz@samsung.com>
2010-06-18 12:48         ` [PATCHv6 07/11] USB: gadget: g_ether: updated INF file Michal Nazarewicz
2010-06-18 12:48           ` [PATCHv6 08/11] USB: gadget: g_serial: INF file updated Michal Nazarewicz
2010-06-18 12:48             ` [PATCHv6 09/11] USB: gadget: g_multi: added documentation and INF files Michal Nazarewicz
2010-06-18 12:48               ` [PATCHv6 10/11] USB: gadget: composite: added disconnect callback Michal Nazarewicz
2010-06-18 12:48                 ` [PATCHv6 11/11] USB: gadget: f_mass_storage: added eject callback Michal Nazarewicz
2010-06-18 13:07               ` [PATCHv6.1 09/11] USB: gadget: g_multi: added documentation and INF files Michal Nazarewicz
2010-06-18 15:52                 ` Greg KH
2010-06-18 16:14                   ` Michał Nazarewicz
2010-06-18 15:04       ` [PATCHv6.1 06/11] USB: gadget: g_multi: code clean up and refactoring Michal Nazarewicz
2010-06-18 21:25         ` Sergei Shtylyov
2010-06-21  8:43           ` Michał Nazarewicz
2010-06-14  8:43 [PATCH] USB: gadget: g_fs: possible invalid pointer reference bug fixed Michal Nazarewicz
2010-06-15 10:10 ` Sergei Shtylyov
2010-06-16  9:30   ` Michał Nazarewicz

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=b34cbaab37bf0590cb254a03478c5297bc4a1723.1275906835.git.m.nazarewicz@samsung.com \
    --to=m.nazarewicz@samsung.com \
    --cc=dbrownell@users.sourceforge.net \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    /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.