linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: (i2c-diolan-u2c) Fix master_xfer return code
@ 2012-08-09 15:47 Guenter Roeck
       [not found] ` <1344527240-18266-1-git-send-email-linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Guenter Roeck @ 2012-08-09 15:47 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
  Cc: Ben Dooks, Jean Delvare, Wolfram Sang, Guenter Roeck

The master_xfer function returns 0 on success. It should return the number of
successful transactions.

Signed-off-by: Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
---
 drivers/i2c/busses/i2c-diolan-u2c.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
index aedb94f..dae3ddf 100644
--- a/drivers/i2c/busses/i2c-diolan-u2c.c
+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
@@ -405,6 +405,7 @@ static int diolan_usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
 			}
 		}
 	}
+	ret = num;
 abort:
 	sret = diolan_i2c_stop(dev);
 	if (sret < 0 && ret >= 0)
-- 
1.7.9.7

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

* Re: [PATCH] i2c: (i2c-diolan-u2c) Fix master_xfer return code
       [not found] ` <1344527240-18266-1-git-send-email-linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
@ 2012-08-10  5:58   ` Shubhrajyoti Datta
       [not found]     ` <CAM=Q2ctnrO6hJkPDa_daDRFNyig3+GVDkgW_MGMjV24jEM8T5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2012-08-18 10:27   ` Wolfram Sang
  1 sibling, 1 reply; 6+ messages in thread
From: Shubhrajyoti Datta @ 2012-08-10  5:58 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks, Jean Delvare,
	Wolfram Sang

Hi Gunter,
A minor suggestion below.

On Thu, Aug 9, 2012 at 9:17 PM, Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> wrote:
> The master_xfer function returns 0 on success. It should return the number of
> successful transactions.
>
> Signed-off-by: Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
> ---
>  drivers/i2c/busses/i2c-diolan-u2c.c |    1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
> index aedb94f..dae3ddf 100644
> --- a/drivers/i2c/busses/i2c-diolan-u2c.c
> +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
> @@ -405,6 +405,7 @@ static int diolan_usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
>                         }
>                 }
>         }
> +       ret = num;
So if all the messages get transferred this is right.

However if only a few go through should we return the number of
successful transactions
instead of error?

>  abort:
>         sret = diolan_i2c_stop(dev);
>         if (sret < 0 && ret >= 0)
> --
> 1.7.9.7
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] i2c: (i2c-diolan-u2c) Fix master_xfer return code
       [not found]     ` <CAM=Q2ctnrO6hJkPDa_daDRFNyig3+GVDkgW_MGMjV24jEM8T5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2012-08-10 17:06       ` Guenter Roeck
       [not found]         ` <20120810170624.GC29281-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Guenter Roeck @ 2012-08-10 17:06 UTC (permalink / raw)
  To: Shubhrajyoti Datta
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks, Jean Delvare,
	Wolfram Sang

On Fri, Aug 10, 2012 at 11:28:26AM +0530, Shubhrajyoti Datta wrote:
> Hi Gunter,
> A minor suggestion below.
> 
> On Thu, Aug 9, 2012 at 9:17 PM, Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> wrote:
> > The master_xfer function returns 0 on success. It should return the number of
> > successful transactions.
> >
> > Signed-off-by: Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
> > ---
> >  drivers/i2c/busses/i2c-diolan-u2c.c |    1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
> > index aedb94f..dae3ddf 100644
> > --- a/drivers/i2c/busses/i2c-diolan-u2c.c
> > +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
> > @@ -405,6 +405,7 @@ static int diolan_usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
> >                         }
> >                 }
> >         }
> > +       ret = num;
> So if all the messages get transferred this is right.
> 
> However if only a few go through should we return the number of
> successful transactions
> instead of error?
> 
Most other I2C bus drivers do the same, so I decided to not make the code
more complicated than necessary and do it the same way. Also, I prefer to have
the actual error code returned to the caller, not "I transferred x of your y
messages, but I won't tell you what went wrong with the rest".

If that prevents it from getting integrated, I'll be happy to change it. 

Thanks,
Guenter

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

