public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] HID: cp2112: fix I2C_SMBUS_BYTE write
@ 2015-07-13 22:23 Ellen Wang
  2015-07-14  8:46 ` Antonio Borneo
       [not found] ` <1436826234-2447-1-git-send-email-ellen-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Ellen Wang @ 2015-07-13 22:23 UTC (permalink / raw)
  To: borneo.antonio, dbarksdale, jkosina, linux-input, linux-i2c; +Cc: ellen

When doing an I2C_SMBUS_BYTE write (one byte write, no address),
the data to be written is in "command" not "data->byte".

Signed-off-by: Ellen Wang <ellen@cumulusnetworks.com>
---
Forgot signed-off-by tag last time, sorry.
---
 drivers/hid/hid-cp2112.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
index a3703b8..7afc3fc 100644
--- a/drivers/hid/hid-cp2112.c
+++ b/drivers/hid/hid-cp2112.c
@@ -606,7 +606,7 @@ static int cp2112_xfer(struct i2c_adapter *adap, u16 addr,
 		if (I2C_SMBUS_READ == read_write)
 			count = cp2112_read_req(buf, addr, read_length);
 		else
-			count = cp2112_write_req(buf, addr, data->byte, NULL,
+			count = cp2112_write_req(buf, addr, command, NULL,
 						 0);
 		break;
 	case I2C_SMBUS_BYTE_DATA:
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] HID: cp2112: fix I2C_SMBUS_BYTE write
  2015-07-13 22:23 [PATCH v2] HID: cp2112: fix I2C_SMBUS_BYTE write Ellen Wang
@ 2015-07-14  8:46 ` Antonio Borneo
       [not found] ` <1436826234-2447-1-git-send-email-ellen-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
  1 sibling, 0 replies; 8+ messages in thread
From: Antonio Borneo @ 2015-07-14  8:46 UTC (permalink / raw)
  To: Ellen Wang; +Cc: David Barksdale, Jiri Kosina, linux-input, linux-i2c

On Tue, Jul 14, 2015 at 6:23 AM, Ellen Wang <ellen@cumulusnetworks.com> wrote:
>
> When doing an I2C_SMBUS_BYTE write (one byte write, no address),
> the data to be written is in "command" not "data->byte".
>
> Signed-off-by: Ellen Wang <ellen@cumulusnetworks.com>
> ---
> Forgot signed-off-by tag last time, sorry.
> ---
>  drivers/hid/hid-cp2112.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
> index a3703b8..7afc3fc 100644
> --- a/drivers/hid/hid-cp2112.c
> +++ b/drivers/hid/hid-cp2112.c
> @@ -606,7 +606,7 @@ static int cp2112_xfer(struct i2c_adapter *adap, u16 addr,
>                 if (I2C_SMBUS_READ == read_write)
>                         count = cp2112_read_req(buf, addr, read_length);
>                 else
> -                       count = cp2112_write_req(buf, addr, data->byte, NULL,
> +                       count = cp2112_write_req(buf, addr, command, NULL,
>                                                  0);
>                 break;
>         case I2C_SMBUS_BYTE_DATA:


Correct!

E.g. in drivers/i2c/i2c-core.c we have:

s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value)
{
       return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
                             I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
}

that passes NULL for data, so data->byte will dereference the NULL ptr.
The value is passed in "command".

Jiri,
I agree with Ellen that this driver is not commonly used, so no rush
to push the fix upstream.
But the fix should be marked for stable.

If you need, you can add
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>

BR
Antonio

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] HID: cp2112: fix I2C_SMBUS_BYTE write
       [not found] ` <1436826234-2447-1-git-send-email-ellen-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
@ 2015-07-14 11:49   ` Wolfram Sang
  2015-07-14 12:54     ` Jiri Kosina
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2015-07-14 11:49 UTC (permalink / raw)
  To: Ellen Wang
  Cc: borneo.antonio-Re5JQEeQqe8AvxtiuMwx3w,
	dbarksdale-2SNLKkHU5xRBDgjK7y7TUQ, jkosina-AlSwsSmVLrQ,
	linux-input-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 489 bytes --]

On Mon, Jul 13, 2015 at 03:23:54PM -0700, Ellen Wang wrote:
> When doing an I2C_SMBUS_BYTE write (one byte write, no address),
> the data to be written is in "command" not "data->byte".
> 
> Signed-off-by: Ellen Wang <ellen-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>

Acked-by: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>

Wow, that driver seems to be largely untested. Thanks for cleaning it
up! Sidenote: i2c drivers should really be in drivers/i2c ;)


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] HID: cp2112: fix I2C_SMBUS_BYTE write
  2015-07-14 11:49   ` Wolfram Sang
@ 2015-07-14 12:54     ` Jiri Kosina
       [not found]       ` <alpine.LNX.2.00.1507141452140.7522-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
  2015-07-14 22:54       ` Ellen Wang
  0 siblings, 2 replies; 8+ messages in thread
From: Jiri Kosina @ 2015-07-14 12:54 UTC (permalink / raw)
  To: Ellen Wang, Wolfram Sang
  Cc: borneo.antonio, dbarksdale, linux-input, linux-i2c

On Mon, 13 Jul 2015, Ellen Wang wrote:

> When doing an I2C_SMBUS_BYTE write (one byte write, no address),
> the data to be written is in "command" not "data->byte".
> 
> Signed-off-by: Ellen Wang <ellen@cumulusnetworks.com>
> ---
> Forgot signed-off-by tag last time, sorry.

Applied to for-4.3/cp2112.

On Tue, 14 Jul 2015, Wolfram Sang wrote:

> Wow, that driver seems to be largely untested. Thanks for cleaning it
> up! Sidenote: i2c drivers should really be in drivers/i2c ;)

Well, it's sometimes a bit on the borderline where HID drivers should live 
(because they often, in addition to HID layer, make use of some other 
transport). If you want to move it under your wings, please send a patch 
that moves it and I'll Ack it.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] HID: cp2112: fix I2C_SMBUS_BYTE write
       [not found]       ` <alpine.LNX.2.00.1507141452140.7522-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
@ 2015-07-14 13:36         ` Antonio Borneo
       [not found]           ` <CAAj6DX2_ZwFqpKD5JjbWuJw7SJv3G+DhpnD6tZAoDcF32GQ=0Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Antonio Borneo @ 2015-07-14 13:36 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Ellen Wang, Wolfram Sang, David Barksdale, linux-input,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

On Tue, Jul 14, 2015 at 8:54 PM, Jiri Kosina <jkosina-IBi9RG/b67k@public.gmane.org> wrote:
> On Mon, 13 Jul 2015, Ellen Wang wrote:
>
>> When doing an I2C_SMBUS_BYTE write (one byte write, no address),
>> the data to be written is in "command" not "data->byte".
>>
>> Signed-off-by: Ellen Wang <ellen-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
>> ---
>> Forgot signed-off-by tag last time, sorry.
>
> Applied to for-4.3/cp2112.
>
> On Tue, 14 Jul 2015, Wolfram Sang wrote:
>
>> Wow, that driver seems to be largely untested. Thanks for cleaning it
>> up! Sidenote: i2c drivers should really be in drivers/i2c ;)
>
> Well, it's sometimes a bit on the borderline where HID drivers should live
> (because they often, in addition to HID layer, make use of some other
> transport). If you want to move it under your wings, please send a patch
> that moves it and I'll Ack it.


