Skip to contentSkip to conversation

HID: hiddev: move hiddev's minor number and refactoring

PATCH In review Jaejoong Kim 3 participants 9 messages Mar 2, 2017 – Mar 3, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover HID: hiddev: move hiddev's minor number and refactoring

Hi all,

I found hiddev's minor number is always zero in struct hid_device. So, store the minor number asked from usb core in struct hid_device.

This is my first approach.

But after reviewed from Bendjamin, he suggested that it would make sense to store a minor number in struct hiddev like hidraw if it neeeded.

So, I move the minor number from hid_device to hiddev and do some refactoring to access struct hiddev in hid-core

Jaejoong Kim (2):
HID: hiddev: move hiddev's minor number from struct hid_device to
hiddev
HID: hiddev: store hiddev's minor number when hiddev is connected

 drivers/hid/hid-core.c      |  2 +-
 drivers/hid/usbhid/hiddev.c | 25 +++----------------------
 include/linux/hid.h         |  1 -
 include/linux/hiddev.h      | 24 ++++++++++++++++++++++++
 4 files changed, 28 insertions(+), 24 deletions(-)
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH 1/2 HID: hiddev: move hiddev's minor number from struct hid_device to hiddev

We need to store the minor number each drivers. In case of hidraw, it's minor number stores in struct hidraw. But hiddev's minor is located in struct hid_device.

So reallocates for hiddev's minor number.

---
 drivers/hid/usbhid/hiddev.c | 1 +
 include/linux/hid.h         | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/hid/usbhid/hiddev.c +1 -0