* Re: [PATCH] i2c: (i2c-diolan-u2c) Fix master_xfer return code
       [not found]         ` <20120810170624.GC29281-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
@ 2012-08-13  6:27           ` Shubhrajyoti Datta
       [not found]             ` <CAM=Q2ctzBg+o-3On8-i-T49Dg9H=_2Tv7Z9iZba6iErTQoLVXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Shubhrajyoti Datta @ 2012-08-13  6:27 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks, Jean Delvare,
	Wolfram Sang

On Fri, Aug 10, 2012 at 10:36 PM, Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> wrote:
[...]
>>
>> However if only a few go through should we return the number of
>> successful transactions
>> instead of error?
>>
> Most other I2C bus drivers do the same, so I decided to not make the code
> more complicated than necessary and do it the same way. Also, I prefer to have
> the actual error code returned to the caller, not "I transferred x of your y
> messages, but I won't tell you what went wrong with the rest".

depends on what the user decides however if ever his algo is that resend only
the remaining it would never work. Anyways thats a different story.

>
> If that prevents it from getting integrated, I'll be happy to change it.

I have no objections to the patch getting integrated.
Afterall anything that helps, helps:-)


>
> Thanks,
> Guenter

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

* Re: [PATCH] i2c: (i2c-diolan-u2c) Fix master_xfer return code
       [not found]             ` <CAM=Q2ctzBg+o-3On8-i-T49Dg9H=_2Tv7Z9iZba6iErTQoLVXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2012-08-13 16:05               ` Guenter Roeck
  0 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2012-08-13 16:05 UTC (permalink / raw)
  To: Shubhrajyoti Datta
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks, Jean Delvare,
	Wolfram Sang

On Mon, Aug 13, 2012 at 11:57:15AM +0530, Shubhrajyoti Datta wrote:
> On Fri, Aug 10, 2012 at 10:36 PM, Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> wrote:
> [...]
> >>
> >> However if only a few go through should we return the number of
> >> successful transactions
> >> instead of error?
> >>
> > Most other I2C bus drivers do the same, so I decided to not make the code
> > more complicated than necessary and do it the same way. Also, I prefer to have
> > the actual error code returned to the caller, not "I transferred x of your y
> > messages, but I won't tell you what went wrong with the rest".
> 
> depends on what the user decides however if ever his algo is that resend only
> the remaining it would never work. Anyways thats a different story.
> 
Worse, many callers don't check if the return code matches the number of
messages. So errors can get lost if the return code after an error is not
negative.

Guenter

> >
> > If that prevents it from getting integrated, I'll be happy to change it.
> 
> I have no objections to the patch getting integrated.
> Afterall anything that helps, helps:-)
> 
> 
> >
> > Thanks,
> > Guenter
> 

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

* Re: [PATCH] i2c: (i2c-diolan-u2c) Fix master_xfer return code
       [not found] ` <1344527240-18266-1-git-send-email-linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
  2012-08-10  5:58   ` Shubhrajyoti Datta
@ 2012-08-18 10:27   ` Wolfram Sang
  1 sibling, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2012-08-18 10:27 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks, Jean Delvare

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

On Thu, Aug 09, 2012 at 08:47:20AM -0700, Guenter Roeck wrote:
> The master_xfer function returns 0 on success. It should return the number of
> successful transactions.
> 
> Signed-off-by: Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>

Applied to -current, thanks! To add something to the discussion, an
excerpt for i2c-core.c:

1357 int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1358 {
1359         int ret;
1360 
1361         /* REVISIT the fault reporting model here is weak:
1362          *
1363          *  - When we get an error after receiving N bytes from a slave,
1364          *    there is no way to report "N".
1365          *
1366          *  - When we get a NAK after transmitting N bytes to a slave,
1367          *    there is no way to report "N" ... or to let the master
1368          *    continue executing the rest of this combined message, if
1369          *    that's the appropriate response.
1370          *
1371          *  - When for example "num" is two and we successfully complete
1372          *    the first message but get an error part way through the
1373          *    second, it's unclear whether that should be reported as
1374          *    one (discarding status on the second message) or errno
1375          *    (discarding status on the first one).
1376          */
1377 

-- 
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] 6+ messages in thread

end of thread, other threads:[~2012-08-18 10:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-09 15:47 [PATCH] i2c: (i2c-diolan-u2c) Fix master_xfer return code Guenter Roeck
     [not found] ` <1344527240-18266-1-git-send-email-linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2012-08-10  5:58   ` Shubhrajyoti Datta
     [not found]     ` <CAM=Q2ctnrO6hJkPDa_daDRFNyig3+GVDkgW_MGMjV24jEM8T5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-08-10 17:06       ` Guenter Roeck
     [not found]         ` <20120810170624.GC29281-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2012-08-13  6:27           ` Shubhrajyoti Datta
     [not found]             ` <CAM=Q2ctzBg+o-3On8-i-T49Dg9H=_2Tv7Z9iZba6iErTQoLVXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-08-13 16:05               ` Guenter Roeck
2012-08-18 10:27   ` Wolfram Sang

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).