This is a MFD; should be split in GPIO and I2C, then each part moved
in its respective tree.

Anyone already working in this direction?

Regards,
Antonio

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] HID: cp2112: fix I2C_SMBUS_BYTE write
       [not found]           ` <CAAj6DX2_ZwFqpKD5JjbWuJw7SJv3G+DhpnD6tZAoDcF32GQ=0Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2015-07-14 15:49             ` Wolfram Sang
  2015-07-14 22:51               ` Ellen Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2015-07-14 15:49 UTC (permalink / raw)
  To: Antonio Borneo
  Cc: Jiri Kosina, Ellen Wang, David Barksdale, linux-input,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 431 bytes --]


> This is a MFD; should be split in GPIO and I2C, then each part moved
> in its respective tree.

Yes, this is the conclusion we drew last time, too. It might seem
overkill for such simple devices, still this case shows how much drivers
can suffer if missing the expertise of the apropriate subsystem. That
being said, world is full of cornercases, I agree.

> Anyone already working in this direction?

I'd be very surprised :)


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] HID: cp2112: fix I2C_SMBUS_BYTE write
  2015-07-14 15:49             ` Wolfram Sang
@ 2015-07-14 22:51               ` Ellen Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Ellen Wang @ 2015-07-14 22:51 UTC (permalink / raw)
  To: Wolfram Sang, Antonio Borneo
  Cc: Jiri Kosina, David Barksdale, linux-input, linux-i2c

On 07/14/2015 08:49 AM, Wolfram Sang wrote:
>
>> This is a MFD; should be split in GPIO and I2C, then each part moved
>> in its respective tree.
>
> Yes, this is the conclusion we drew last time, too. It might seem
> overkill for such simple devices, still this case shows how much drivers
> can suffer if missing the expertise of the apropriate subsystem. That
> being said, world is full of cornercases, I agree.

This driver is a good example of that (missing expertise).  It seems to 
be a fine HID driver but a lot of the I2C details were just wrong.  At 
the same time, I have no idea whether the GPIO part works at all.

>> Anyone already working in this direction?
>
> I'd be very surprised :)

I could and would but I'm really not in a good position to do it.  My 
only sample hardware is in a network switch.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] HID: cp2112: fix I2C_SMBUS_BYTE write
  2015-07-14 12:54     ` Jiri Kosina
       [not found]       ` <alpine.LNX.2.00.1507141452140.7522-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
@ 2015-07-14 22:54       ` Ellen Wang
  1 sibling, 0 replies; 8+ messages in thread