index 700145b..5c2c489 100644
@@ -47,6 +47,7 @@
 #define HIDDEV_BUFFER_SIZE	2048
 
 struct hiddev {
+	int minor;
 	int exist;
 	int open;
 	struct mutex existancelock;
include/linux/hid.h +0 -1
index 28f38e2b8..643c017 100644
@@ -541,7 +541,6 @@ struct hid_device {							/* device report descriptor */
 	struct list_head inputs;					/* The list of inputs */
 	void *hiddev;							/* The hiddev structure */
 	void *hidraw;
-	int minor;							/* Hiddev minor number */
 
 	int open;							/* is the device open by anyone? */
 	char name[128];							/* Device name */
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/2] HID: hiddev: move hiddev's minor number from struct hid_device to hiddev

Quoted 6 lines · Jaejoong Kim

We need to store the minor number each drivers. In case of hidraw, it's minor number stores in struct hidraw. But hiddev's minor is located in struct hid_device.

So reallocates for hiddev's minor number.

There is not a real need to have this one in a separate patch. Also, it depends on the patch "[PATCH] HID: cp2112: use proper hidraw name with minor number", so better include this cp2112 in this series (as I mentioned in the cp2112 patch).

I'd say simply squash this patch with 2/2 and have the cp2112 as 1/2.

Cheers,
Benjamin

Quoted 33 lines
---
 drivers/hid/usbhid/hiddev.c | 1 +
 include/linux/hid.h         | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/hid/usbhid/hiddev.c +1 -0
index 700145b..5c2c489 100644
@@ -47,6 +47,7 @@
 #define HIDDEV_BUFFER_SIZE	2048
 
 struct hiddev {
+	int minor;
 	int exist;
 	int open;
 	struct mutex existancelock;
include/linux/hid.h +0 -1
index 28f38e2b8..643c017 100644
@@ -541,7 +541,6 @@ struct hid_device {							/* device report descriptor */
 	struct list_head inputs;					/* The list of inputs */
 	void *hiddev;							/* The hiddev structure */
 	void *hidraw;
-	int minor;							/* Hiddev minor number */
 
 	int open;							/* is the device open by anyone? */
 	char name[128];							/* Device name */
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH 1/2] HID: hiddev: move hiddev's minor number from struct hid_device to hiddev

2017-03-02 23:10 GMT+09:00 Benjamin Tissoires <[email protected]>:

Quoted 8 lines · Jaejoong Kim
Quoted 6 lines

We need to store the minor number each drivers. In case of hidraw, it's minor number stores in struct hidraw. But hiddev's minor is located in struct hid_device.

So reallocates for hiddev's minor number.

Quoted 6 lines

There is not a real need to have this one in a separate patch. Also, it depends on the patch "[PATCH] HID: cp2112: use proper hidraw name with minor number", so better include this cp2112 in this series (as I mentioned in the cp2112 patch).

I'd say simply squash this patch with 2/2 and have the cp2112 as 1/2.

Ok. I will resend v2 patchset.

Thanks.
jaejoong

Quoted 37 lines

Cheers,
Benjamin

Quoted 33 lines
---
 drivers/hid/usbhid/hiddev.c | 1 +
 include/linux/hid.h         | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/hid/usbhid/hiddev.c +1 -0
index 700145b..5c2c489 100644
@@ -47,6 +47,7 @@
 #define HIDDEV_BUFFER_SIZE   2048
 
 struct hiddev {
+     int minor;
      int exist;
      int open;
      struct mutex existancelock;
include/linux/hid.h +0 -2
index 28f38e2b8..643c017 100644
@@ -541,7 +541,6 @@ struct hid_device {                                                       /* device report descriptor */
      struct list_head inputs;                                        /* The list of inputs */
      void *hiddev;                                                   /* The hiddev structure */
      void *hidraw;
-     int minor;                                                      /* Hiddev minor number */
 
      int open;                                                       /* is the device open by anyone? */
      char name[128];                                                 /* Device name */
--

2.7.4

#4 lore raw

Re: [PATCH 1/2] HID: hiddev: move hiddev's minor number from struct hid_device to hiddev

In reply to Jaejoong Kim
reproduce:

Hi Jaejoong,

[auto build test ERROR on hid/for-next]
[also build test ERROR on v4.10 next-20170303]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jaejoong-Kim/HID-hiddev-move-hiddev-s-minor-number-and-refactoring/20170303-222428
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid.git for-next
config: i386-randconfig-b0-03032110 (attached as .config)
compiler: gcc-5 (Debian 5.4.1-2) 5.4.1 20160904
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

drivers/hid/hid-cp2112.c: In function 'cp2112_probe':

>> drivers/hid/hid-cp2112.c:1300:43: error: 'struct hid_device' has no member named 'minor'
       "CP2112 SMBus Bridge on hiddev%d", hdev->minor);
                                              ^

vim +1300 drivers/hid/hid-cp2112.c

e932d817 David Barksdale 2014-02-04  1294  	dev->adap.owner		= THIS_MODULE;
e932d817 David Barksdale 2014-02-04  1295  	dev->adap.class		= I2C_CLASS_HWMON;
e932d817 David Barksdale 2014-02-04  1296  	dev->adap.algo		= &smbus_algorithm;
e932d817 David Barksdale 2014-02-04  1297  	dev->adap.algo_data	= dev;
e932d817 David Barksdale 2014-02-04  1298  	dev->adap.dev.parent	= &hdev->dev;
e932d817 David Barksdale 2014-02-04  1299  	snprintf(dev->adap.name, sizeof(dev->adap.name),
e932d817 David Barksdale 2014-02-04 @1300  		 "CP2112 SMBus Bridge on hiddev%d", hdev->minor);
44eda784 Ellen Wang      2015-07-09  1301  	dev->hwversion = buf[2];
e932d817 David Barksdale 2014-02-04  1302  	init_waitqueue_head(&dev->wait);

e932d817 David Barksdale 2014-02-04 1303

:::::: The code at line 1300 was first introduced by commit :::::: e932d817866770d456815c9a84b7ed94f0589d80 HID: add hid-cp2112 driver

:::::: TO: David Barksdale <[email protected]> :::::: CC: Jiri Kosina <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#5 lore raw

Re: [PATCH 1/2] HID: hiddev: move hiddev's minor number from struct hid_device to hiddev

In reply to Jaejoong Kim
reproduce:

Hi Jaejoong,

[auto build test ERROR on hid/for-next]
[also build test ERROR on v4.10 next-20170303]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jaejoong-Kim/HID-hiddev-move-hiddev-s-minor-number-and-refactoring/20170303-222428
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid.git for-next
config: x86_64-randconfig-x016-201709 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

drivers/hid/hid-core.c: In function 'hid_connect':

>> drivers/hid/hid-core.c:1698:9: error: 'struct hid_device' has no member named 'minor'; did you mean 'vendor'?
        hdev->minor);
            ^~
--
   drivers/hid/hid-cp2112.c: In function 'cp2112_probe':
>> drivers/hid/hid-cp2112.c:1300:43: error: 'struct hid_device' has no member named 'minor'; did you mean 'vendor'?
       "CP2112 SMBus Bridge on hiddev%d", hdev->minor);
                                              ^~

vim +1698 drivers/hid/hid-core.c

93c10132 Jiri Slaby 2008-06-27  1692  
93c10132 Jiri Slaby 2008-06-27  1693  	len = 0;
93c10132 Jiri Slaby 2008-06-27  1694  	if (hdev->claimed & HID_CLAIMED_INPUT)
93c10132 Jiri Slaby 2008-06-27  1695  		len += sprintf(buf + len, "input");
93c10132 Jiri Slaby 2008-06-27  1696  	if (hdev->claimed & HID_CLAIMED_HIDDEV)
93c10132 Jiri Slaby 2008-06-27  1697  		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
93c10132 Jiri Slaby 2008-06-27 @1698  				hdev->minor);
93c10132 Jiri Slaby 2008-06-27  1699  	if (hdev->claimed & HID_CLAIMED_HIDRAW)
93c10132 Jiri Slaby 2008-06-27  1700  		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
93c10132 Jiri Slaby 2008-06-27  1701  				((struct hidraw *)hdev->hidraw)->minor);

