* [PATCH] i2c: convert struct i2c_msg initialization to C99 format @ 2012-08-03 11:55 Shubhrajyoti D [not found] ` <1343994924-2341-1-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Shubhrajyoti D @ 2012-08-03 11:55 UTC (permalink / raw) To: linux-i2c-u79uwXL29TY76Z2rM5mHXA; +Cc: Shubhrajyoti D Convert the struct i2c_msg initialization to C99 format. This makes maintaining and editing the code simpler. Also helps once other fields like transferred are added in future. Signed-off-by: Shubhrajyoti D <shubhrajyoti-l0cyMroinI0@public.gmane.org> --- drivers/i2c/i2c-core.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 2efa56c..33cfdd3 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1971,12 +1971,19 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; int num = read_write == I2C_SMBUS_READ ? 2 : 1; - struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, - { addr, flags | I2C_M_RD, 0, msgbuf1 } - }; int i; u8 partial_pec = 0; int status; + struct i2c_msg msg[2]; + + msg[0].addr = addr; + msg[0].flags = flags; + msg[0].len = 1; + msg[0].buf = msgbuf0; + msg[1].addr = addr; + msg[1].flags = flags | I2C_M_RD; + msg[1].len = 0; + msg[1].buf = msgbuf1; msgbuf0[0] = command; switch (size) { -- 1.7.5.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
[parent not found: <1343994924-2341-1-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org>]
* Re: [PATCH] i2c: convert struct i2c_msg initialization to C99 format [not found] ` <1343994924-2341-1-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org> @ 2012-08-03 13:14 ` Jean Delvare [not found] ` <20120803151412.0cb16ed6-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Jean Delvare @ 2012-08-03 13:14 UTC (permalink / raw) To: Shubhrajyoti D; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA Hi Shubhrajyoti, On Fri, 3 Aug 2012 17:25:24 +0530, Shubhrajyoti D wrote: > Convert the struct i2c_msg initialization to C99 format. This makes > maintaining and editing the code simpler. Also helps once other fields > like transferred are added in future. > > Signed-off-by: Shubhrajyoti D <shubhrajyoti-l0cyMroinI0@public.gmane.org> > --- > drivers/i2c/i2c-core.c | 13 ++++++++++--- > 1 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c > index 2efa56c..33cfdd3 100644 > --- a/drivers/i2c/i2c-core.c > +++ b/drivers/i2c/i2c-core.c > @@ -1971,12 +1971,19 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, > unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; > unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; > int num = read_write == I2C_SMBUS_READ ? 2 : 1; > - struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, > - { addr, flags | I2C_M_RD, 0, msgbuf1 } > - }; > int i; > u8 partial_pec = 0; > int status; > + struct i2c_msg msg[2]; > + > + msg[0].addr = addr; > + msg[0].flags = flags; > + msg[0].len = 1; > + msg[0].buf = msgbuf0; > + msg[1].addr = addr; > + msg[1].flags = flags | I2C_M_RD; > + msg[1].len = 0; > + msg[1].buf = msgbuf1; > > msgbuf0[0] = command; > switch (size) { Good idea but I see no good reason to switch from struct-wide initialization to per-field initialization. AFAIK per-field initialization is less efficient and might leave some fields uninitialized, while I seem to remember struct-wide initialization sets them to 0. Can you please resubmit with struct-wide initialization preserved? Thanks, -- Jean Delvare ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <20120803151412.0cb16ed6-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>]
* Re: [PATCH] i2c: convert struct i2c_msg initialization to C99 format [not found] ` <20120803151412.0cb16ed6-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org> @ 2012-08-03 13:39 ` Datta, Shubhrajyoti [not found] ` <CANQgH-bmTdZ1z=Vbeg07mZ-FLRBrzhuf+Wz1Uv2GcU2dWW9TGA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Datta, Shubhrajyoti @ 2012-08-03 13:39 UTC (permalink / raw) To: Jean Delvare; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA On Fri, Aug 3, 2012 at 6:44 PM, Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> wrote: > Hi Shubhrajyoti, > > On Fri, 3 Aug 2012 17:25:24 +0530, Shubhrajyoti D wrote: >> Convert the struct i2c_msg initialization to C99 format. This makes >> maintaining and editing the code simpler. Also helps once other fields >> like transferred are added in future. >> >> Signed-off-by: Shubhrajyoti D <shubhrajyoti-l0cyMroinI0@public.gmane.org> >> --- >> drivers/i2c/i2c-core.c | 13 ++++++++++--- >> 1 files changed, 10 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c >> index 2efa56c..33cfdd3 100644 >> --- a/drivers/i2c/i2c-core.c >> +++ b/drivers/i2c/i2c-core.c >> @@ -1971,12 +1971,19 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, >> unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; >> unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; >> int num = read_write == I2C_SMBUS_READ ? 2 : 1; >> - struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, >> - { addr, flags | I2C_M_RD, 0, msgbuf1 } >> - }; >> int i; >> u8 partial_pec = 0; >> int status; >> + struct i2c_msg msg[2]; >> + >> + msg[0].addr = addr; >> + msg[0].flags = flags; >> + msg[0].len = 1; >> + msg[0].buf = msgbuf0; >> + msg[1].addr = addr; >> + msg[1].flags = flags | I2C_M_RD; >> + msg[1].len = 0; >> + msg[1].buf = msgbuf1; >> >> msgbuf0[0] = command; >> switch (size) { > > Good idea but I see no good reason to switch from struct-wide > initialization to per-field initialization. AFAIK per-field > initialization is less efficient and might leave some fields > uninitialized, while I seem to remember struct-wide initialization sets > them to 0. in case of locals also? > > Can you please resubmit with struct-wide initialization preserved? > yes thats doable too. thanks, > Thanks, > -- > Jean Delvare ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <CANQgH-bmTdZ1z=Vbeg07mZ-FLRBrzhuf+Wz1Uv2GcU2dWW9TGA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH] i2c: convert struct i2c_msg initialization to C99 format [not found] ` <CANQgH-bmTdZ1z=Vbeg07mZ-FLRBrzhuf+Wz1Uv2GcU2dWW9TGA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2012-08-03 14:14 ` Jean Delvare 0 siblings, 0 replies; 6+ messages in thread From: Jean Delvare @ 2012-08-03 14:14 UTC (permalink / raw) To: Datta, Shubhrajyoti; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA On Fri, 3 Aug 2012 19:09:33 +0530, Datta, Shubhrajyoti wrote: > On Fri, Aug 3, 2012 at 6:44 PM, Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> wrote: > > Good idea but I see no good reason to switch from struct-wide > > initialization to per-field initialization. AFAIK per-field > > initialization is less efficient and might leave some fields > > uninitialized, while I seem to remember struct-wide initialization sets > > them to 0. > in case of locals also? I _think_ so... But I admit I would be unable to quote the C99 standard on that. If someone knows for sure, please speak up. -- Jean Delvare ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] i2c: convert struct i2c_msg initialization to C99 format @ 2012-08-03 11:52 Shubhrajyoti D [not found] ` <1343994764-2286-1-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Shubhrajyoti D @ 2012-08-03 11:52 UTC (permalink / raw) To: linux-i2c-u79uwXL29TY76Z2rM5mHXA; +Cc: Shubhrajyoti D Convert the struct i2c_msg initialization to C99 format and remove all the NULL or 0 initializers. This makes maintaining and editing the code simpler. This may help once other fields like transferred are added in future. Signed-off-by: Shubhrajyoti D <shubhrajyoti-l0cyMroinI0@public.gmane.org> --- drivers/i2c/i2c-core.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 2efa56c..33cfdd3 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1971,12 +1971,19 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; int num = read_write == I2C_SMBUS_READ ? 2 : 1; - struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, - { addr, flags | I2C_M_RD, 0, msgbuf1 } - }; int i; u8 partial_pec = 0; int status; + struct i2c_msg msg[2]; + + msg[0].addr = addr; + msg[0].flags = flags; + msg[0].len = 1; + msg[0].buf = msgbuf0; + msg[1].addr = addr; + msg[1].flags = flags | I2C_M_RD; + msg[1].len = 0; + msg[1].buf = msgbuf1; msgbuf0[0] = command; switch (size) { -- 1.7.5.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
[parent not found: <1343994764-2286-1-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org>]
* Re: [PATCH] i2c: convert struct i2c_msg initialization to C99 format [not found] ` <1343994764-2286-1-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org> @ 2012-08-03 11:54 ` Datta, Shubhrajyoti 0 siblings, 0 replies; 6+ messages in thread From: Datta, Shubhrajyoti @ 2012-08-03 11:54 UTC (permalink / raw) To: linux-i2c-u79uwXL29TY76Z2rM5mHXA; +Cc: Shubhrajyoti D On Fri, Aug 3, 2012 at 5:22 PM, Shubhrajyoti D <shubhrajyoti-l0cyMroinI0@public.gmane.org> wrote: > Convert the struct i2c_msg initialization to C99 format and remove > all the NULL or 0 initializers. This makes maintaining and editing the > code simpler. This may help once other fields like transferred are added > in future. Please ignore > > Signed-off-by: Shubhrajyoti D <shubhrajyoti-l0cyMroinI0@public.gmane.org> > --- > drivers/i2c/i2c-core.c | 13 ++++++++++--- > 1 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c > index 2efa56c..33cfdd3 100644 > --- a/drivers/i2c/i2c-core.c > +++ b/drivers/i2c/i2c-core.c > @@ -1971,12 +1971,19 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, > unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; > unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; > int num = read_write == I2C_SMBUS_READ ? 2 : 1; > - struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, > - { addr, flags | I2C_M_RD, 0, msgbuf1 } > - }; > int i; > u8 partial_pec = 0; > int status; > + struct i2c_msg msg[2]; > + > + msg[0].addr = addr; > + msg[0].flags = flags; > + msg[0].len = 1; > + msg[0].buf = msgbuf0; > + msg[1].addr = addr; > + msg[1].flags = flags | I2C_M_RD; > + msg[1].len = 0; > + msg[1].buf = msgbuf1; > > msgbuf0[0] = command; > switch (size) { > -- > 1.7.5.4 > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-08-03 14:14 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-08-03 11:55 [PATCH] i2c: convert struct i2c_msg initialization to C99 format Shubhrajyoti D [not found] ` <1343994924-2341-1-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org> 2012-08-03 13:14 ` Jean Delvare [not found] ` <20120803151412.0cb16ed6-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org> 2012-08-03 13:39 ` Datta, Shubhrajyoti [not found] ` <CANQgH-bmTdZ1z=Vbeg07mZ-FLRBrzhuf+Wz1Uv2GcU2dWW9TGA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2012-08-03 14:14 ` Jean Delvare -- strict thread matches above, loose matches on Subject: below -- 2012-08-03 11:52 Shubhrajyoti D [not found] ` <1343994764-2286-1-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org> 2012-08-03 11:54 ` Datta, Shubhrajyoti
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).