i2c-hid cleanup and bug fixes
Subsystems (2)
cover i2c-hid cleanup and bug fixes
Hi guys,
Jean made a recent review of i2c-hid, and before this driver goes into Linus' tree, here are some cleanups.
Patch 2 has not been detected by Jean, but it appeared while playing with buffers allocation. So this is the only change not asked by the previous review.
I still need to work on the mutex to protect the potential race on .open and .close, but meanwhile, here is a first batch of patches.
Cheers,
Benjamin
Benjamin Tissoires (14):
HID: i2c-hid: change I2C name
HID: i2c-hid: fix memory corruption due to missing hid declarations
HID: i2c-hid: enhance Kconfig
HID: i2c-hid: fix checkpatch.pl warning
HID: i2c-hid: fix i2c_hid_dbg macro
HID: i2c-hid: remove unused static declarations
HID: i2c-hid: fix return paths
HID: i2c-hid: fix error messages
HID: i2c-hid: i2c_hid_get_report may fail
HID: i2c-hid: reorder allocation/free of buffers
HID: i2c-hid: remove unneeded test in i2c_hid_remove
HID: i2c-hid: remove extra .irq field in struct i2c_hid
HID: i2c-hid: also call i2c_hid_free_buffers in i2c_hid_remove
HID: i2c-hid: fix i2c_hid_get_raw_report count mismatches
drivers/hid/i2c-hid/Kconfig | 7 +- drivers/hid/i2c-hid/i2c-hid.c | 184 ++++++++++++++++++++---------------------- 2 files changed, 89 insertions(+), 102 deletions(-)
Signature · 1 line
1.8.0.1
PATCH 1/14 HID: i2c-hid: change I2C name
no I2C driver has "i2c" in its name. It makes more sense to call this i2c driver "hid".
--- drivers/hid/i2c-hid/i2c-hid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/i2c-hid/i2c-hid.c +1 -1
@@ -949,7 +949,7 @@ static int i2c_hid_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(i2c_hid_pm, i2c_hid_suspend, i2c_hid_resume);static const struct i2c_device_id i2c_hid_id_table[] = { - {"i2c_hid" ,0 }, + {"hid" ,0 }, { }, };MODULE_DEVICE_TABLE (i2c, i2c_hid_id_table);
Signature · 1 line
1.8.0.1
Re: [PATCH 01/14] HID: i2c-hid: change I2C name
Quoted 13 lines · Benjamin Tissoires
no I2C driver has "i2c" in its name. It makes more sense to call this i2c driver "hid".
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/i2c-hid/i2c-hid.c +0
-0
drivers/hid/i2c-hid/i2c-hid.c static int i2c_hid_resume(struct device *dev) · line 955
Quoted 8 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-1@@ -949,7 +949,7 @@ static int i2c_hid_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(i2c_hid_pm, i2c_hid_suspend, i2c_hid_resume);static const struct i2c_device_id i2c_hid_id_table[] = { - {"i2c_hid" ,0 }, + {"hid" ,0 }, { }, };MODULE_DEVICE_TABLE (i2c, i2c_hid_id_table);
Signature · 1 line
Jean Delvare
Jiri Kosina
AppliedRe: [PATCH 01/14] HID: i2c-hid: change I2C name
Quoted 15 lines · Jean Delvare
Quoted 15 lines
no I2C driver has "i2c" in its name. It makes more sense to call this i2c driver "hid".
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/i2c-hid/i2c-hid.c +0
-0@@ -949,7 +949,7 @@ static int i2c_hid_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(i2c_hid_pm, i2c_hid_suspend, i2c_hid_resume);
Quoted 8 lines
drivers/hid/i2c-hid/i2c-hid.c static int i2c_hid_resume(struct device *dev) · line 955
Quoted 6 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-1static const struct i2c_device_id i2c_hid_id_table[] = { - {"i2c_hid" ,0 }, + {"hid" ,0 }, { }, };MODULE_DEVICE_TABLE (i2c, i2c_hid_id_table);Reviewed-by Jean Delvare <[email protected]>
Applied, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 2/14 HID: i2c-hid: fix memory corruption due to missing hid declaration
In reply to Benjamin TissoiresHID descriptors contains 4 bytes of reserved field.
The previous implementation was overriding the next fields in struct i2c_hid.
--- drivers/hid/i2c-hid/i2c-hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hid/i2c-hid/i2c-hid.c +2 -1
@@ -68,6 +68,7 @@ struct i2c_hid_desc {__le16 wVendorID;__le16 wProductID;__le16 wVersionID; +__le32 reserved; } __packed;struct i2c_hid_cmd {
@@ -778,7 +779,7 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) } dsize =le16_to_cpu (hdesc->wHIDDescLength); -if (!dsize || dsize >HID_MAX_DESCRIPTOR_SIZE ) { +if (!dsize || dsize >sizeof (struct i2c_hid_desc )) {dev_err (&client->dev,"weird size of HID descriptor (%u)\n" , dsize);return -ENODEV ;
Signature · 1 line
1.8.0.1
Re: [PATCH 02/14] HID: i2c-hid: fix memory corruption due to missing hid declaration
Quoted 21 lines · Benjamin Tissoires
HID descriptors contains 4 bytes of reserved field.
The previous implementation was overriding the next fields in structi2c_hid.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/hid/i2c-hid/i2c-hid.c +1
-0@@ -68,6 +68,7 @@ struct i2c_hid_desc {__le16 wVendorID;__le16 wProductID;__le16 wVersionID; +__le32 reserved; } __packed;struct i2c_hid_cmd {
drivers/hid/i2c-hid/i2c-hid.c static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) · line 782
Quoted 5 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-1@@ -778,7 +779,7 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) } dsize =le16_to_cpu (hdesc->wHIDDescLength); -if (!dsize || dsize >HID_MAX_DESCRIPTOR_SIZE ) { +if (!dsize || dsize >sizeof (struct i2c_hid_desc )) {
Shouldn't !dsize rather be dsize < 4? You're reading hdesc->bcdVersion, which is only defined if dsize >= 4 if I understand the code correctly.
Quoted 3 lines
drivers/hid/i2c-hid/i2c-hid.c +0
-0dev_err (&client->dev,"weird size of HID descriptor (%u)\n" , dsize);return -ENODEV ;
Signature · 1 line
Jean Delvare
Re: [PATCH 02/14] HID: i2c-hid: fix memory corruption due to missing hid declaration
Quoted 24 lines · Jean Delvare
Quoted 23 lines · Benjamin Tissoires
HID descriptors contains 4 bytes of reserved field.
The previous implementation was overriding the next fields in structi2c_hid.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/hid/i2c-hid/i2c-hid.c +1
-0@@ -68,6 +68,7 @@ struct i2c_hid_desc {__le16 wVendorID;__le16 wProductID;__le16 wVersionID; +__le32 reserved; } __packed;struct i2c_hid_cmd {@@ -778,7 +779,7 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) }
Quoted 6 lines
drivers/hid/i2c-hid/i2c-hid.c static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) · line 782
Quoted 3 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-1dsize =le16_to_cpu (hdesc->wHIDDescLength); -if (!dsize || dsize >HID_MAX_DESCRIPTOR_SIZE ) { +if (!dsize || dsize >sizeof (struct i2c_hid_desc )) {Shouldn't !dsize rather be dsize < 4? You're reading
hdesc->bcdVersion, which is only defined if dsize >= 4 if I understand the code correctly.
Yes, you are right. Thanks.
Jiri, this patch is a prerequisite for "[PATCH 10/14] HID: i2c-hid:
reorder allocation/free of buffers".
could you please what for a v2 before applying 10/14?
Cheers,
Benjamin
Quoted 8 lines
drivers/hid/i2c-hid/i2c-hid.c static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) · line 785
Quoted 4 lines
drivers/hid/i2c-hid/i2c-hid.c +0
-0dev_err (&client->dev,"weird size of HID descriptor (%u)\n" , dsize);return -ENODEV ;--
Jean Delvare
Re: [PATCH 02/14] HID: i2c-hid: fix memory corruption due to missing hid declaration
Quoted 31 lines · Benjamin Tissoires
Quoted 24 lines · Benjamin Tissoires
Quoted 23 lines
HID descriptors contains 4 bytes of reserved field.
The previous implementation was overriding the next fields in structi2c_hid.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/hid/i2c-hid/i2c-hid.c +1
-0@@ -68,6 +68,7 @@ struct i2c_hid_desc {__le16 wVendorID;__le16 wProductID;__le16 wVersionID; +__le32 reserved; } __packed;struct i2c_hid_cmd {@@ -778,7 +779,7 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) }Quoted 6 lines
drivers/hid/i2c-hid/i2c-hid.c static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) · line 782
Quoted 3 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-1dsize =le16_to_cpu (hdesc->wHIDDescLength); -if (!dsize || dsize >HID_MAX_DESCRIPTOR_SIZE ) { +if (!dsize || dsize >sizeof (struct i2c_hid_desc )) {Shouldn't !dsize rather be dsize < 4? You're reading
hdesc->bcdVersion, which is only defined if dsize >= 4 if I understand the code correctly.
Quoted 5 lines
Yes, you are right. Thanks.
Jiri, this patch is a prerequisite for "[PATCH 10/14] HID: i2c-hid:
reorder allocation/free of buffers".
could you please what for a v2 before applying 10/14?
Absolutely. I still have to review 9, 10, 11, 12, 13, 14, so am dropping 2 and 10 from my attention for now.
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 3/14 HID: i2c-hid: enhance Kconfig
In reply to Benjamin TissoiresThe "comment" part can never be displayed, so we can remove it.
--- drivers/hid/i2c-hid/Kconfig | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/hid/i2c-hid/Kconfig +2 -5
@@ -7,15 +7,12 @@ config I2C_HID depends on I2C && INPUT select HID ---help--- - Say Y here if you want to use the HID over i2c protocol - implementation. + Say Y here if you use a keyboard, a touchpad, a touchscreen, or any + other HID based devices which is connected to your computer via I2C. If unsure, say N. This support is also available as a module. If so, the module will be called i2c-hid. -comment "Input core support is needed for HID over I2C input layer" - depends on I2C_HID && INPUT=n - endmenu
Signature · 1 line
1.8.0.1
Re: [PATCH 03/14] HID: i2c-hid: enhance Kconfig
Quoted 19 lines · Benjamin Tissoires
The "comment" part can never be displayed, so we can remove it.
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/Kconfig | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/hid/i2c-hid/Kconfig +2
-2@@ -7,15 +7,12 @@ config I2C_HID depends on I2C && INPUT select HID ---help--- - Say Y here if you want to use the HID over i2c protocol - implementation. + Say Y here if you use a keyboard, a touchpad, a touchscreen, or any + other HID based devices which is connected to your computer via I2C.
drivers/hid/i2c-hid/Kconfig config I2C_HID · line 18
Quoted 10 lines
drivers/hid/i2c-hid/Kconfig +0
-3If unsure, say N. This support is also available as a module. If so, the module will be called i2c-hid. -comment "Input core support is needed for HID over I2C input layer" - depends on I2C_HID && INPUT=n - endmenu
Signature · 1 line
Jean Delvare
Jiri Kosina
AppliedRe: [PATCH 03/14] HID: i2c-hid: enhance Kconfig
Quoted 25 lines · Jean Delvare
Quoted 25 lines
The "comment" part can never be displayed, so we can remove it.
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/Kconfig | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/hid/i2c-hid/Kconfig +2
-2@@ -7,15 +7,12 @@ config I2C_HID depends on I2C && INPUT select HID ---help--- - Say Y here if you want to use the HID over i2c protocol - implementation. + Say Y here if you use a keyboard, a touchpad, a touchscreen, or any + other HID based devices which is connected to your computer via I2C. If unsure, say N. This support is also available as a module. If so, the module will be called i2c-hid.
Quoted 6 lines
drivers/hid/i2c-hid/Kconfig config I2C_HID · line 18
Quoted 4 lines
drivers/hid/i2c-hid/Kconfig +0
-3-comment "Input core support is needed for HID over I2C input layer" - depends on I2C_HID && INPUT=n - endmenuReviewed-by Jean Delvare <[email protected]>
Applied.
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 4/14 HID: i2c-hid: fix checkpatch.pl warning
In reply to Benjamin TissoiresWe should not initialize to 0 static declarations.
--- drivers/hid/i2c-hid/i2c-hid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/i2c-hid/i2c-hid.c +1 -1
@@ -46,7 +46,7 @@#define I2C_HID_PWR_SLEEP 0x01/* debug option */ -static bool debug = false; +static bool debug;module_param (debug, bool,0444 );MODULE_PARM_DESC (debug,"print a lot of debug information" );
Signature · 1 line
1.8.0.1
Re: [PATCH 04/14] HID: i2c-hid: fix checkpatch.pl warning
Quoted 12 lines · Benjamin Tissoires
We should not initialize to 0 static declarations.
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/i2c-hid/i2c-hid.c +0
-0
drivers/hid/i2c-hid/i2c-hid.c line 52
Quoted 8 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-1@@ -46,7 +46,7 @@#define I2C_HID_PWR_SLEEP 0x01/* debug option */ -static bool debug = false; +static bool debug;module_param (debug, bool,0444 );MODULE_PARM_DESC (debug,"print a lot of debug information" );
Signature · 1 line
Jean Delvare
Jiri Kosina
AppliedRe: [PATCH 04/14] HID: i2c-hid: fix checkpatch.pl warning
Quoted 14 lines · Jean Delvare
Quoted 14 lines
We should not initialize to 0 static declarations.
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/i2c-hid/i2c-hid.c +0
-0@@ -46,7 +46,7 @@#define I2C_HID_PWR_SLEEP 0x01
Quoted 8 lines
drivers/hid/i2c-hid/i2c-hid.c line 52
Quoted 6 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-1/* debug option */ -static bool debug = false; +static bool debug;module_param (debug, bool,0444 );MODULE_PARM_DESC (debug,"print a lot of debug information" );Reviewed-by Jean Delvare <[email protected]>
Applied, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 5/14 HID: i2c-hid: fix i2c_hid_dbg macro
In reply to Benjamin TissoiresThis avoids the problematic case:
if (condition)
i2c_hid_dbg(ihid, "Blah blah %d\n", i); else do_something_very_important();
Which looks correct, however with the previous macro definition, this expands to the unexpected:
if (condition) {
if (debug) \
dev_printk(KERN_DEBUG, &ihid->client->dev,
"Blah blah %d\n", i);
else
do_something_very_important();
}--- drivers/hid/i2c-hid/i2c-hid.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/hid/i2c-hid/i2c-hid.c +5 -3
@@ -50,9 +50,11 @@ static bool debug;module_param (debug, bool,0444 );MODULE_PARM_DESC (debug,"print a lot of debug information" ); -#define i2c_hid_dbg(ihid, fmt, arg...) \ - if (debug) \ - dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg) +#define i2c_hid_dbg(ihid, fmt, arg...) \ +do { \ + if (debug) \ + dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \ +} while (0)struct i2c_hid_desc {__le16 wHIDDescLength;
Signature · 1 line
1.8.0.1
Re: [PATCH 05/14] HID: i2c-hid: fix i2c_hid_dbg macro
Quoted 32 lines · Benjamin Tissoires
This avoids the problematic case:
if (condition)
i2c_hid_dbg(ihid, "Blah blah %d\n", i); else do_something_very_important();Which looks correct, however with the previous macro definition, this expands to the unexpected:
if (condition) { if (debug) \ dev_printk(KERN_DEBUG, &ihid->client->dev, "Blah blah %d\n", i); else do_something_very_important(); }Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +0
-1@@ -50,9 +50,11 @@ static bool debug;module_param (debug, bool,0444 );MODULE_PARM_DESC (debug,"print a lot of debug information" ); -#define i2c_hid_dbg(ihid, fmt, arg...) \
drivers/hid/i2c-hid/i2c-hid.c static bool debug; · line 60
Quoted 10 lines
drivers/hid/i2c-hid/i2c-hid.c +5
-2- if (debug) \ - dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg) +#define i2c_hid_dbg(ihid, fmt, arg...) \ +do { \ + if (debug) \ + dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \ +} while (0)struct i2c_hid_desc {__le16 wHIDDescLength;
Signature · 1 line
Jean Delvare
Jiri Kosina
AppliedRe: [PATCH 05/14] HID: i2c-hid: fix i2c_hid_dbg macro
Quoted 40 lines · Jean Delvare
Quoted 40 lines
This avoids the problematic case:
if (condition)
i2c_hid_dbg(ihid, "Blah blah %d\n", i); else do_something_very_important();Which looks correct, however with the previous macro definition, this expands to the unexpected:
if (condition) { if (debug) \ dev_printk(KERN_DEBUG, &ihid->client->dev, "Blah blah %d\n", i); else do_something_very_important(); }Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +5
-3@@ -50,9 +50,11 @@ static bool debug;module_param (debug, bool,0444 );MODULE_PARM_DESC (debug,"print a lot of debug information" ); -#define i2c_hid_dbg(ihid, fmt, arg...) \ - if (debug) \ - dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg) +#define i2c_hid_dbg(ihid, fmt, arg...) \ +do { \ + if (debug) \ + dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \ +} while (0)
Quoted 4 lines
drivers/hid/i2c-hid/i2c-hid.c static bool debug; · line 60
Quoted 2 lines
drivers/hid/i2c-hid/i2c-hid.c +0
-0struct i2c_hid_desc {__le16 wHIDDescLength;Reviewed-by Jean Delvare <[email protected]>
Applied.
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 6/14 HID: i2c-hid: remove unused static declarations
In reply to Benjamin TissoiresThese definitions are not used here, but are defined by the specification. Keeping some of them for documentation purposes.
--- drivers/hid/i2c-hid/i2c-hid.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
drivers/hid/i2c-hid/i2c-hid.c +10 -15
@@ -106,22 +106,17 @@ static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01), .wait = true };static const struct i2c_hid_cmd hid_get_report_cmd = {I2C_HID_CMD (0x02 ) };static const struct i2c_hid_cmd hid_set_report_cmd = {I2C_HID_CMD (0x03 ) }; -static const struct i2c_hid_cmd hid_get_idle_cmd = {I2C_HID_CMD (0x04 ) }; -static const struct i2c_hid_cmd hid_set_idle_cmd = {I2C_HID_CMD (0x05 ) }; -static const struct i2c_hid_cmd hid_get_protocol_cmd = {I2C_HID_CMD (0x06 ) }; -static const struct i2c_hid_cmd hid_set_protocol_cmd = {I2C_HID_CMD (0x07 ) };static const struct i2c_hid_cmd hid_set_power_cmd = {I2C_HID_CMD (0x08 ) }; -/* read/write data register */ -static const struct i2c_hid_cmd hid_data_cmd = { - .registerIndex = offsetof(struct i2c_hid_desc , wDataRegister), - .opcode =0x00 , - .length =2 }; -/* write output reports */ -static const struct i2c_hid_cmd hid_out_cmd = { - .registerIndex = offsetof(struct i2c_hid_desc , - wOutputRegister), - .opcode =0x00 , - .length =2 }; + +/* +* These definitions are not used here, but are defined by the spec. +* Keeping them here for documentation purposes. +* +* static const struct i2c_hid_cmd hid_get_idle_cmd = { I2C_HID_CMD(0x04) }; +* static const struct i2c_hid_cmd hid_set_idle_cmd = { I2C_HID_CMD(0x05) }; +* static const struct i2c_hid_cmd hid_get_protocol_cmd = { I2C_HID_CMD(0x06) }; +* static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) }; +*/ /* The main device structure */ struct i2c_hid {
Signature · 1 line
1.8.0.1
Re: [PATCH 06/14] HID: i2c-hid: remove unused static declarations
Quoted 35 lines · Benjamin Tissoires
These definitions are not used here, but are defined by the specification. Keeping some of them for documentation purposes.
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +3
-15@@ -106,22 +106,17 @@ static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01), .wait = true };static const struct i2c_hid_cmd hid_get_report_cmd = {I2C_HID_CMD (0x02 ) };static const struct i2c_hid_cmd hid_set_report_cmd = {I2C_HID_CMD (0x03 ) }; -static const struct i2c_hid_cmd hid_get_idle_cmd = {I2C_HID_CMD (0x04 ) }; -static const struct i2c_hid_cmd hid_set_idle_cmd = {I2C_HID_CMD (0x05 ) }; -static const struct i2c_hid_cmd hid_get_protocol_cmd = {I2C_HID_CMD (0x06 ) }; -static const struct i2c_hid_cmd hid_set_protocol_cmd = {I2C_HID_CMD (0x07 ) };static const struct i2c_hid_cmd hid_set_power_cmd = {I2C_HID_CMD (0x08 ) }; -/* read/write data register */ -static const struct i2c_hid_cmd hid_data_cmd = { - .registerIndex = offsetof(struct i2c_hid_desc , wDataRegister), - .opcode =0x00 , - .length =2 }; -/* write output reports */ -static const struct i2c_hid_cmd hid_out_cmd = { - .registerIndex = offsetof(struct i2c_hid_desc , - wOutputRegister), - .opcode =0x00 , - .length =2 }; + +/* +* These definitions are not used here, but are defined by the spec.
drivers/hid/i2c-hid/i2c-hid.c static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01), · line 122
Quoted 10 lines
drivers/hid/i2c-hid/i2c-hid.c +7
-0+* Keeping them here for documentation purposes. +* +* static const struct i2c_hid_cmd hid_get_idle_cmd = { I2C_HID_CMD(0x04) }; +* static const struct i2c_hid_cmd hid_set_idle_cmd = { I2C_HID_CMD(0x05) }; +* static const struct i2c_hid_cmd hid_get_protocol_cmd = { I2C_HID_CMD(0x06) }; +* static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) }; +*/ /* The main device structure */ struct i2c_hid {
Signature · 1 line
Jean Delvare
Jiri Kosina
AppliedRe: [PATCH 06/14] HID: i2c-hid: remove unused static declarations
Quoted 43 lines · Jean Delvare
Quoted 43 lines
These definitions are not used here, but are defined by the specification. Keeping some of them for documentation purposes.
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +10
-15@@ -106,22 +106,17 @@ static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01), .wait = true };static const struct i2c_hid_cmd hid_get_report_cmd = {I2C_HID_CMD (0x02 ) };static const struct i2c_hid_cmd hid_set_report_cmd = {I2C_HID_CMD (0x03 ) }; -static const struct i2c_hid_cmd hid_get_idle_cmd = {I2C_HID_CMD (0x04 ) }; -static const struct i2c_hid_cmd hid_set_idle_cmd = {I2C_HID_CMD (0x05 ) }; -static const struct i2c_hid_cmd hid_get_protocol_cmd = {I2C_HID_CMD (0x06 ) }; -static const struct i2c_hid_cmd hid_set_protocol_cmd = {I2C_HID_CMD (0x07 ) };static const struct i2c_hid_cmd hid_set_power_cmd = {I2C_HID_CMD (0x08 ) }; -/* read/write data register */ -static const struct i2c_hid_cmd hid_data_cmd = { - .registerIndex = offsetof(struct i2c_hid_desc , wDataRegister), - .opcode =0x00 , - .length =2 }; -/* write output reports */ -static const struct i2c_hid_cmd hid_out_cmd = { - .registerIndex = offsetof(struct i2c_hid_desc , - wOutputRegister), - .opcode =0x00 , - .length =2 }; + +/* +* These definitions are not used here, but are defined by the spec. +* Keeping them here for documentation purposes. +* +* static const struct i2c_hid_cmd hid_get_idle_cmd = { I2C_HID_CMD(0x04) }; +* static const struct i2c_hid_cmd hid_set_idle_cmd = { I2C_HID_CMD(0x05) }; +* static const struct i2c_hid_cmd hid_get_protocol_cmd = { I2C_HID_CMD(0x06) }; +* static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) }; +*/
Quoted 4 lines
drivers/hid/i2c-hid/i2c-hid.c static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01), · line 122
Quoted 2 lines
drivers/hid/i2c-hid/i2c-hid.c +0
-0/* The main device structure */ struct i2c_hid {Reviewed-by Jean Delvare <[email protected]>
Applied.
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 7/14 HID: i2c-hid: fix return paths
In reply to Benjamin TissoiresForwards appropriate return values.
As noone use the error returned by i2c_hid_get_input, let's make it returning void.
--- drivers/hid/i2c-hid/i2c-hid.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/hid/i2c-hid/i2c-hid.c +12 -12
@@ -245,7 +245,7 @@ static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,if (ret) {dev_err (&client->dev,"failed to retrieve report from device.\n" ); -return -EINVAL ; +return ret; }return 0 ;
@@ -290,7 +290,7 @@ static int i2c_hid_set_report(struct i2c_client *client, u8 reportType, reportType, args, args_len, NULL, 0);if (ret) {dev_err (&client->dev,"failed to set a report to device.\n" ); -return -EINVAL ; +return ret; }return data_len;
@@ -334,7 +334,7 @@ static int i2c_hid_hwreset(struct i2c_client *client)return 0 ; } -static int i2c_hid_get_input (struct i2c_hid *ihid) +static void i2c_hid_get_input (struct i2c_hid *ihid) {int ret, ret_size;int size =le16_to_cpu (ihid->hdesc.wMaxInputLength);
@@ -342,11 +342,11 @@ static int i2c_hid_get_input(struct i2c_hid *ihid) ret =i2c_master_recv (ihid->client, ihid->inbuf, size);if (ret != size) {if (ret <0 ) -return ret; +return ;dev_err (&ihid->client->dev,"%s: got %d data instead of %d\n" , __func__, ret, size); -return ret; +return ; } ret_size = ihid->inbuf[0 ] | ihid->inbuf[1 ] <<8 ;
@@ -355,13 +355,13 @@ static int i2c_hid_get_input(struct i2c_hid *ihid)/* host or device initiated RESET completed */ if (test_and_clear_bit (I2C_HID_RESET_PENDING , &ihid->flags))wake_up (&ihid->wait); -return 0 ; +return ; }if (ret_size > size) {dev_err (&ihid->client->dev,"%s: incomplete report (%d/%d)\n" , __func__, size, ret_size); -return -EIO ; +return ; }i2c_hid_dbg (ihid,"input: %*ph\n" , ret_size, ihid->inbuf);
@@ -370,7 +370,7 @@ static int i2c_hid_get_input(struct i2c_hid *ihid)hid_input_report (ihid->hid,HID_INPUT_REPORT , ihid->inbuf +2 , ret_size -2 ,1 ); -return 0 ; +return ; }static irqreturn_t i2c_hid_irq (int irq,void *dev_id)
@@ -430,8 +430,10 @@ static void i2c_hid_init_reports(struct hid_device *hid)struct i2c_hid *ihid =i2c_get_clientdata (client);u8 *inbuf =kzalloc (ihid->bufsize,GFP_KERNEL ); -if (!inbuf) +if (!inbuf) { +dev_err (&client->dev,"can not retrieve initial reports\n" );return ; + }list_for_each_entry (report, &hid->report_enum[HID_INPUT_REPORT ].report_list, list)
@@ -715,9 +717,7 @@ static int i2c_hid_hidinput_input_event(struct input_dev *dev,return -1 ; } -hid_set_field (field, offset, value); - -return 0 ; +return hid_set_field (field, offset, value); }static struct hid_ll_driver i2c_hid_ll_driver = {
Signature · 1 line
1.8.0.1
Re: [PATCH 07/14] HID: i2c-hid: fix return paths
Quoted 80 lines · Benjamin Tissoires
Forwards appropriate return values.
As noone use the error returned byi2c_hid_get_input, let's make it returning void.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +8
-8@@ -245,7 +245,7 @@ static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,if (ret) {dev_err (&client->dev,"failed to retrieve report from device.\n" ); -return -EINVAL ; +return ret; }return 0 ;@@ -290,7 +290,7 @@ static int i2c_hid_set_report(struct i2c_client *client, u8 reportType, reportType, args, args_len, NULL, 0);if (ret) {dev_err (&client->dev,"failed to set a report to device.\n" ); -return -EINVAL ; +return ret; }return data_len;@@ -334,7 +334,7 @@ static int i2c_hid_hwreset(struct i2c_client *client)return 0 ; } -static int i2c_hid_get_input (struct i2c_hid *ihid) +static void i2c_hid_get_input (struct i2c_hid *ihid) {int ret, ret_size;int size =le16_to_cpu (ihid->hdesc.wMaxInputLength);@@ -342,11 +342,11 @@ static int i2c_hid_get_input(struct i2c_hid *ihid) ret =i2c_master_recv (ihid->client, ihid->inbuf, size);if (ret != size) {if (ret <0 ) -return ret; +return ;dev_err (&ihid->client->dev,"%s: got %d data instead of %d\n" , __func__, ret, size); -return ret; +return ; } ret_size = ihid->inbuf[0 ] | ihid->inbuf[1 ] <<8 ;@@ -355,13 +355,13 @@ static int i2c_hid_get_input(struct i2c_hid *ihid)/* host or device initiated RESET completed */ if (test_and_clear_bit (I2C_HID_RESET_PENDING , &ihid->flags))wake_up (&ihid->wait); -return 0 ; +return ; }if (ret_size > size) {dev_err (&ihid->client->dev,"%s: incomplete report (%d/%d)\n" , __func__, size, ret_size); -return -EIO ; +return ; }i2c_hid_dbg (ihid,"input: %*ph\n" , ret_size, ihid->inbuf);@@ -370,7 +370,7 @@ static int i2c_hid_get_input(struct i2c_hid *ihid)hid_input_report (ihid->hid,HID_INPUT_REPORT , ihid->inbuf +2 , ret_size -2 ,1 ); -return 0 ; +return ; }static irqreturn_t i2c_hid_irq (int irq,void *dev_id)
drivers/hid/i2c-hid/i2c-hid.c static void i2c_hid_init_reports(struct hid_device *hid) · line 436
Quoted 8 lines
drivers/hid/i2c-hid/i2c-hid.c +3
-1@@ -430,8 +430,10 @@ static void i2c_hid_init_reports(struct hid_device *hid)struct i2c_hid *ihid =i2c_get_clientdata (client);u8 *inbuf =kzalloc (ihid->bufsize,GFP_KERNEL ); -if (!inbuf) +if (!inbuf) { +dev_err (&client->dev,"can not retrieve initial reports\n" );return ; + }
This change would have been better located in patch 07/14 IMHO, but that's a detail.
Quoted 4 lines
drivers/hid/i2c-hid/i2c-hid.c +0
-0list_for_each_entry (report, &hid->report_enum[HID_INPUT_REPORT ].report_list, list)
drivers/hid/i2c-hid/i2c-hid.c static int i2c_hid_hidinput_input_event(struct input_dev *dev, · line 723
Quoted 10 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-3@@ -715,9 +717,7 @@ static int i2c_hid_hidinput_input_event(struct input_dev *dev,return -1 ; } -hid_set_field (field, offset, value); - -return 0 ; +return hid_set_field (field, offset, value); }static struct hid_ll_driver i2c_hid_ll_driver = {
Signature · 1 line
Jean Delvare
Jiri Kosina
AppliedRe: [PATCH 07/14] HID: i2c-hid: fix return paths
In reply to Benjamin TissoiresQuoted 5 lines · Benjamin Tissoires
Forwards appropriate return values.
As noone use the error returned byi2c_hid_get_input, let's make it returning void.Signed-off-by Benjamin Tissoires <[email protected]>
Applied.
Quoted 100 lines
--- drivers/hid/i2c-hid/i2c-hid.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +12
-12@@ -245,7 +245,7 @@ static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,if (ret) {dev_err (&client->dev,"failed to retrieve report from device.\n" ); -return -EINVAL ; +return ret; }return 0 ;@@ -290,7 +290,7 @@ static int i2c_hid_set_report(struct i2c_client *client, u8 reportType, reportType, args, args_len, NULL, 0);if (ret) {dev_err (&client->dev,"failed to set a report to device.\n" ); -return -EINVAL ; +return ret; }return data_len;@@ -334,7 +334,7 @@ static int i2c_hid_hwreset(struct i2c_client *client)return 0 ; } -static int i2c_hid_get_input (struct i2c_hid *ihid) +static void i2c_hid_get_input (struct i2c_hid *ihid) {int ret, ret_size;int size =le16_to_cpu (ihid->hdesc.wMaxInputLength);@@ -342,11 +342,11 @@ static int i2c_hid_get_input(struct i2c_hid *ihid) ret =i2c_master_recv (ihid->client, ihid->inbuf, size);if (ret != size) {if (ret <0 ) -return ret; +return ;dev_err (&ihid->client->dev,"%s: got %d data instead of %d\n" , __func__, ret, size); -return ret; +return ; } ret_size = ihid->inbuf[0 ] | ihid->inbuf[1 ] <<8 ;@@ -355,13 +355,13 @@ static int i2c_hid_get_input(struct i2c_hid *ihid)/* host or device initiated RESET completed */ if (test_and_clear_bit (I2C_HID_RESET_PENDING , &ihid->flags))wake_up (&ihid->wait); -return 0 ; +return ; }if (ret_size > size) {dev_err (&ihid->client->dev,"%s: incomplete report (%d/%d)\n" , __func__, size, ret_size); -return -EIO ; +return ; }i2c_hid_dbg (ihid,"input: %*ph\n" , ret_size, ihid->inbuf);@@ -370,7 +370,7 @@ static int i2c_hid_get_input(struct i2c_hid *ihid)hid_input_report (ihid->hid,HID_INPUT_REPORT , ihid->inbuf +2 , ret_size -2 ,1 ); -return 0 ; +return ; }static irqreturn_t i2c_hid_irq (int irq,void *dev_id)@@ -430,8 +430,10 @@ static void i2c_hid_init_reports(struct hid_device *hid)struct i2c_hid *ihid =i2c_get_clientdata (client);u8 *inbuf =kzalloc (ihid->bufsize,GFP_KERNEL ); -if (!inbuf) +if (!inbuf) { +dev_err (&client->dev,"can not retrieve initial reports\n" );return ; + }list_for_each_entry (report, &hid->report_enum[HID_INPUT_REPORT ].report_list, list)@@ -715,9 +717,7 @@ static int i2c_hid_hidinput_input_event(struct input_dev *dev,return -1 ; } -hid_set_field (field, offset, value); - -return 0 ; +return hid_set_field (field, offset, value); }static struct hid_ll_driver i2c_hid_ll_driver = {Signature · 1 line
1.8.0.1
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 8/14 HID: i2c-hid: fix error messages
In reply to Benjamin Tissoires--- drivers/hid/i2c-hid/i2c-hid.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/hid/i2c-hid/i2c-hid.c +6 -5
@@ -741,10 +741,10 @@ static int __devinit i2c_hid_init_irq(struct i2c_client *client)IRQF_TRIGGER_FALLING |IRQF_ONESHOT , client->name, ihid);if (ret <0 ) { -dev_dbg (&client->dev, +dev_warn (&client->dev,"Could not register for %s interrupt, irq = %d," " ret = %d\n" , - client->name, client->irq, ret); + client->name, client->irq, ret);return ret; }
@@ -770,7 +770,8 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) __func__, 4, ihid->hdesc_buffer);if (ret) { -dev_err (&client->dev,"HID_DESCR_LENGTH_CMD Fail (ret=%d)\n" , +dev_err (&client->dev, +"unable to fetch the size of HID descriptor (ret=%d)\n" , ret);return -ENODEV ; }
@@ -785,7 +786,7 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)/* check bcdVersion == 1.0 */ if (le16_to_cpu (hdesc->bcdVersion) !=0x0100 ) {dev_err (&client->dev, -"unexpected HID descriptor bcdVersion (0x%04x)\n" , +"unexpected HID descriptor bcdVersion (0x%04hx)\n" ,le16_to_cpu (hdesc->bcdVersion));return -ENODEV ; }
@@ -871,7 +872,7 @@ static int __devinit i2c_hid_probe(struct i2c_client *client, hid->vendor =le16_to_cpu (ihid->hdesc.wVendorID); hid->product =le16_to_cpu (ihid->hdesc.wProductID); -snprintf (hid->name,sizeof (hid->name),"%s %04X:%04X" , +snprintf (hid->name,sizeof (hid->name),"%s %04hX:%04hX" , client->name, hid->vendor, hid->product); ret =hid_add_device (hid);
Signature · 1 line
1.8.0.1
Re: [PATCH 08/14] HID: i2c-hid: fix error messages
Quoted 42 lines · Benjamin Tissoires
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +5
-4@@ -741,10 +741,10 @@ static int __devinit i2c_hid_init_irq(struct i2c_client *client)IRQF_TRIGGER_FALLING |IRQF_ONESHOT , client->name, ihid);if (ret <0 ) { -dev_dbg (&client->dev, +dev_warn (&client->dev,"Could not register for %s interrupt, irq = %d," " ret = %d\n" , - client->name, client->irq, ret); + client->name, client->irq, ret);return ret; }@@ -770,7 +770,8 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) __func__, 4, ihid->hdesc_buffer);if (ret) { -dev_err (&client->dev,"HID_DESCR_LENGTH_CMD Fail (ret=%d)\n" , +dev_err (&client->dev, +"unable to fetch the size of HID descriptor (ret=%d)\n" , ret);return -ENODEV ; }@@ -785,7 +786,7 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)/* check bcdVersion == 1.0 */ if (le16_to_cpu (hdesc->bcdVersion) !=0x0100 ) {dev_err (&client->dev, -"unexpected HID descriptor bcdVersion (0x%04x)\n" , +"unexpected HID descriptor bcdVersion (0x%04hx)\n" ,le16_to_cpu (hdesc->bcdVersion));return -ENODEV ; }
drivers/hid/i2c-hid/i2c-hid.c static int __devinit i2c_hid_probe(struct i2c_client *client, · line 878
Quoted 8 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-1@@ -871,7 +872,7 @@ static int __devinit i2c_hid_probe(struct i2c_client *client, hid->vendor =le16_to_cpu (ihid->hdesc.wVendorID); hid->product =le16_to_cpu (ihid->hdesc.wProductID); -snprintf (hid->name,sizeof (hid->name),"%s %04X:%04X" , +snprintf (hid->name,sizeof (hid->name),"%s %04hX:%04hX" , client->name, hid->vendor, hid->product); ret =hid_add_device (hid);
Signature · 1 line
Jean Delvare
Jiri Kosina
AppliedRe: [PATCH 08/14] HID: i2c-hid: fix error messages
Quoted 45 lines · Jean Delvare
Quoted 45 lines
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +5
-4@@ -741,10 +741,10 @@ static int __devinit i2c_hid_init_irq(struct i2c_client *client)IRQF_TRIGGER_FALLING |IRQF_ONESHOT , client->name, ihid);if (ret <0 ) { -dev_dbg (&client->dev, +dev_warn (&client->dev,"Could not register for %s interrupt, irq = %d," " ret = %d\n" , - client->name, client->irq, ret); + client->name, client->irq, ret);return ret; }@@ -770,7 +770,8 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) __func__, 4, ihid->hdesc_buffer);if (ret) { -dev_err (&client->dev,"HID_DESCR_LENGTH_CMD Fail (ret=%d)\n" , +dev_err (&client->dev, +"unable to fetch the size of HID descriptor (ret=%d)\n" , ret);return -ENODEV ; }@@ -785,7 +786,7 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)/* check bcdVersion == 1.0 */ if (le16_to_cpu (hdesc->bcdVersion) !=0x0100 ) {dev_err (&client->dev, -"unexpected HID descriptor bcdVersion (0x%04x)\n" , +"unexpected HID descriptor bcdVersion (0x%04hx)\n" ,le16_to_cpu (hdesc->bcdVersion));return -ENODEV ; }@@ -871,7 +872,7 @@ static int __devinit i2c_hid_probe(struct i2c_client *client, hid->vendor =le16_to_cpu (ihid->hdesc.wVendorID); hid->product =le16_to_cpu (ihid->hdesc.wProductID);
Quoted 7 lines
drivers/hid/i2c-hid/i2c-hid.c static int __devinit i2c_hid_probe(struct i2c_client *client, · line 878
Quoted 5 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-1-snprintf (hid->name,sizeof (hid->name),"%s %04X:%04X" , +snprintf (hid->name,sizeof (hid->name),"%s %04hX:%04hX" , client->name, hid->vendor, hid->product); ret =hid_add_device (hid);Reviewed-by Jean Delvare <[email protected]>
Applied.
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 9/14 HID: i2c-hid: i2c_hid_get_report may fail
In reply to Benjamin TissoiresIf i2c_hid_get_report fails, exit i2c_hid_init_report. The printk log is already called by i2c_hid_get_report, so no need to add some more printks.
--- drivers/hid/i2c-hid/i2c-hid.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hid/i2c-hid/i2c-hid.c +3 -2
@@ -400,9 +400,10 @@ static void i2c_hid_init_report(struct hid_report *report, u8 *buffer,unsigned int size, ret_size; size =i2c_hid_get_report_length (report); -i2c_hid_get_report (client, +if (i2c_hid_get_report (client, report->type ==HID_FEATURE_REPORT ?0x03 :0x01 , - report->id, buffer, size); + report->id, buffer, size)) +return ;i2c_hid_dbg (ihid,"report (len=%d): %*ph\n" , size, size, ihid->inbuf);
Signature · 1 line
1.8.0.1
Re: [PATCH 09/14] HID: i2c-hid: i2c_hid_get_report may fail
Quoted 16 lines · Benjamin Tissoires
If
i2c_hid_get_reportfails, exiti2c_hid_init_report. The printk log is already called byi2c_hid_get_report, so no need to add some more printks.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +0
-0@@ -400,9 +400,10 @@ static void i2c_hid_init_report(struct hid_report *report, u8 *buffer,unsigned int size, ret_size;
drivers/hid/i2c-hid/i2c-hid.c static void i2c_hid_init_report(struct hid_report *report, u8 *buffer, · line 409
Quoted 10 lines
drivers/hid/i2c-hid/i2c-hid.c +3
-2size =i2c_hid_get_report_length (report); -i2c_hid_get_report (client, +if (i2c_hid_get_report (client, report->type ==HID_FEATURE_REPORT ?0x03 :0x01 , - report->id, buffer, size); + report->id, buffer, size)) +return ;i2c_hid_dbg (ihid,"report (len=%d): %*ph\n" , size, size, ihid->inbuf);
OK, although I don't quite get the rationale for not reporting the errors from i2c_hid_init_report() and i2c_hid_init_reports() to their respective callers. Does the device have any chance to work properly if i2c_hid_init_reports() fails?
Signature · 1 line
Jean Delvare
Re: [PATCH 09/14] HID: i2c-hid: i2c_hid_get_report may fail
Quoted 25 lines · Jean Delvare
Quoted 24 lines · Benjamin Tissoires
If
i2c_hid_get_reportfails, exiti2c_hid_init_report. The printk log is already called byi2c_hid_get_report, so no need to add some more printks.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +3
-2@@ -400,9 +400,10 @@ static void i2c_hid_init_report(struct hid_report *report, u8 *buffer,unsigned int size, ret_size; size =i2c_hid_get_report_length (report); -i2c_hid_get_report (client, +if (i2c_hid_get_report (client, report->type ==HID_FEATURE_REPORT ?0x03 :0x01 , - report->id, buffer, size); + report->id, buffer, size)) +return ;
Quoted 7 lines
drivers/hid/i2c-hid/i2c-hid.c static void i2c_hid_init_report(struct hid_report *report, u8 *buffer, · line 409
Quoted 2 lines
drivers/hid/i2c-hid/i2c-hid.c +0
-0i2c_hid_dbg (ihid,"report (len=%d): %*ph\n" , size, size, ihid->inbuf);OK, although I don't quite get the rationale for not reporting the errors from
i2c_hid_init_report()andi2c_hid_init_reports()to their respective callers. Does the device have any chance to work properly ifi2c_hid_init_reports()fails?
Hi Jean,
first thanks for the review you have started.
For your question, the answer is yes, the device works properly even if i2c_hid_init_reports().
IIRC, the only required steps are:
- get HID descriptor
- get HID report descriptors
- send reset
- set power on
i2c_hid_init_reports is not part of the specification for the boot
process, and the Windows driver does not retrieve the reports for input reports at all (it does it though for the features). Actually, the device I have does not implement get_report for inputs (it returns 0), but it's not a problem for it to work.
I put the whole init_reports in place to get the features values before sending them to the hid driver, and also to copy the behavior of usbhid.
Cheers,
Benjamin
Quoted 5 lines
Reviewed-by Jean Delvare <[email protected]>--
Jean Delvare
Jiri Kosina
AppliedRe: [PATCH 09/14] HID: i2c-hid: i2c_hid_get_report may fail
In reply to Benjamin TissoiresQuoted 15 lines · Benjamin Tissoires
If
i2c_hid_get_reportfails, exiti2c_hid_init_report. The printk log is already called byi2c_hid_get_report, so no need to add some more printks.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +0
-0@@ -400,9 +400,10 @@ static void i2c_hid_init_report(struct hid_report *report, u8 *buffer,unsigned int size, ret_size;
drivers/hid/i2c-hid/i2c-hid.c static void i2c_hid_init_report(struct hid_report *report, u8 *buffer, · line 408
Quoted 10 lines
drivers/hid/i2c-hid/i2c-hid.c +3
-2size =i2c_hid_get_report_length (report); -i2c_hid_get_report (client, +if (i2c_hid_get_report (client, report->type ==HID_FEATURE_REPORT ?0x03 :0x01 , - report->id, buffer, size); + report->id, buffer, size)) +return ;i2c_hid_dbg (ihid,"report (len=%d): %*ph\n" , size, size, ihid->inbuf);
Applied.
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 10/14 HID: i2c-hid: reorder allocation/free of buffers
In reply to Benjamin TissoiresSimplifies i2c_hid_alloc_buffers tests, and makes this function responsible of the assignment of ihid->bufsize.
The condition for the reallocation in i2c_hid_start is then simpler.
--- drivers/hid/i2c-hid/i2c-hid.c | 68 ++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 40 deletions(-)
drivers/hid/i2c-hid/i2c-hid.c +28 -40
@@ -465,48 +465,38 @@ static void i2c_hid_find_max_report(struct hid_device *hid, unsigned int type, } } -static int i2c_hid_alloc_buffers (struct i2c_hid *ihid) +static void i2c_hid_free_buffers (struct i2c_hid *ihid) +{ +kfree (ihid->inbuf); +kfree (ihid->argsbuf); +kfree (ihid->cmdbuf); + ihid->inbuf =NULL ; + ihid->cmdbuf =NULL ; + ihid->argsbuf =NULL ; + ihid->bufsize =0 ; +} + +static int i2c_hid_alloc_buffers (struct i2c_hid *ihid,size_t report_size) {/* the worst case is computed from the set_report command with a * reportID > 15 and the maximum report length */ int args_len =sizeof (__u8) +/* optional ReportID byte */ sizeof (__u16) +/* data register */ sizeof (__u16) +/* size of the report */ - ihid->bufsize;/* report */ - - ihid->inbuf =kzalloc (ihid->bufsize,GFP_KERNEL ); - -if (!ihid->inbuf) -return -ENOMEM ; + report_size;/* report */ + ihid->inbuf =kzalloc (report_size,GFP_KERNEL ); ihid->argsbuf =kzalloc (args_len,GFP_KERNEL ); - -if (!ihid->argsbuf) { -kfree (ihid->inbuf); -return -ENOMEM ; - } - ihid->cmdbuf =kzalloc (sizeof (union command ) + args_len,GFP_KERNEL ); -if (!ihid->cmdbuf) { -kfree (ihid->inbuf); -kfree (ihid->argsbuf); - ihid->inbuf =NULL ; - ihid->argsbuf =NULL ; +if (!ihid->inbuf || !ihid->argsbuf || !ihid->cmdbuf) { +i2c_hid_free_buffers (ihid);return -ENOMEM ; } -return 0 ; -} + ihid->bufsize = report_size; -static void i2c_hid_free_buffers (struct i2c_hid *ihid) -{ -kfree (ihid->inbuf); -kfree (ihid->argsbuf); -kfree (ihid->cmdbuf); - ihid->inbuf =NULL ; - ihid->cmdbuf =NULL ; - ihid->argsbuf =NULL ; +return 0 ; } static int i2c_hid_get_raw_report(struct hid_device *hid,
@@ -611,22 +601,19 @@ static int i2c_hid_start(struct hid_device *hid)struct i2c_client *client = hid->driver_data;struct i2c_hid *ihid =i2c_get_clientdata (client);int ret; -int old_bufsize = ihid->bufsize; +unsigned int bufsize =HID_MIN_BUFFER_SIZE ; - ihid->bufsize =HID_MIN_BUFFER_SIZE ; -i2c_hid_find_max_report (hid,HID_INPUT_REPORT , &ihid->bufsize); -i2c_hid_find_max_report (hid,HID_OUTPUT_REPORT , &ihid->bufsize); -i2c_hid_find_max_report (hid,HID_FEATURE_REPORT , &ihid->bufsize); +i2c_hid_find_max_report (hid,HID_INPUT_REPORT , &bufsize); +i2c_hid_find_max_report (hid,HID_OUTPUT_REPORT , &bufsize); +i2c_hid_find_max_report (hid,HID_FEATURE_REPORT , &bufsize); -if (ihid->bufsize > old_bufsize || !ihid->inbuf || !ihid->cmdbuf) { +if (bufsize > ihid->bufsize) {i2c_hid_free_buffers (ihid); - ret =i2c_hid_alloc_buffers (ihid); + ret =i2c_hid_alloc_buffers (ihid, bufsize); -if (ret) { - ihid->bufsize = old_bufsize; +if (ret)return ret; - } }if (!(hid->quirks &HID_QUIRK_NO_INIT_REPORTS ))
@@ -844,8 +831,9 @@ static int __devinit i2c_hid_probe(struct i2c_client *client,/* we need to allocate the command buffer without knowing the maximum * size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the * real computation later. */ - ihid->bufsize =HID_MIN_BUFFER_SIZE ; -i2c_hid_alloc_buffers (ihid); + ret =i2c_hid_alloc_buffers (ihid,HID_MIN_BUFFER_SIZE ); +if (ret <0 ) + goto err; ret =i2c_hid_fetch_hid_descriptor (ihid);if (ret <0 )
Signature · 1 line
1.8.0.1
Re: [PATCH 10/14] HID: i2c-hid: reorder allocation/free of buffers
Quoted 112 lines · Benjamin Tissoires
Simplifies
i2c_hid_alloc_bufferstests, and makes this function responsible of the assignment ofihid->bufsize.
The condition for the reallocation ini2c_hid_startis then simpler.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 68 ++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 40 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +25
-38@@ -465,48 +465,38 @@ static void i2c_hid_find_max_report(struct hid_device *hid, unsigned int type, } } -static int i2c_hid_alloc_buffers (struct i2c_hid *ihid) +static void i2c_hid_free_buffers (struct i2c_hid *ihid) +{ +kfree (ihid->inbuf); +kfree (ihid->argsbuf); +kfree (ihid->cmdbuf); + ihid->inbuf =NULL ; + ihid->cmdbuf =NULL ; + ihid->argsbuf =NULL ; + ihid->bufsize =0 ; +} + +static int i2c_hid_alloc_buffers (struct i2c_hid *ihid,size_t report_size) {/* the worst case is computed from the set_report command with a * reportID > 15 and the maximum report length */ int args_len =sizeof (__u8) +/* optional ReportID byte */ sizeof (__u16) +/* data register */ sizeof (__u16) +/* size of the report */ - ihid->bufsize;/* report */ - - ihid->inbuf =kzalloc (ihid->bufsize,GFP_KERNEL ); - -if (!ihid->inbuf) -return -ENOMEM ; + report_size;/* report */ + ihid->inbuf =kzalloc (report_size,GFP_KERNEL ); ihid->argsbuf =kzalloc (args_len,GFP_KERNEL ); - -if (!ihid->argsbuf) { -kfree (ihid->inbuf); -return -ENOMEM ; - } - ihid->cmdbuf =kzalloc (sizeof (union command ) + args_len,GFP_KERNEL ); -if (!ihid->cmdbuf) { -kfree (ihid->inbuf); -kfree (ihid->argsbuf); - ihid->inbuf =NULL ; - ihid->argsbuf =NULL ; +if (!ihid->inbuf || !ihid->argsbuf || !ihid->cmdbuf) { +i2c_hid_free_buffers (ihid);return -ENOMEM ; } -return 0 ; -} + ihid->bufsize = report_size; -static void i2c_hid_free_buffers (struct i2c_hid *ihid) -{ -kfree (ihid->inbuf); -kfree (ihid->argsbuf); -kfree (ihid->cmdbuf); - ihid->inbuf =NULL ; - ihid->cmdbuf =NULL ; - ihid->argsbuf =NULL ; +return 0 ; } static int i2c_hid_get_raw_report(struct hid_device *hid,@@ -611,22 +601,19 @@ static int i2c_hid_start(struct hid_device *hid)struct i2c_client *client = hid->driver_data;struct i2c_hid *ihid =i2c_get_clientdata (client);int ret; -int old_bufsize = ihid->bufsize; +unsigned int bufsize =HID_MIN_BUFFER_SIZE ; - ihid->bufsize =HID_MIN_BUFFER_SIZE ; -i2c_hid_find_max_report (hid,HID_INPUT_REPORT , &ihid->bufsize); -i2c_hid_find_max_report (hid,HID_OUTPUT_REPORT , &ihid->bufsize); -i2c_hid_find_max_report (hid,HID_FEATURE_REPORT , &ihid->bufsize); +i2c_hid_find_max_report (hid,HID_INPUT_REPORT , &bufsize); +i2c_hid_find_max_report (hid,HID_OUTPUT_REPORT , &bufsize); +i2c_hid_find_max_report (hid,HID_FEATURE_REPORT , &bufsize); -if (ihid->bufsize > old_bufsize || !ihid->inbuf || !ihid->cmdbuf) { +if (bufsize > ihid->bufsize) {i2c_hid_free_buffers (ihid); - ret =i2c_hid_alloc_buffers (ihid); + ret =i2c_hid_alloc_buffers (ihid, bufsize); -if (ret) { - ihid->bufsize = old_bufsize; +if (ret)return ret; - } }if (!(hid->quirks &HID_QUIRK_NO_INIT_REPORTS ))@@ -844,8 +831,9 @@ static int __devinit i2c_hid_probe(struct i2c_client *client,/* we need to allocate the command buffer without knowing the maximum
drivers/hid/i2c-hid/i2c-hid.c static int __devinit i2c_hid_probe(struct i2c_client *client, · line 839
Quoted 10 lines
drivers/hid/i2c-hid/i2c-hid.c +3
-2* size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the * real computation later. */ - ihid->bufsize =HID_MIN_BUFFER_SIZE ; -i2c_hid_alloc_buffers (ihid); + ret =i2c_hid_alloc_buffers (ihid,HID_MIN_BUFFER_SIZE ); +if (ret <0 ) + goto err; ret =i2c_hid_fetch_hid_descriptor (ihid);if (ret <0 )
Yes, looks much better.
Signature · 1 line
Jean Delvare
Re: [PATCH 10/14] HID: i2c-hid: reorder allocation/free of buffers
Quoted 121 lines · Jean Delvare
Quoted 120 lines · Benjamin Tissoires
Simplifies
i2c_hid_alloc_bufferstests, and makes this function responsible of the assignment ofihid->bufsize.
The condition for the reallocation ini2c_hid_startis then simpler.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 68 ++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 40 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +28
-40@@ -465,48 +465,38 @@ static void i2c_hid_find_max_report(struct hid_device *hid, unsigned int type, } } -static int i2c_hid_alloc_buffers (struct i2c_hid *ihid) +static void i2c_hid_free_buffers (struct i2c_hid *ihid) +{ +kfree (ihid->inbuf); +kfree (ihid->argsbuf); +kfree (ihid->cmdbuf); + ihid->inbuf =NULL ; + ihid->cmdbuf =NULL ; + ihid->argsbuf =NULL ; + ihid->bufsize =0 ; +} + +static int i2c_hid_alloc_buffers (struct i2c_hid *ihid,size_t report_size) {/* the worst case is computed from the set_report command with a * reportID > 15 and the maximum report length */ int args_len =sizeof (__u8) +/* optional ReportID byte */ sizeof (__u16) +/* data register */ sizeof (__u16) +/* size of the report */ - ihid->bufsize;/* report */ - - ihid->inbuf =kzalloc (ihid->bufsize,GFP_KERNEL ); - -if (!ihid->inbuf) -return -ENOMEM ; + report_size;/* report */ + ihid->inbuf =kzalloc (report_size,GFP_KERNEL ); ihid->argsbuf =kzalloc (args_len,GFP_KERNEL ); - -if (!ihid->argsbuf) { -kfree (ihid->inbuf); -return -ENOMEM ; - } - ihid->cmdbuf =kzalloc (sizeof (union command ) + args_len,GFP_KERNEL ); -if (!ihid->cmdbuf) { -kfree (ihid->inbuf); -kfree (ihid->argsbuf); - ihid->inbuf =NULL ; - ihid->argsbuf =NULL ; +if (!ihid->inbuf || !ihid->argsbuf || !ihid->cmdbuf) { +i2c_hid_free_buffers (ihid);return -ENOMEM ; } -return 0 ; -} + ihid->bufsize = report_size; -static void i2c_hid_free_buffers (struct i2c_hid *ihid) -{ -kfree (ihid->inbuf); -kfree (ihid->argsbuf); -kfree (ihid->cmdbuf); - ihid->inbuf =NULL ; - ihid->cmdbuf =NULL ; - ihid->argsbuf =NULL ; +return 0 ; } static int i2c_hid_get_raw_report(struct hid_device *hid,@@ -611,22 +601,19 @@ static int i2c_hid_start(struct hid_device *hid)struct i2c_client *client = hid->driver_data;struct i2c_hid *ihid =i2c_get_clientdata (client);int ret; -int old_bufsize = ihid->bufsize; +unsigned int bufsize =HID_MIN_BUFFER_SIZE ; - ihid->bufsize =HID_MIN_BUFFER_SIZE ; -i2c_hid_find_max_report (hid,HID_INPUT_REPORT , &ihid->bufsize); -i2c_hid_find_max_report (hid,HID_OUTPUT_REPORT , &ihid->bufsize); -i2c_hid_find_max_report (hid,HID_FEATURE_REPORT , &ihid->bufsize); +i2c_hid_find_max_report (hid,HID_INPUT_REPORT , &bufsize); +i2c_hid_find_max_report (hid,HID_OUTPUT_REPORT , &bufsize); +i2c_hid_find_max_report (hid,HID_FEATURE_REPORT , &bufsize); -if (ihid->bufsize > old_bufsize || !ihid->inbuf || !ihid->cmdbuf) { +if (bufsize > ihid->bufsize) {i2c_hid_free_buffers (ihid); - ret =i2c_hid_alloc_buffers (ihid); + ret =i2c_hid_alloc_buffers (ihid, bufsize); -if (ret) { - ihid->bufsize = old_bufsize; +if (ret)return ret; - } }if (!(hid->quirks &HID_QUIRK_NO_INIT_REPORTS ))@@ -844,8 +831,9 @@ static int __devinit i2c_hid_probe(struct i2c_client *client,/* we need to allocate the command buffer without knowing the maximum * size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the * real computation later. */ - ihid->bufsize =HID_MIN_BUFFER_SIZE ; -i2c_hid_alloc_buffers (ihid); + ret =i2c_hid_alloc_buffers (ihid,HID_MIN_BUFFER_SIZE ); +if (ret <0 ) + goto err;
Quoted 6 lines
drivers/hid/i2c-hid/i2c-hid.c static int __devinit i2c_hid_probe(struct i2c_client *client, · line 839
Quoted 2 lines
drivers/hid/i2c-hid/i2c-hid.c +0
-0ret =i2c_hid_fetch_hid_descriptor (ihid);if (ret <0 )Yes, looks much better.
Reviewed-by Jean Delvare <[email protected]>
Thanks Jean,
as mentioned in 2/14, this patch need the fix in 2/14 to be able to work. Jiri, I'll try to send a v2 ASAP so that you can pick both in the right order (otherwise, the bisect may fall between the two).
Cheers,
Benjamin
Quoted 3 lines
--
Jean Delvare
PATCH 11/14 HID: i2c-hid: remove unneeded test in i2c_hid_remove
In reply to Benjamin Tissoiresihid can not be null, so there are no reasons to test it.
--- drivers/hid/i2c-hid/i2c-hid.c | 3 --- 1 file changed, 3 deletions(-)
drivers/hid/i2c-hid/i2c-hid.c +0 -3
@@ -890,9 +890,6 @@ static int __devexit i2c_hid_remove(struct i2c_client *client)struct i2c_hid *ihid =i2c_get_clientdata (client);struct hid_device *hid; -if (WARN_ON (!ihid)) -return -1 ; - hid = ihid->hid;hid_destroy_device (hid);
Signature · 1 line
1.8.0.1
Re: [PATCH 11/14] HID: i2c-hid: remove unneeded test in i2c_hid_remove
Quoted 12 lines · Benjamin Tissoires
ihid can not be null, so there are no reasons to test it.
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 3 --- 1 file changed, 3 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +0
-0
drivers/hid/i2c-hid/i2c-hid.c static int __devexit i2c_hid_remove(struct i2c_client *client) · line 895
Quoted 9 lines
drivers/hid/i2c-hid/i2c-hid.c +0
-3@@ -890,9 +890,6 @@ static int __devexit i2c_hid_remove(struct i2c_client *client)struct i2c_hid *ihid =i2c_get_clientdata (client);struct hid_device *hid; -if (WARN_ON (!ihid)) -return -1 ; - hid = ihid->hid;hid_destroy_device (hid);
This leaves <linux/bug.h> included for no good reason. Please remove it too.
Signature · 1 line
Jean Delvare
Re: [PATCH 11/14] HID: i2c-hid: remove unneeded test in i2c_hid_remove
Quoted 15 lines · Jean Delvare
Quoted 15 lines
ihid can not be null, so there are no reasons to test it.
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 3 --- 1 file changed, 3 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +0
-0@@ -890,9 +890,6 @@ static int __devexit i2c_hid_remove(struct i2c_client *client)struct i2c_hid *ihid =i2c_get_clientdata (client);struct hid_device *hid;
Quoted 9 lines
drivers/hid/i2c-hid/i2c-hid.c static int __devexit i2c_hid_remove(struct i2c_client *client) · line 895
Quoted 6 lines
drivers/hid/i2c-hid/i2c-hid.c +0
-3-if (WARN_ON (!ihid)) -return -1 ; - hid = ihid->hid;hid_destroy_device (hid);This leaves <
linux/bug.h> included for no good reason. Please remove it too.
I have applied the patch, and removed the superfluous include as well, thanks for spotting that, Jean.
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 12/14 HID: i2c-hid: remove extra .irq field in struct i2c_hid
In reply to Benjamin TissoiresThere is no point in keeping the irq in i2c_hid as it's already there in client.
--- drivers/hid/i2c-hid/i2c-hid.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/hid/i2c-hid/i2c-hid.c +6 -11
@@ -136,8 +136,6 @@ struct i2c_hid {unsigned long flags;/* device flags */ -int irq;/* the interrupt line irq */ -wait_queue_head_t wait;/* For waiting the interrupt */ };
@@ -737,8 +735,6 @@ static int __devinit i2c_hid_init_irq(struct i2c_client *client)return ret; } - ihid->irq = client->irq; -return 0 ; }
@@ -841,12 +837,12 @@ static int __devinit i2c_hid_probe(struct i2c_client *client, ret =i2c_hid_init_irq (client);if (ret <0 ) - goto err; + goto err_irq; hid =hid_allocate_device ();if (IS_ERR (hid)) { ret =PTR_ERR (hid); - goto err; + goto err_irq; } ihid->hid = hid;
@@ -876,10 +872,10 @@ static int __devinit i2c_hid_probe(struct i2c_client *client, err_mem_free:hid_destroy_device (hid); -err: -if (ihid->irq) -free_irq (ihid->irq, ihid); +err_irq: +free_irq (client->irq, ihid); +err:i2c_hid_free_buffers (ihid);kfree (ihid);return ret;
@@ -904,10 +900,9 @@ static int __devexit i2c_hid_remove(struct i2c_client *client)static int i2c_hid_suspend (struct device *dev) {struct i2c_client *client =to_i2c_client (dev); -struct i2c_hid *ihid =i2c_get_clientdata (client);if (device_may_wakeup (&client->dev)) -enable_irq_wake (ihid->irq); +enable_irq_wake (client->irq);/* Save some power */ i2c_hid_set_power (client,I2C_HID_PWR_SLEEP );
Signature · 1 line
1.8.0.1
Re: [PATCH 12/14] HID: i2c-hid: remove extra .irq field in struct i2c_hid
Quoted 31 lines · Benjamin Tissoires
There is no point in keeping the irq in
i2c_hidas it's already there in client.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +0
-4@@ -136,8 +136,6 @@ struct i2c_hid {unsigned long flags;/* device flags */ -int irq;/* the interrupt line irq */ -wait_queue_head_t wait;/* For waiting the interrupt */ };@@ -737,8 +735,6 @@ static int __devinit i2c_hid_init_irq(struct i2c_client *client)return ret; } - ihid->irq = client->irq; -return 0 ; }
drivers/hid/i2c-hid/i2c-hid.c static int __devinit i2c_hid_probe(struct i2c_client *client, · line 840
Quoted 5 lines
drivers/hid/i2c-hid/i2c-hid.c +1
-1@@ -841,12 +837,12 @@ static int __devinit i2c_hid_probe(struct i2c_client *client, ret =i2c_hid_init_irq (client);if (ret <0 ) - goto err; + goto err_irq;
Looks wrong. If i2c_hid_init_irq() failed, the irq couldn't be requested so you don't want to free it.
Quoted 35 lines
drivers/hid/i2c-hid/i2c-hid.c +5
-6hid =hid_allocate_device ();if (IS_ERR (hid)) { ret =PTR_ERR (hid); - goto err; + goto err_irq; } ihid->hid = hid;@@ -876,10 +872,10 @@ static int __devinit i2c_hid_probe(struct i2c_client *client, err_mem_free:hid_destroy_device (hid); -err: -if (ihid->irq) -free_irq (ihid->irq, ihid); +err_irq: +free_irq (client->irq, ihid); +err:i2c_hid_free_buffers (ihid);kfree (ihid);return ret;@@ -904,10 +900,9 @@ static int __devexit i2c_hid_remove(struct i2c_client *client)static int i2c_hid_suspend (struct device *dev) {struct i2c_client *client =to_i2c_client (dev); -struct i2c_hid *ihid =i2c_get_clientdata (client);if (device_may_wakeup (&client->dev)) -enable_irq_wake (ihid->irq); +enable_irq_wake (client->irq);/* Save some power */ i2c_hid_set_power (client,I2C_HID_PWR_SLEEP );
Signature · 1 line
Jean Delvare
PATCH 13/14 HID: i2c-hid: also call i2c_hid_free_buffers in i2c_hid_remove
In reply to Benjamin TissoiresIn the case where the hid driver in charge of handling the hid part of the device (hid-generic for instance) fails at probe, neither i2c_hid_start nor i2c_hid_stop are called.
Thus, the buffers allocated in i2c_hid_probe are never freed.
--- drivers/hid/i2c-hid/i2c-hid.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/i2c-hid/i2c-hid.c +3 -0
@@ -891,6 +891,9 @@ static int __devexit i2c_hid_remove(struct i2c_client *client)free_irq (client->irq, ihid); +if (ihid->bufsize) +i2c_hid_free_buffers (ihid); +kfree (ihid);return 0 ;
Signature · 1 line
1.8.0.1
Jiri Kosina
AppliedRe: [PATCH 13/14] HID: i2c-hid: also call i2c_hid_free_buffers in i2c_hid_remove
Quoted 15 lines · Benjamin Tissoires
In the case where the hid driver in charge of handling the hid part of the device (hid-generic for instance) fails at probe, neither
i2c_hid_startnori2c_hid_stopare called.
Thus, the buffers allocated ini2c_hid_probeare never freed.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 3 +++ 1 file changed, 3 insertions(+)drivers/hid/i2c-hid/i2c-hid.c +0
-0
drivers/hid/i2c-hid/i2c-hid.c static int __devexit i2c_hid_remove(struct i2c_client *client) · line 897
Quoted 7 lines
drivers/hid/i2c-hid/i2c-hid.c +3
-0@@ -891,6 +891,9 @@ static int __devexit i2c_hid_remove(struct i2c_client *client)free_irq (client->irq, ihid); +if (ihid->bufsize) +i2c_hid_free_buffers (ihid); +kfree (ihid);
Applied.
Signature · 2 lines
Jiri Kosina SUSE Labs
Re: [PATCH 13/14] HID: i2c-hid: also call i2c_hid_free_buffers in i2c_hid_remove
In reply to Benjamin TissoiresQuoted 15 lines · Benjamin Tissoires
In the case where the hid driver in charge of handling the hid part of the device (hid-generic for instance) fails at probe, neither
i2c_hid_startnori2c_hid_stopare called.
Thus, the buffers allocated ini2c_hid_probeare never freed.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 3 +++ 1 file changed, 3 insertions(+)drivers/hid/i2c-hid/i2c-hid.c +0
-0
drivers/hid/i2c-hid/i2c-hid.c static int __devexit i2c_hid_remove(struct i2c_client *client) · line 899
Quoted 9 lines
drivers/hid/i2c-hid/i2c-hid.c +3
-0@@ -891,6 +891,9 @@ static int __devexit i2c_hid_remove(struct i2c_client *client)free_irq (client->irq, ihid); +if (ihid->bufsize) +i2c_hid_free_buffers (ihid); +kfree (ihid);return 0 ;
Signature · 1 line
Jean Delvare
PATCH 14/14 HID: i2c-hid: fix i2c_hid_get_raw_report count mismatches
In reply to Benjamin TissoiresThe previous memcpy implementation relied on the size advertized by the device. There were no guarantees that buf was big enough.
Some gymnastic is also required with the +2/-2 to take into account the first 2 bytes where the total length is supplied by the device.
--- drivers/hid/i2c-hid/i2c-hid.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/hid/i2c-hid/i2c-hid.c +10 -3
@@ -503,13 +503,14 @@ static int i2c_hid_get_raw_report(struct hid_device *hid, {struct i2c_client *client = hid->driver_data;struct i2c_hid *ihid =i2c_get_clientdata (client); +size_t rcount;int ret;if (report_type ==HID_OUTPUT_REPORT )return -EINVAL ; -if (count > ihid->bufsize) - count = ihid->bufsize; +if (count > ihid->bufsize -2 ) + count = ihid->bufsize -2 ; ret = i2c_hid_get_report(client, report_type == HID_FEATURE_REPORT ? 0x03 : 0x01,
@@ -518,7 +519,13 @@ static int i2c_hid_get_raw_report(struct hid_device *hid,if (ret <0 )return ret; - count = ihid->inbuf[0 ] | (ihid->inbuf[1 ] <<8 ); + rcount = ihid->inbuf[0 ] | (ihid->inbuf[1 ] <<8 ); + +if (!rcount) +return 0 ; + +if (count > rcount -2 ) + count = rcount -2 ;memcpy (buf, ihid->inbuf +2 , count);
Signature · 1 line
1.8.0.1
Re: [PATCH 14/14] HID: i2c-hid: fix i2c_hid_get_raw_report count mismatches
Hi,
sorry, but when I re-read it, it seems that I missed a +2 in the call of i2c_hid_get_report.
So Jean, Jiri, please ignore this one. I'm really sorry if you already started reviewing it.
I'll send a v2 with the missing patches early this afternoon.
Cheers,
Benjamin
Quoted 50 lines · Benjamin Tissoires
The previous memcpy implementation relied on the size advertized by the device. There were no guarantees that buf was big enough.
Some gymnastic is also required with the +2/-2 to take into account the first 2 bytes where the total length is supplied by the device.
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/i2c-hid/i2c-hid.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/hid/i2c-hid/i2c-hid.c +10
-4@@ -503,13 +503,14 @@ static int i2c_hid_get_raw_report(struct hid_device *hid, {struct i2c_client *client = hid->driver_data;struct i2c_hid *ihid =i2c_get_clientdata (client); +size_t rcount;int ret;if (report_type ==HID_OUTPUT_REPORT )return -EINVAL ; -if (count > ihid->bufsize) - count = ihid->bufsize; +if (count > ihid->bufsize -2 ) + count = ihid->bufsize -2 ; ret = i2c_hid_get_report(client, report_type == HID_FEATURE_REPORT ? 0x03 : 0x01,@@ -518,7 +519,13 @@ static int i2c_hid_get_raw_report(struct hid_device *hid,if (ret <0 )return ret; - count = ihid->inbuf[0 ] | (ihid->inbuf[1 ] <<8 ); + rcount = ihid->inbuf[0 ] | (ihid->inbuf[1 ] <<8 ); + +if (!rcount) +return 0 ; + +if (count > rcount -2 ) + count = rcount -2 ;memcpy (buf, ihid->inbuf +2 , count); --1.8.0.1