:::::: The code at line 1698 was first introduced by commit :::::: 93c10132a7ac160df3175b53f7ee857625412165 HID: move connect quirks

:::::: TO: Jiri Slaby <[email protected]>
:::::: CC: Jiri Kosina <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#6 lore raw

PATCH 2/2 HID: hiddev: store hiddev's minor number when hiddev is connected

In reply to Jaejoong Kim

The hid-core announces kernel message which driver is loaded if there is a hiddev, but hiddev's minor number is always zero even though it's not zero.

So, we need to store the minor number asked from usb core and do some refactoring work(move from hiddev.c to hiddev.h) to access hiddev in hid-core.

---
 drivers/hid/hid-core.c      |  2 +-
 drivers/hid/usbhid/hiddev.c | 26 +++-----------------------
 include/linux/hiddev.h      | 24 ++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 24 deletions(-)
drivers/hid/hid-core.c +1 -1
index e9e87d3..1a0b910 100644
@@ -1695,7 +1695,7 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
 		len += sprintf(buf + len, "input");
 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
 		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
-				hdev->minor);
+				((struct hiddev *)hdev->hiddev)->minor);
 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
 		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
 				((struct hidraw *)hdev->hidraw)->minor);
drivers/hid/usbhid/hiddev.c +3 -23
index 5c2c489..ef83d68 100644
@@ -44,29 +44,6 @@
 #define HIDDEV_MINOR_BASE	96
 #define HIDDEV_MINORS		16
 #endif
-#define HIDDEV_BUFFER_SIZE	2048
-
-struct hiddev {
-	int minor;
-	int exist;
-	int open;
-	struct mutex existancelock;
-	wait_queue_head_t wait;
-	struct hid_device *hid;
-	struct list_head list;
-	spinlock_t list_lock;
-};
-
-struct hiddev_list {
-	struct hiddev_usage_ref buffer[HIDDEV_BUFFER_SIZE];
-	int head;
-	int tail;
-	unsigned flags;
-	struct fasync_struct *fasync;
-	struct hiddev *hiddev;
-	struct list_head node;
-	struct mutex thread_lock;
-};
 
 /*
  * Find a report, given the report's type and ID.  The ID can be specified
@@ -911,6 +888,9 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
 		kfree(hiddev);
 		return -1;
 	}
+
+	hiddev->minor = usbhid->intf->minor;
+
 	return 0;
 }
 
include/linux/hiddev.h +24 -0
index a5dd814..ff3701b 100644
@@ -32,6 +32,30 @@
  * In-kernel definitions.
  */
 