From: Ellen Wang @ 2015-07-14 22:54 UTC (permalink / raw)
  To: Jiri Kosina, Wolfram Sang
  Cc: borneo.antonio, dbarksdale, linux-input, linux-i2c

On 07/14/2015 05:54 AM, Jiri Kosina wrote:
> On Mon, 13 Jul 2015, Ellen Wang wrote:
>
>> When doing an I2C_SMBUS_BYTE write (one byte write, no address),
>> the data to be written is in "command" not "data->byte".
>>
>> Signed-off-by: Ellen Wang <ellen@cumulusnetworks.com>
>> ---
>> Forgot signed-off-by tag last time, sorry.
>
> Applied to for-4.3/cp2112.

Would it be possible to consider it for stable, as well as the other 
recent commits (6debce6f4e787a8eb4cec94e7afa85fb4f40db27 and 
5ddfb12e90c73cf86881345be422e09c367f6981)?

Thanks!

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-07-14 22:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-13 22:23 [PATCH v2] HID: cp2112: fix I2C_SMBUS_BYTE write Ellen Wang
2015-07-14  8:46 ` Antonio Borneo
     [not found] ` <1436826234-2447-1-git-send-email-ellen-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
2015-07-14 11:49   ` Wolfram Sang
2015-07-14 12:54     ` Jiri Kosina
     [not found]       ` <alpine.LNX.2.00.1507141452140.7522-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
2015-07-14 13:36         ` Antonio Borneo
     [not found]           ` <CAAj6DX2_ZwFqpKD5JjbWuJw7SJv3G+DhpnD6tZAoDcF32GQ=0Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-14 15:49             ` Wolfram Sang
2015-07-14 22:51               ` Ellen Wang
2015-07-14 22:54       ` Ellen Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox