staging iio: Replace kmalloc with local variable
Subsystems (4)
PATCH 1/1 staging iio: Replace kmalloc with local variable
From: anish kumar <[email protected]>
replaced kmalloc with local variable as I2C(in this case) doesn't require kmalloc memory it can do with stack memory.
--- drivers/staging/iio/adc/max1363_core.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
drivers/staging/iio/adc/max1363_core.c +1 -4
@@ -207,15 +207,12 @@ static int max1363_write_basic_config(struct i2c_client *client, unsigned char d2) {int ret; -u8 *tx_buf =kmalloc (2 ,GFP_KERNEL ); +u8 tx_buf[2 ]; -if (!tx_buf) -return -ENOMEM ; tx_buf[0 ] = d1; tx_buf[1 ] = d2; ret =i2c_master_send (client, tx_buf,2 ); -kfree (tx_buf);return (ret >0 ) ?0 : ret; }
Signature · 1 line
1.7.0.4
Quoted 4 lines · anish
From: anish kumar <[email protected]>
replaced kmalloc with local variable as I2C(in this case) doesn't require kmalloc memory it can do with stack memory.
I've cc'd linux-i2c just to check I'm right about the whole i2c doesn't need dma safe buffers bit...
Quoted 2 lines
Signed-off-by anish kumar <[email protected]>
Quoted 25 lines
--- drivers/staging/iio/adc/max1363_core.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)drivers/staging/iio/adc/max1363_core.c +1
-4@@ -207,15 +207,12 @@ static int max1363_write_basic_config(struct i2c_client *client, unsigned char d2) {int ret; -u8 *tx_buf =kmalloc (2 ,GFP_KERNEL ); +u8 tx_buf[2 ]; -if (!tx_buf) -return -ENOMEM ; tx_buf[0 ] = d1; tx_buf[1 ] = d2; ret =i2c_master_send (client, tx_buf,2 ); -kfree (tx_buf);return (ret >0 ) ?0 : ret; }
Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · anish
From: anish kumar <[email protected]>
replaced kmalloc with local variable as I2C(in this case) doesn't require kmalloc memory it can do with stack memory.
I've cc'd linux-i2c just to check I'm right about the whole i2c doesn't need dma safe buffers bit...
No, it is down to the i2c driver, and from recollection dma from stack is not recommended, due to things like cache line alignment. Please do not do this.
Quoted 32 lines
Quoted 1 line
Signed-off-by anish kumar <[email protected]>Quoted 15 lines
--- drivers/staging/iio/adc/max1363_core.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)drivers/staging/iio/adc/max1363_core.c +1
-1@@ -207,15 +207,12 @@ static int max1363_write_basic_config(struct i2c_client *client, unsigned char d2) {int ret; -u8 *tx_buf =kmalloc (2 ,GFP_KERNEL ); +u8 tx_buf[2 ];drivers/staging/iio/adc/max1363_core.c static int max1363_write_basic_config(struct i2c_client *client, · line 218
Quoted 10 lines
drivers/staging/iio/adc/max1363_core.c +0
-3-if (!tx_buf) -return -ENOMEM ; tx_buf[0 ] = d1; tx_buf[1 ] = d2; ret =i2c_master_send (client, tx_buf,2 ); -kfree (tx_buf);return (ret >0 ) ?0 : ret; }--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Ben Dooks, [email protected], http://www.fluff.org/ben/ Large Hadron Colada: A large Pina Colada that makes the universe disappear.
Quoted 4 lines · Ben Dooks
Quoted 3 lines · Jonathan Cameron
Quoted 2 lines · anish
From: anish kumar <[email protected]>
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
replaced kmalloc with local variable as I2C(in this case) doesn't require kmalloc memory it can do with stack memory.
I've cc'd linux-i2c just to check I'm right about the whole i2c doesn't need dma safe buffers bit...
No, it is down to the i2c driver, and from recollection dma from stack is not recommended, due to things like cache line alignment. Please do not do this.
Then lets drop this. Sorry Anish, seems I led you down the garden path. I'll check all my i2c drivers don't do this...
Quoted 34 lines
Quoted 33 lines
Quoted 2 lines
Signed-off-by anish kumar <[email protected]>Acked-by Jonathan Cameron <[email protected]>Quoted 15 lines
--- drivers/staging/iio/adc/max1363_core.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)drivers/staging/iio/adc/max1363_core.c +1
-1@@ -207,15 +207,12 @@ static int max1363_write_basic_config(struct i2c_client *client, unsigned char d2) {int ret; -u8 *tx_buf =kmalloc (2 ,GFP_KERNEL ); +u8 tx_buf[2 ];drivers/staging/iio/adc/max1363_core.c static int max1363_write_basic_config(struct i2c_client *client, · line 218
Quoted 10 lines
drivers/staging/iio/adc/max1363_core.c +0
-3-if (!tx_buf) -return -ENOMEM ; tx_buf[0 ] = d1; tx_buf[1 ] = d2; ret =i2c_master_send (client, tx_buf,2 ); -kfree (tx_buf);return (ret >0 ) ?0 : ret; }--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Ben Dooks
Quoted 3 lines · Jonathan Cameron
Quoted 2 lines · anish
From: anish kumar <[email protected]>
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
replaced kmalloc with local variable as I2C(in this case) doesn't require kmalloc memory it can do with stack memory.
I've cc'd linux-i2c just to check I'm right about the whole i2c doesn't need dma safe buffers bit...
No, it is down to the i2c driver, and from recollection dma from stack is not recommended, due to things like cache line alignment. Please do not do this.
To be clearer, it is down to the i2c BUS (adapter) driver, NOT the i2c device driver. So the patch is correct.
Keep in mind that not all I2C/SMBus controllers care about DMA. In fact, most don't (at least in the set I am maintaining - might be different an embedded.) So calling kmalloc for every transfer in every I2C device driver "just in case" is very much counterproductive.
And, if a controller does DMA and needs well-aligned, dynamically allocated buffer, its driver would hopefully allocate the buffer ONCE and keep it around, rather than reallocating it for every transfer.
Signature · 1 line
Jean Delvare
Jonathan Cameron wrote on 2011-06-07:
Quoted 7 lines · Ben Dooks
Quoted 6 lines · Jonathan Cameron
Quoted 5 lines · anish
Quoted 4 lines
From: anish kumar <[email protected]>
replaced kmalloc with local variable as I2C(in this case) doesn't require kmalloc memory it can do with stack memory.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I've cc'd linux-i2c just to check I'm right about the whole i2c doesn't need dma safe buffers bit...
No, it is down to the i2c driver, and from recollection dma from stack is not recommended, due to things like cache line alignment. Please do not do this.
Then lets drop this. Sorry Anish, seems I led you down the garden path. I'll check all my i2c drivers don't do this...
Can you point to a i2c bus driver that does dma and uses the buffer from the client directly?
Quoted 35 lines
Quoted 11 lines
Quoted 11 lines
drivers/staging/iio/adc/max1363_core.c static int max1363_write_basic_config(struct
Quoted 11 lines
Signed-off-by anish kumar <[email protected]> Acked-by:Jonathan Cameron <jic23-KWPb1pKIrIJaa/[email protected]> ---
drivers/staging/iio/adc/max1363_core.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)drivers/staging/iio/adc/max1363_core.c +0
-0@@ -207,15 +207,12 @@ static int max1363_write_basic_config(struct
i2c_client*client,Quoted 22 lines
Quoted 21 lines
Quoted 6 lines
drivers/staging/iio/adc/max1363_core.c +1
-1unsigned char d2) {int ret; -u8 *tx_buf =kmalloc (2 ,GFP_KERNEL ); +u8 tx_buf[2 ];drivers/staging/iio/adc/max1363_core.c static int max1363_write_basic_config(struct i2c_client *client, · line 218
Quoted 10 lines
drivers/staging/iio/adc/max1363_core.c +0
-3-if (!tx_buf) -return -ENOMEM ; tx_buf[0 ] = d1; tx_buf[1 ] = d2; ret =i2c_master_send (client, tx_buf,2 ); -kfree (tx_buf);return (ret >0 ) ?0 : ret; }--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Greetings,
Michael
--
Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368; Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif
Quoted 10 lines · Jean Delvare
Quoted 5 lines · Ben Dooks
Quoted 4 lines · Jonathan Cameron
Quoted 3 lines · anish
From: anish kumar <[email protected]>
replaced kmalloc with local variable as I2C(in this case) doesn't
require
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
kmalloc memory it can do with stack memory.
I've cc'd linux-i2c just to check I'm right about the whole i2c doesn't
need
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
dma safe buffers bit...
No, it is down to the i2c driver, and from recollection dma from stack is not recommended, due to things like cache line alignment. Please do not do this.
To be clearer, it is down to the i2c BUS (adapter) driver, NOT the i2c device driver. So the patch is correct.
I think i can take Jean ack on this?If yes then Joanthan kindly apply this patch and i think you didn't lead me in wrong way as whatever said by you is corroborated by jean also i.e. it is I2C bus driver responsiblity
to care about DMA.
Quoted 13 lines
Keep in mind that not all I2C/SMBus controllers care about DMA. In fact, most don't (at least in the set I am maintaining - might be different an embedded.) So calling kmalloc for every transfer in every I2C device driver "just in case" is very much counterproductive.
And, if a controller does DMA and needs well-aligned, dynamically allocated buffer, its driver would hopefully allocate the buffer ONCE and keep it around, rather than reallocating it for every transfer.
--
Jean Delvare
Quoted 21 lines · anish singh
Quoted 17 lines · Jean Delvare
Quoted 5 lines · Ben Dooks
Quoted 4 lines · Jonathan Cameron
Quoted 3 lines · anish
From: anish kumar <[email protected]>
replaced kmalloc with local variable as I2C(in this case) doesn't
require
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
kmalloc memory it can do with stack memory.
I've cc'd linux-i2c just to check I'm right about the whole i2c
doesn't need
Quoted 3 lines
Quoted 1 line
dma safe buffers bit...
No, it is down to the i2c driver, and from recollection dma from stack
is
Quoted 2 lines
not recommended, due to things like cache line alignment. Please do not do this.
Quoted 9 lines
Quoted 3 lines
To be clearer, it is down to the i2c BUS (adapter) driver, NOT the i2c device driver. So the patch is correct.
I think i can take Jean ack on this?If yes then Joanthan kindly apply this patch and i think you didn't lead me in wrong way as whatever said by you is corroborated by jean also i.e. it is I2C bus driver responsiblity
to care about DMA.
Sorry to ping you again.Can i take your ack on this?
Quoted 15 lines
Quoted 13 lines
Keep in mind that not all I2C/SMBus controllers care about DMA. In fact, most don't (at least in the set I am maintaining - might be different an embedded.) So calling kmalloc for every transfer in every I2C device driver "just in case" is very much counterproductive.
And, if a controller does DMA and needs well-aligned, dynamically allocated buffer, its driver would hopefully allocate the buffer ONCE and keep it around, rather than reallocating it for every transfer.
--
Jean Delvare
Jean Delvare
Acked-byQuoted 5 lines · anish singh
Quoted 4 lines · anish singh
Quoted 3 lines · Jean Delvare
To be clearer, it is down to the i2c BUS (adapter) driver, NOT the i2c device driver. So the patch is correct.
Quoted 7 lines
Quoted 6 lines
I think i can take Jean ack on this?If yes then Joanthan kindly apply this patch and i think you didn't lead me in wrong way as whatever said by you is corroborated by jean also i.e. it is I2C bus driver responsiblity
to care about DMA.Sorry to ping you again.Can i take your ack on this?
Yes of course.
Signature · 1 line
Jean Delvare
Quoted 14 lines · Jean Delvare
Quoted 1 line · anish singh
On Wed, Jun 8, 2011 at 10:41 AM, anish singh <
Quoted 1 line · [email protected]>wrote:
Quoted 1 line
On Tue, Jun 7, 2011 at 7:32 PM, Jean Delvare <[email protected]>
Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 3 lines
To be clearer, it is down to the i2c BUS (adapter) driver, NOT the i2c device driver. So the patch is correct.
I think i can take Jean ack on this?If yes then Joanthan kindly apply this patch and i think you didn't lead me in wrong way as whatever said by you is corroborated by jean also i.e. it is I2C bus driver responsiblity
to care about DMA.
Quoted 6 lines
Quoted 1 line
Sorry to ping you again.Can i take your ack on this?
Yes of course.
Acked-by Jean Delvare <[email protected]>
Thanks a ton.Jonathan kindly apply it now :)
Quoted 4 lines
--
Jean Delvare
Quoted 16 lines · anish singh
On Thu, Jun 9, 2011 at 1:59 PM, Jean Delvare <[email protected] <mailto:[email protected]>> wrote:
On Thu, 9 Jun 2011 13:53:09 +0530, anish singh wrote:
> On Wed, Jun 8, 2011 at 10:41 AM, anish singh <[email protected] <mailto:[email protected]>>wrote:
> > On Tue, Jun 7, 2011 at 7:32 PM, Jean Delvare <[email protected] <mailto:[email protected]>> wrote:
> >> To be clearer, it is down to the i2c BUS (adapter) driver, NOT the i2c
> >> device driver. So the patch is correct.
> >>
> > I think i can take Jean ack on this?If yes then Joanthan kindly apply
> > this patch and i think you didn't lead me in wrong way as whatever
> > said by you is corroborated by jean also i.e. it is I2C bus driver
> > responsiblity
> > to care about DMA.
> >
Quoted 7 lines
> Sorry to ping you again.Can i take your ack on this?
Yes of course.
Acked-by Jean Delvare <[email protected] <mailto:[email protected]>>Thanks a ton.Jonathan kindly apply it now :)
Greg, I'll send this one on to you with the set I currently have out for review.
Jonathan
Quoted 17 lines · Jonathan Cameron
Quoted 16 lines · anish singh
On Thu, Jun 9, 2011 at 1:59 PM, Jean Delvare <[email protected] <mailto:[email protected]>> wrote:
On Thu, 9 Jun 2011 13:53:09 +0530, anish singh wrote:
> On Wed, Jun 8, 2011 at 10:41 AM, anish singh <[email protected] <mailto:[email protected]>>wrote:
> > On Tue, Jun 7, 2011 at 7:32 PM, Jean Delvare <[email protected] <mailto:[email protected]>> wrote:
> >> To be clearer, it is down to the i2c BUS (adapter) driver, NOT the i2c
> >> device driver. So the patch is correct.
> >>
> > I think i can take Jean ack on this?If yes then Joanthan kindly apply
> > this patch and i think you didn't lead me in wrong way as whatever
> > said by you is corroborated by jean also i.e. it is I2C bus driver
> > responsiblity
> > to care about DMA.
> >
Quoted 9 lines
Quoted 7 lines
Quoted 1 line
Sorry to ping you again.Can i take your ack on this?
Yes of course.
Acked-by Jean Delvare <[email protected] <mailto:[email protected]>>Thanks a ton.Jonathan kindly apply it now :)
Greg, I'll send this one on to you with the set I currently have out for review.
Doh, after all this, I just tried to apply this to find the code in question has already gone. Anish, what tree are you working against? Looks like I did an equivalent clean up (with a load of others) back in May then forgot about it.
Sorry all. I should have actually have checked it was still relevant rather than reviewing purely on basis of content of patch...
Jonathan
Quoted 32 lines · Jonathan Cameron
Quoted 4 lines · Jonathan Cameron
Quoted 3 lines · anish singh
On Thu, Jun 9, 2011 at 1:59 PM, Jean Delvare <[email protected]<mailto:
Quoted 3 lines · [email protected]>> wrote:
Quoted 3 lines · anish singh
Quoted 1 line
On Wed, Jun 8, 2011 at 10:41 AM, anish singh <
Quoted 1 line · [email protected] <mailto:[email protected]>>wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
On Tue, Jun 7, 2011 at 7:32 PM, Jean Delvare <
Quoted 1 line · [email protected] <mailto:[email protected]>> wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
To be clearer, it is down to the i2c BUS (adapter) driver, NOT
the i2c
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
device driver. So the patch is correct.
I think i can take Jean ack on this?If yes then Joanthan kindly
apply
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
this patch and i think you didn't lead me in wrong way as
whatever
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
said by you is corroborated by jean also i.e. it is I2C bus
driver
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
responsiblity
to care about DMA.Sorry to ping you again.Can i take your ack on this?
Yes of course.
Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
Thanks a ton.Jonathan kindly apply it now :)
Greg, I'll send this one on to you with the set I currently have out for
review.
Quoted 1 line
Doh, after all this, I just tried to apply this to find the code in question has already
gone. Anish, what tree are you working against?
I am using linux-next.Is it not the right tree for staging?
Quoted 9 lines
Looks like I did an equivalent clean up
(with a load of others) back in May then forgot about it.Sorry all. I should have actually have checked it was still relevant rather than reviewing
purely on basis of content of patch...Jonathan
Quoted 28 lines · anish singh
On Thu, Jun 9, 2011 at 7:46 PM, Jonathan Cameron <[email protected] <mailto:[email protected]>> wrote:
On 06/09/11 09:48, Jonathan Cameron wrote:
> On 06/09/11 09:34, anish singh wrote:
>>
>>
>> On Thu, Jun 9, 2011 at 1:59 PM, Jean Delvare <[email protected] <mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>> wrote:
>>
>> On Thu, 9 Jun 2011 13:53:09 +0530, anish singh wrote:
>> > On Wed, Jun 8, 2011 at 10:41 AM, anish singh <[email protected] <mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>>wrote:
>> > > On Tue, Jun 7, 2011 at 7:32 PM, Jean Delvare <[email protected] <mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>> wrote:
>> > >> To be clearer, it is down to the i2c BUS (adapter) driver, NOT the i2c
>> > >> device driver. So the patch is correct.
>> > >>
>> > > I think i can take Jean ack on this?If yes then Joanthan kindly apply
>> > > this patch and i think you didn't lead me in wrong way as whatever
>> > > said by you is corroborated by jean also i.e. it is I2C bus driver
>> > > responsiblity
>> > > to care about DMA.
>> > >
>> > Sorry to ping you again.Can i take your ack on this?
>>
>> Yes of course.
>>
>> Acked-by: Jean Delvare <[email protected] <mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>>
>>
Quoted 7 lines
>> Thanks a ton.Jonathan kindly apply it now :)
> Greg, I'll send this one on to you with the set I currently have out for review. >
Doh, after all this, I just tried to apply this to find the code in question has already gone. Anish, what tree are you working against?I am using linux-next.Is it not the right tree for staging?
Something curious is going on then because this code is no longer in linux-next either.
Quoted 10 lines
Looks like I did an equivalent clean up
(with a load of others) back in May then forgot about it.Sorry all. I should have actually have checked it was still relevant rather than reviewing purely on basis of content of patch...
Jonathan
Quoted 46 lines · Jonathan Cameron
Quoted 3 lines · anish singh
On Thu, Jun 9, 2011 at 7:46 PM, Jonathan Cameron <[email protected]<mailto:
Quoted 6 lines · [email protected]>> wrote:
On 06/09/11 09:48, Jonathan Cameron wrote: > On 06/09/11 09:34, anish singh wrote: >> >> >> On Thu, Jun 9, 2011 at 1:59 PM, Jean Delvare <[email protected]<mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>>
Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines · anish singh
Quoted 1 line
On Wed, Jun 8, 2011 at 10:41 AM, anish singh <
[email protected] <mailto:[email protected]> <mailto:
Quoted 1 line · [email protected] <mailto:[email protected]>>>wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
On Tue, Jun 7, 2011 at 7:32 PM, Jean Delvare <
[email protected] <mailto:[email protected]> <mailto:[email protected]<mailto:
Quoted 1 line · [email protected]>>> wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
To be clearer, it is down to the i2c BUS (adapter)
driver, NOT the i2c
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
device driver. So the patch is correct.
I think i can take Jean ack on this?If yes then Joanthan
kindly apply
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
this patch and i think you didn't lead me in wrong way as
whatever
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
said by you is corroborated by jean also i.e. it is I2C
bus driver
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
responsiblity
to care about DMA.Sorry to ping you again.Can i take your ack on this?
Yes of course.
[email protected]> <mailto:[email protected] <mailto:[email protected]
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Thanks a ton.Jonathan kindly apply it now :)
Greg, I'll send this one on to you with the set I currently have
out for review.
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Doh, after all this, I just tried to apply this to find the code in
question has already
Quoted 3 lines
gone. Anish, what tree are you working against?
I am using linux-next.Is it not the right tree for staging?
Something curious is going on then because this code is no longer in linux-next either.
Even checked it now it is not there.Will check, thanks.
Quoted 13 lines
Quoted 5 lines
Looks like I did an equivalent clean up
(with a load of others) back in May then forgot about it.Sorry all. I should have actually have checked it was still relevant
rather than reviewing
Quoted 5 lines
purely on basis of content of patch...
Jonathan