+#define HIDDEV_BUFFER_SIZE      2048
+
+struct hiddev {
+	int minor;
+	int exist;
+	int open;
+	struct mutex existancelock;
+	wait_queue_head_t wait;
+	struct hid_device *hid;
+	struct list_head list;
+	spinlock_t list_lock;
+};
+
+struct hiddev_list {
+	struct hiddev_usage_ref buffer[HIDDEV_BUFFER_SIZE];
+	int head;
+	int tail;
+	unsigned flags;
+	struct fasync_struct *fasync;
+	struct hiddev *hiddev;
+	struct list_head node;
+	struct mutex thread_lock;
+};
+
 struct hid_device;
 struct hid_usage;
 struct hid_field;
Signature · 1 line
2.7.4
#7 lore raw

Re: [PATCH 2/2] HID: hiddev: store hiddev's minor number when hiddev is connected

Quoted 93 lines · Jaejoong Kim

The hid-core announces kernel message which driver is loaded if there is a hiddev, but hiddev's minor number is always zero even though it's not zero.

So, we need to store the minor number asked from usb core and do some refactoring work(move from hiddev.c to hiddev.h) to access hiddev in hid-core.

---
 drivers/hid/hid-core.c      |  2 +-
 drivers/hid/usbhid/hiddev.c | 26 +++-----------------------
 include/linux/hiddev.h      | 24 ++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 24 deletions(-)
drivers/hid/hid-core.c +1 -1
index e9e87d3..1a0b910 100644
@@ -1695,7 +1695,7 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
 		len += sprintf(buf + len, "input");
 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
 		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
-				hdev->minor);
+				((struct hiddev *)hdev->hiddev)->minor);
 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
 		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
 				((struct hidraw *)hdev->hidraw)->minor);
drivers/hid/usbhid/hiddev.c +3 -23
index 5c2c489..ef83d68 100644
@@ -44,29 +44,6 @@
 #define HIDDEV_MINOR_BASE	96
 #define HIDDEV_MINORS		16
 #endif
-#define HIDDEV_BUFFER_SIZE	2048
-
-struct hiddev {
-	int minor;
-	int exist;
-	int open;
-	struct mutex existancelock;
-	wait_queue_head_t wait;
-	struct hid_device *hid;
-	struct list_head list;
-	spinlock_t list_lock;
-};
-
-struct hiddev_list {
-	struct hiddev_usage_ref buffer[HIDDEV_BUFFER_SIZE];
-	int head;
-	int tail;
-	unsigned flags;
-	struct fasync_struct *fasync;
-	struct hiddev *hiddev;
-	struct list_head node;
-	struct mutex thread_lock;
-};
 
 /*
  * Find a report, given the report's type and ID.  The ID can be specified
@@ -911,6 +888,9 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
 		kfree(hiddev);
 		return -1;
 	}
+
+	hiddev->minor = usbhid->intf->minor;
+
 	return 0;
 }
 
include/linux/hiddev.h +13 -0
index a5dd814..ff3701b 100644
@@ -32,6 +32,30 @@
  * In-kernel definitions.
  */
 
+#define HIDDEV_BUFFER_SIZE      2048
+
+struct hiddev {
+	int minor;
+	int exist;
+	int open;
+	struct mutex existancelock;
+	wait_queue_head_t wait;
+	struct hid_device *hid;
+	struct list_head list;
+	spinlock_t list_lock;
+};
+

include/linux/hiddev.h line 57

Quoted 10 lines
include/linux/hiddev.h +10 -0
+struct hiddev_list {
+	struct hiddev_usage_ref buffer[HIDDEV_BUFFER_SIZE];
+	int head;
+	int tail;
+	unsigned flags;
+	struct fasync_struct *fasync;
+	struct hiddev *hiddev;
+	struct list_head node;
+	struct mutex thread_lock;
+};

Why do you need to also export struct hiddev_list? Unless I am missing something we don't need it elsewhere but in hiddev.c, and so there is no point exporting this struct to the world.

With this change amended, the end result looks good and the series should be ready to be integrated IMO.

Cheers,
Benjamin

Quoted 7 lines
include/linux/hiddev.h +1 -0
+
 struct hid_device;
 struct hid_usage;
 struct hid_field;
Signature · 1 line
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

Re: [PATCH 2/2] HID: hiddev: store hiddev's minor number when hiddev is connected

2017-03-02 23:13 GMT+09:00 Benjamin Tissoires <[email protected]>:

Quoted 100 lines · Jaejoong Kim
Quoted 99 lines

The hid-core announces kernel message which driver is loaded if there is a hiddev, but hiddev's minor number is always zero even though it's not zero.

So, we need to store the minor number asked from usb core and do some refactoring work(move from hiddev.c to hiddev.h) to access hiddev in hid-core.

---
 drivers/hid/hid-core.c      |  2 +-
 drivers/hid/usbhid/hiddev.c | 26 +++-----------------------
 include/linux/hiddev.h      | 24 ++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 24 deletions(-)
drivers/hid/hid-core.c +1 -1
index e9e87d3..1a0b910 100644
@@ -1695,7 +1695,7 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
              len += sprintf(buf + len, "input");
      if (hdev->claimed & HID_CLAIMED_HIDDEV)
              len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
-                             hdev->minor);
+                             ((struct hiddev *)hdev->hiddev)->minor);
      if (hdev->claimed & HID_CLAIMED_HIDRAW)
              len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
                              ((struct hidraw *)hdev->hidraw)->minor);
drivers/hid/usbhid/hiddev.c +3 -23
index 5c2c489..ef83d68 100644
@@ -44,29 +44,6 @@
 #define HIDDEV_MINOR_BASE    96
 #define HIDDEV_MINORS                16
 #endif
-#define HIDDEV_BUFFER_SIZE   2048
-
-struct hiddev {
-     int minor;
-     int exist;
-     int open;
-     struct mutex existancelock;
-     wait_queue_head_t wait;
-     struct hid_device *hid;
-     struct list_head list;
-     spinlock_t list_lock;
-};
-
-struct hiddev_list {
-     struct hiddev_usage_ref buffer[HIDDEV_BUFFER_SIZE];
-     int head;
-     int tail;
-     unsigned flags;
-     struct fasync_struct *fasync;
-     struct hiddev *hiddev;
-     struct list_head node;
-     struct mutex thread_lock;
-};
 
 /*
  * Find a report, given the report's type and ID.  The ID can be specified
@@ -911,6 +888,9 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
              kfree(hiddev);
              return -1;
      }
+
+     hiddev->minor = usbhid->intf->minor;
+
      return 0;
 }
 
include/linux/hiddev.h +19 -0
index a5dd814..ff3701b 100644
@@ -32,6 +32,30 @@
  * In-kernel definitions.
  */
 
+#define HIDDEV_BUFFER_SIZE      2048
+
+struct hiddev {
+     int minor;
+     int exist;
+     int open;
+     struct mutex existancelock;
+     wait_queue_head_t wait;
+     struct hid_device *hid;
+     struct list_head list;
+     spinlock_t list_lock;
+};
+
+struct hiddev_list {
+     struct hiddev_usage_ref buffer[HIDDEV_BUFFER_SIZE];
+     int head;
+     int tail;
+     unsigned flags;
+     struct fasync_struct *fasync;
Quoted 8 lines

include/linux/hiddev.h line 57

Quoted 4 lines
include/linux/hiddev.h +4 -0
+     struct hiddev *hiddev;
+     struct list_head node;
+     struct mutex thread_lock;
+};

Why do you need to also export struct hiddev_list? Unless I am missing something we don't need it elsewhere but in hiddev.c, and so there is no point exporting this struct to the world.

You're right. I will export only struct hiddev.

Quoted 4 lines

With this change amended, the end result looks good and the series should be ready to be integrated IMO.

I will resend v2 patchset your said.

Thanks,
jaejoong

Quoted 10 lines

Cheers,
Benjamin

Quoted 7 lines
include/linux/hiddev.h +1 -1
+
 struct hid_device;
 struct hid_usage;
 struct hid_field;
--

2.7.4