linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: zhangfei gao <zhangfei.gao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>,
	khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org
Cc: eric.y.miao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	haojian.zhuang-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/1] fix i2c_msg.len not aligning with i2c_master_send
Date: Thu, 4 Feb 2010 16:25:40 +0800	[thread overview]
Message-ID: <309424b61002040025n22c2b05wbaab46ca4da946f2@mail.gmail.com> (raw)
In-Reply-To: <20100204073759.GC13267-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>

Hi, Ben

Thanks for your suggestion.

On Thu, Feb 4, 2010 at 3:37 PM, Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org> wrote:
>
> On Thu, Feb 04, 2010 at 02:04:03PM +0800, zhangfei gao wrote:
> > Hi, Jean
> >
> >
> > We found type of i2c_msg.len is __u16, while parameter count in
> > i2c_master_send is int.
> > The mismatch will truncate count from int to u16.
> > For example we downloading firmware which is more than 64K (64K+8) via i2c,
> > i2c would transfer u16 (8 bytes) in fact.
>
> I would be wary of changing the i2c_msg structure as this is exported to
> userspace.
>
>
> I think a better fix would be to test the count parameter to i2c_master_send
> and return something like EMSGSIZE to inform the user it is too long.
>
> If you really want i2c transfers of 64K and above, then you might have to
> add a new struct i2c_msg and update all the callsites to use it. Either that
> or chain a set of msgs together and pass them to the i2c controller in one
> go.
>
> Please discuss on the i2c list.
>

1. Both i2c_master_send and i2c_msg are exported in include/linux/i2c.h.
2. Both i2c_master_send and i2c_master_recv supposed to support int
count, is it suitable to return error when count is bigger than 64K?
3. It may impact a lot if adding new structure :)

include/linux/i2c.h
extern int i2c_master_send(struct i2c_client *client, const char *buf,
                           int count);
extern int i2c_master_recv(struct i2c_client *client, char *buf, int count);

Thansk
Zhangfei

> > >From 69ec7599bf0fa28441281be1df76a2f573bb9127 Mon Sep 17 00:00:00 2001
> > From: Zhangfei Gao <zgao6-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org>
> > Date: Fri, 5 Feb 2010 05:12:19 +0800
> > Subject: [PATCH] i2c: i2c_msg.len modify to __u32 type
> >
> >     int i2c_master_send(struct i2c_client *client,const char *buf ,int
> > count)
> >     {
> >         ~
> >         msg.len = count;
> >         ~
> >     }
> >     Parameter count would truncate from int to __u16
> >
> > Signed-off-by: Zhangfei Gao <zgao6-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org>
> > ---
> >  include/linux/i2c.h |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> > index 57d41b0..4769ce9 100644
> > --- a/include/linux/i2c.h
> > +++ b/include/linux/i2c.h
> > @@ -491,7 +491,7 @@ struct i2c_msg {
> >  #define I2C_M_IGNORE_NAK    0x1000    /* if I2C_FUNC_PROTOCOL_MANGLING */
> >  #define I2C_M_NO_RD_ACK        0x0800    /* if I2C_FUNC_PROTOCOL_MANGLING
> > */
> >  #define I2C_M_RECV_LEN        0x0400    /* length will be first received
> > byte */
> > -    __u16 len;        /* msg length                */
> > +    __u32 len;        /* msg length                */
> >      __u8 *buf;        /* pointer to msg data            */
> >  };
> >
> > --
> > 1.6.0.4
>
>
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
>
> --
> --
> Ben
>
> Q:      What's a light-year?
> A:      One-third less calories than a regular year.
>

       reply	other threads:[~2010-02-04  8:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <309424b61002032204y37307236q94ab3a502b0526e0@mail.gmail.com>
     [not found] ` <20100204073759.GC13267@trinity.fluff.org>
     [not found]   ` <20100204073759.GC13267-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2010-02-04  8:25     ` zhangfei gao [this message]
     [not found] ` <309424b61002032204y37307236q94ab3a502b0526e0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-04  9:35   ` [PATCH 1/1] fix i2c_msg.len not aligning with i2c_master_send Jean Delvare
2010-02-04 12:38     ` zhangfei gao
2010-02-04 12:47       ` Eric Miao
     [not found]         ` <f17812d71002040447y4b6f889o1137ae6149559994-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-04 13:14           ` Jean Delvare
     [not found]             ` <20100204141451.3e0f865e-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-02-05  5:51               ` zhangfei gao
     [not found]                 ` <309424b61002042151i2a762d41md3521a820fd45622-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-05 11:12                   ` Eric Miao
2010-02-21 11:20                 ` Jean Delvare

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=309424b61002040025n22c2b05wbaab46ca4da946f2@mail.gmail.com \
    --to=zhangfei.gao-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
    --cc=eric.y.miao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=haojian.zhuang-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org \
    --cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).