linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: at91: add a sanity check on i2c message length
@ 2012-10-10 14:25 ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w
  2012-10-24 14:34 ` ludovic.desroches
       [not found] ` <1349879158-27268-1-git-send-email-ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
  0 siblings, 2 replies; 8+ messages in thread
From: ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w @ 2012-10-10 14:25 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA
  Cc: nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w, Ludovic Desroches

From: Ludovic Desroches <ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>

If the i2c message length is zero, i2c-at91 will directly return an error
instead of trying to send a zero-length message.

Signed-off-by: Ludovic Desroches <ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
---

fix for 3.7

 drivers/i2c/busses/i2c-at91.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index aa59a25..eaddc77 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -263,6 +263,9 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
 	unsigned int_addr_flag = 0;
 	struct i2c_msg *m_start = msg;
 
+	if (!msg->len)
+		return -EINVAL;
+
 	dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num);
 
 	/*
-- 
1.7.11.3

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

* Re: [PATCH] i2c: at91: add a sanity check on i2c message length
  2012-10-10 14:25 [PATCH] i2c: at91: add a sanity check on i2c message length ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w
@ 2012-10-24 14:34 ` ludovic.desroches
       [not found] ` <1349879158-27268-1-git-send-email-ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
  1 sibling, 0 replies; 8+ messages in thread
From: ludovic.desroches @ 2012-10-24 14:34 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: ludovic.desroches, nicolas.ferre, linux-i2c, linux-arm-kernel

Hi Wolfram,

Le 10/10/2012 04:25 PM, ludovic.desroches@atmel.com a écrit :
> From: Ludovic Desroches <ludovic.desroches@atmel.com>
>
> If the i2c message length is zero, i2c-at91 will directly return an error
> instead of trying to send a zero-length message.
>
> Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
> ---
>
> fix for 3.7
>
>   drivers/i2c/busses/i2c-at91.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
> index aa59a25..eaddc77 100644
> --- a/drivers/i2c/busses/i2c-at91.c
> +++ b/drivers/i2c/busses/i2c-at91.c
> @@ -263,6 +263,9 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
>   	unsigned int_addr_flag = 0;
>   	struct i2c_msg *m_start = msg;
>
> +	if (!msg->len)
> +		return -EINVAL;
> +
>   	dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num);
>
>   	/*
>

Could you take this fix for 3.7?

Thanks

Regards

Ludovic

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

* Re: [PATCH] i2c: at91: add a sanity check on i2c message length
       [not found] ` <1349879158-27268-1-git-send-email-ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
@ 2012-11-01 22:29   ` Wolfram Sang
  2012-11-02 11:04     ` ludovic.desroches
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2012-11-01 22:29 UTC (permalink / raw)
  To: ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w

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

On Wed, Oct 10, 2012 at 04:25:58PM +0200, ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org wrote:
> From: Ludovic Desroches <ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> 
> If the i2c message length is zero, i2c-at91 will directly return an error
> instead of trying to send a zero-length message.
> 
> Signed-off-by: Ludovic Desroches <ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>

What happens if you send a 0 byte message? Some hardware is able to do
this and it will be used in SMBUS QUICK which the driver states to
support according to at91_twi_func().

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

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

* Re: [PATCH] i2c: at91: add a sanity check on i2c message length
  2012-11-01 22:29   ` Wolfram Sang
@ 2012-11-02 11:04     ` ludovic.desroches
       [not found]       ` <5093A8CD.60006-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: ludovic.desroches @ 2012-11-02 11:04 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: ludovic.desroches, nicolas.ferre, linux-i2c, linux-arm-kernel

Hi Wolfram,

Le 11/01/2012 11:29 PM, Wolfram Sang a écrit :
> On Wed, Oct 10, 2012 at 04:25:58PM +0200, ludovic.desroches@atmel.com wrote:
>> From: Ludovic Desroches <ludovic.desroches@atmel.com>
>>
>> If the i2c message length is zero, i2c-at91 will directly return an error
>> instead of trying to send a zero-length message.
>>
>> Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
>
> What happens if you send a 0 byte message? Some hardware is able to do
> this and it will be used in SMBUS QUICK which the driver states to
> support according to at91_twi_func().

Without this I had some data corruption when writing to / reading from a 
serial eeprom (depending on the IP version).

Yes SMBUS quick command is supported but is not managed in the driver, 
we have to tell explicitly the IP that we want to send this command.


Regards

Ludovic

>
> Regards,
>
>     Wolfram
>

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

* Re: [PATCH] i2c: at91: add a sanity check on i2c message length
       [not found]       ` <5093A8CD.60006-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
@ 2012-11-02 11:14         ` Wolfram Sang
  2012-11-02 16:00           ` ludovic.desroches
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2012-11-02 11:14 UTC (permalink / raw)
  To: ludovic.desroches
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w

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

On Fri, Nov 02, 2012 at 12:04:45PM +0100, ludovic.desroches wrote:
> Hi Wolfram,
> 
> Le 11/01/2012 11:29 PM, Wolfram Sang a écrit :
> >On Wed, Oct 10, 2012 at 04:25:58PM +0200, ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org wrote:
> >>From: Ludovic Desroches <ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> >>
> >>If the i2c message length is zero, i2c-at91 will directly return an error
> >>instead of trying to send a zero-length message.
> >>
> >>Signed-off-by: Ludovic Desroches <ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> >
> >What happens if you send a 0 byte message? Some hardware is able to do
> >this and it will be used in SMBUS QUICK which the driver states to
> >support according to at91_twi_func().
> 
> Without this I had some data corruption when writing to / reading
> from a serial eeprom (depending on the IP version).
> 
> Yes SMBUS quick command is supported but is not managed in the
> driver, we have to tell explicitly the IP that we want to send this
> command.

Ok, so unless you want to implement the support, please update this
patch with a comment that SMBUS_QUICK is a TODO and remove the
SMBUS_QUICK capability.

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

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

* Re: [PATCH] i2c: at91: add a sanity check on i2c message length
  2012-11-02 11:14         ` Wolfram Sang
@ 2012-11-02 16:00           ` ludovic.desroches
       [not found]             ` <5093EE2B.8080005-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: ludovic.desroches @ 2012-11-02 16:00 UTC (permalink / raw)
  To: Wolfram Sang, Voss, Nikolaus
  Cc: ludovic.desroches, nicolas.ferre, linux-i2c, linux-arm-kernel

Le 11/02/2012 12:14 PM, Wolfram Sang a écrit :
> On Fri, Nov 02, 2012 at 12:04:45PM +0100, ludovic.desroches wrote:
>> Hi Wolfram,
>>
>> Le 11/01/2012 11:29 PM, Wolfram Sang a écrit :
>>> On Wed, Oct 10, 2012 at 04:25:58PM +0200, ludovic.desroches@atmel.com wrote:
>>>> From: Ludovic Desroches <ludovic.desroches@atmel.com>
>>>>
>>>> If the i2c message length is zero, i2c-at91 will directly return an error
>>>> instead of trying to send a zero-length message.
>>>>
>>>> Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
>>>
>>> What happens if you send a 0 byte message? Some hardware is able to do
>>> this and it will be used in SMBUS QUICK which the driver states to
>>> support according to at91_twi_func().
>>
>> Without this I had some data corruption when writing to / reading
>> from a serial eeprom (depending on the IP version).
>>
>> Yes SMBUS quick command is supported but is not managed in the
>> driver, we have to tell explicitly the IP that we want to send this
>> command.
>
> Ok, so unless you want to implement the support, please update this
> patch with a comment that SMBUS_QUICK is a TODO and remove the
> SMBUS_QUICK capability.
>

Implementation should not be a huge task, only one bit to set in a 
register but I have no device to test it.
So I will choose to remove the SMBUS_QUICK capability.

Hi Nikolaus,

Did you test the driver with SMBus compatible devices? Can I keep other 
SMBus capabilities from SMBUS_EMUL?

Thanks

Regards

Ludovic

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

* Re: [PATCH] i2c: at91: add a sanity check on i2c message length
       [not found]             ` <5093EE2B.8080005-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
@ 2012-11-03 14:16               ` Wolfram Sang
  2012-11-05  6:08               ` Voss, Nikolaus
  1 sibling, 0 replies; 8+ messages in thread
From: Wolfram Sang @ 2012-11-03 14:16 UTC (permalink / raw)
  To: ludovic.desroches
  Cc: Voss, Nikolaus, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w

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


> >>Yes SMBUS quick command is supported but is not managed in the
> >>driver, we have to tell explicitly the IP that we want to send this
> >>command.
> >
> >Ok, so unless you want to implement the support, please update this
> >patch with a comment that SMBUS_QUICK is a TODO and remove the
> >SMBUS_QUICK capability.
> >
> 
> Implementation should not be a huge task, only one bit to set in a
> register but I have no device to test it.

'i2cdetect' from i2c-tools uses SMBUS_QUICK as one method to detect
chips. Most slaves (both I2C and SMBus) react to that, so that would do
in my book.

> Did you test the driver with SMBus compatible devices? Can I keep
> other SMBus capabilities from SMBUS_EMUL?

The rest should be fine.

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

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

* RE: [PATCH] i2c: at91: add a sanity check on i2c message length
       [not found]             ` <5093EE2B.8080005-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
  2012-11-03 14:16               ` Wolfram Sang
@ 2012-11-05  6:08               ` Voss, Nikolaus
  1 sibling, 0 replies; 8+ messages in thread
From: Voss, Nikolaus @ 2012-11-05  6:08 UTC (permalink / raw)
  To: 'ludovic.desroches', 'Wolfram Sang'
  Cc: 'linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org',
	'linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org',
	'nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org'

ludovic.desroches wrote on Friday, November 02, 2012 5:01 PM:
> Le 11/02/2012 12:14 PM, Wolfram Sang a écrit :
> > On Fri, Nov 02, 2012 at 12:04:45PM +0100, ludovic.desroches wrote:
> >> Hi Wolfram,
> >>
> >> Le 11/01/2012 11:29 PM, Wolfram Sang a écrit :
> >>> On Wed, Oct 10, 2012 at 04:25:58PM +0200,
> ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org wrote:
> >>>> From: Ludovic Desroches <ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> >>>>
> >>>> If the i2c message length is zero, i2c-at91 will directly return an error
> >>>> instead of trying to send a zero-length message.
> >>>>
> >>>> Signed-off-by: Ludovic Desroches <ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> >>>
> >>> What happens if you send a 0 byte message? Some hardware is able to
> do
> >>> this and it will be used in SMBUS QUICK which the driver states to
> >>> support according to at91_twi_func().
> >>
> >> Without this I had some data corruption when writing to / reading
> >> from a serial eeprom (depending on the IP version).
> >>
> >> Yes SMBUS quick command is supported but is not managed in the
> >> driver, we have to tell explicitly the IP that we want to send this
> >> command.
> >
> > Ok, so unless you want to implement the support, please update this
> > patch with a comment that SMBUS_QUICK is a TODO and remove the
> > SMBUS_QUICK capability.
> >
> 
> Implementation should not be a huge task, only one bit to set in a
> register but I have no device to test it.
> So I will choose to remove the SMBUS_QUICK capability.
> 
> Hi Nikolaus,
> 
> Did you test the driver with SMBus compatible devices? Can I keep other
> SMBus capabilities from SMBUS_EMUL?

Hi Ludovic,

yes, I use this driver with the sbs driver to query a smbus-attached
battery with a TI bq chip (I actually wrote this driver only for this
purpose). I implemented and tested SMBUS_BLOCK but not
SMBUS_QUICK...

Niko

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

end of thread, other threads:[~2012-11-05  6:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-10 14:25 [PATCH] i2c: at91: add a sanity check on i2c message length ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w
2012-10-24 14:34 ` ludovic.desroches
     [not found] ` <1349879158-27268-1-git-send-email-ludovic.desroches-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
2012-11-01 22:29   ` Wolfram Sang
2012-11-02 11:04     ` ludovic.desroches
     [not found]       ` <5093A8CD.60006-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
2012-11-02 11:14         ` Wolfram Sang
2012-11-02 16:00           ` ludovic.desroches
     [not found]             ` <5093EE2B.8080005-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
2012-11-03 14:16               ` Wolfram Sang
2012-11-05  6:08               ` Voss, Nikolaus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).