Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1584405 > unrolled thread
| Started by | Cheah Kok Cheong <thrust73@gmail.com> |
|---|---|
| First post | 2017-02-20 09:40 +0100 |
| Last post | 2017-02-22 09:40 +0100 |
| Articles | 10 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference Cheah Kok Cheong <thrust73@gmail.com> - 2017-02-20 09:40 +0100
Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference Ian Abbott <abbotti@mev.co.uk> - 2017-02-20 11:10 +0100
Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference Cheah Kok Cheong <thrust73@gmail.com> - 2017-02-20 17:10 +0100
Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference Ian Abbott <abbotti@mev.co.uk> - 2017-02-20 18:40 +0100
Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference Cheah Kok Cheong <thrust73@gmail.com> - 2017-02-21 10:40 +0100
Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference Ian Abbott <abbotti@mev.co.uk> - 2017-02-21 11:20 +0100
Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference Valentin Rothberg <valentinrothberg@gmail.com> - 2017-02-21 11:30 +0100
Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference Cheah Kok Cheong <thrust73@gmail.com> - 2017-02-21 17:40 +0100
Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference Joe Perches <joe@perches.com> - 2017-02-21 18:30 +0100
Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference Valentin Rothberg <valentinrothberg@gmail.com> - 2017-02-22 09:40 +0100
| From | Cheah Kok Cheong <thrust73@gmail.com> |
|---|---|
| Date | 2017-02-20 09:40 +0100 |
| Subject | [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference |
| Message-ID | <tcRFM-2hh-15@gated-at.bofh.it> |
Fix checkpatch warning "Avoid multiple line dereference"
using a local variable to avoid line wrap.
Signed-off-by: Cheah Kok Cheong <thrust73@gmail.com>
---
drivers/staging/comedi/drivers/comedi_test.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
index 2a063f0..fde83e0 100644
--- a/drivers/staging/comedi/drivers/comedi_test.c
+++ b/drivers/staging/comedi/drivers/comedi_test.c
@@ -480,11 +480,9 @@ static void waveform_ao_timer(unsigned long arg)
/* output the last scan */
for (i = 0; i < cmd->scan_end_arg; i++) {
unsigned int chan = CR_CHAN(cmd->chanlist[i]);
+ unsigned short d = devpriv->ao_loopbacks[chan];
- if (comedi_buf_read_samples(s,
- &devpriv->
- ao_loopbacks[chan],
- 1) == 0) {
+ if (!comedi_buf_read_samples(s, &d, 1)) {
/* unexpected underrun! (cancelled?) */
async->events |= COMEDI_CB_OVERFLOW;
goto underrun;
--
2.7.4
[toc] | [next] | [standalone]
| From | Ian Abbott <abbotti@mev.co.uk> |
|---|---|
| Date | 2017-02-20 11:10 +0100 |
| Subject | Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference |
| Message-ID | <tcT4T-3ij-37@gated-at.bofh.it> |
| In reply to | #1584405 |
On 20/02/17 08:28, Cheah Kok Cheong wrote:
> Fix checkpatch warning "Avoid multiple line dereference"
> using a local variable to avoid line wrap.
>
> Signed-off-by: Cheah Kok Cheong <thrust73@gmail.com>
> ---
> drivers/staging/comedi/drivers/comedi_test.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
> index 2a063f0..fde83e0 100644
> --- a/drivers/staging/comedi/drivers/comedi_test.c
> +++ b/drivers/staging/comedi/drivers/comedi_test.c
> @@ -480,11 +480,9 @@ static void waveform_ao_timer(unsigned long arg)
> /* output the last scan */
> for (i = 0; i < cmd->scan_end_arg; i++) {
> unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> + unsigned short d = devpriv->ao_loopbacks[chan];
>
> - if (comedi_buf_read_samples(s,
> - &devpriv->
> - ao_loopbacks[chan],
> - 1) == 0) {
> + if (!comedi_buf_read_samples(s, &d, 1)) {
> /* unexpected underrun! (cancelled?) */
> async->events |= COMEDI_CB_OVERFLOW;
> goto underrun;
>
NAK. This leaves devpriv->ao_loopbacks[chan] unchanged.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@mev.co.uk> )=-
-=( Web: http://www.mev.co.uk/ )=-
[toc] | [prev] | [next] | [standalone]
| From | Cheah Kok Cheong <thrust73@gmail.com> |
|---|---|
| Date | 2017-02-20 17:10 +0100 |
| Subject | Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference |
| Message-ID | <tcYHf-6QY-9@gated-at.bofh.it> |
| In reply to | #1584463 |
On Mon, Feb 20, 2017 at 10:03:39AM +0000, Ian Abbott wrote:
> On 20/02/17 08:28, Cheah Kok Cheong wrote:
> >Fix checkpatch warning "Avoid multiple line dereference"
> >using a local variable to avoid line wrap.
> >
> >Signed-off-by: Cheah Kok Cheong <thrust73@gmail.com>
> >---
> > drivers/staging/comedi/drivers/comedi_test.c | 6 ++----
> > 1 file changed, 2 insertions(+), 4 deletions(-)
> >
> >diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
> >index 2a063f0..fde83e0 100644
> >--- a/drivers/staging/comedi/drivers/comedi_test.c
> >+++ b/drivers/staging/comedi/drivers/comedi_test.c
> >@@ -480,11 +480,9 @@ static void waveform_ao_timer(unsigned long arg)
> > /* output the last scan */
> > for (i = 0; i < cmd->scan_end_arg; i++) {
> > unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> >+ unsigned short d = devpriv->ao_loopbacks[chan];
> >
> >- if (comedi_buf_read_samples(s,
> >- &devpriv->
> >- ao_loopbacks[chan],
> >- 1) == 0) {
> >+ if (!comedi_buf_read_samples(s, &d, 1)) {
> > /* unexpected underrun! (cancelled?) */
> > async->events |= COMEDI_CB_OVERFLOW;
> > goto underrun;
> >
>
> NAK. This leaves devpriv->ao_loopbacks[chan] unchanged.
>
Thanks for pointing this out. In that case will assigning the variable to
devpriv->ao_loopbacks[chan] be acceptable? Please review below snippet.
Otherwise I'll just drop the variable and adjust the lines to avoid
checkpatch warning.
Sorry for the inconvenience caused.
[ Snip ]
/* output the last scan */
for (i = 0; i < cmd->scan_end_arg; i++) {
unsigned int chan = CR_CHAN(cmd->chanlist[i]);
unsigned short data;
if (!comedi_buf_read_samples(s, &data, 1)) {
/* unexpected underrun! (cancelled?) */
async->events |= COMEDI_CB_OVERFLOW;
goto underrun;
}
devpriv->ao_loopbacks[chan] = data;
}
/* advance time of last scan */
[ Snip ]
Thks.
Brgds,
CheahKC
[toc] | [prev] | [next] | [standalone]
| From | Ian Abbott <abbotti@mev.co.uk> |
|---|---|
| Date | 2017-02-20 18:40 +0100 |
| Subject | Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference |
| Message-ID | <td06m-7EN-27@gated-at.bofh.it> |
| In reply to | #1584701 |
On 20/02/17 16:02, Cheah Kok Cheong wrote:
> On Mon, Feb 20, 2017 at 10:03:39AM +0000, Ian Abbott wrote:
>> On 20/02/17 08:28, Cheah Kok Cheong wrote:
>>> Fix checkpatch warning "Avoid multiple line dereference"
>>> using a local variable to avoid line wrap.
>>>
>>> Signed-off-by: Cheah Kok Cheong <thrust73@gmail.com>
>>> ---
>>> drivers/staging/comedi/drivers/comedi_test.c | 6 ++----
>>> 1 file changed, 2 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
>>> index 2a063f0..fde83e0 100644
>>> --- a/drivers/staging/comedi/drivers/comedi_test.c
>>> +++ b/drivers/staging/comedi/drivers/comedi_test.c
>>> @@ -480,11 +480,9 @@ static void waveform_ao_timer(unsigned long arg)
>>> /* output the last scan */
>>> for (i = 0; i < cmd->scan_end_arg; i++) {
>>> unsigned int chan = CR_CHAN(cmd->chanlist[i]);
>>> + unsigned short d = devpriv->ao_loopbacks[chan];
>>>
>>> - if (comedi_buf_read_samples(s,
>>> - &devpriv->
>>> - ao_loopbacks[chan],
>>> - 1) == 0) {
>>> + if (!comedi_buf_read_samples(s, &d, 1)) {
>>> /* unexpected underrun! (cancelled?) */
>>> async->events |= COMEDI_CB_OVERFLOW;
>>> goto underrun;
>>>
>>
>> NAK. This leaves devpriv->ao_loopbacks[chan] unchanged.
>>
>
> Thanks for pointing this out. In that case will assigning the variable to
> devpriv->ao_loopbacks[chan] be acceptable? Please review below snippet.
>
> Otherwise I'll just drop the variable and adjust the lines to avoid
> checkpatch warning.
>
> Sorry for the inconvenience caused.
>
> [ Snip ]
>
> /* output the last scan */
> for (i = 0; i < cmd->scan_end_arg; i++) {
> unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> unsigned short data;
>
> if (!comedi_buf_read_samples(s, &data, 1)) {
> /* unexpected underrun! (cancelled?) */
> async->events |= COMEDI_CB_OVERFLOW;
> goto underrun;
> }
>
> devpriv->ao_loopbacks[chan] = data;
> }
> /* advance time of last scan */
>
> [ Snip ]
It will work, but you could just use a pointer variable set to
&devpriv->ao_loopbacks[chan] and pass that to comedi_buf_read_samples().
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@mev.co.uk> )=-
-=( Web: http://www.mev.co.uk/ )=-
[toc] | [prev] | [next] | [standalone]
| From | Cheah Kok Cheong <thrust73@gmail.com> |
|---|---|
| Date | 2017-02-21 10:40 +0100 |
| Subject | Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference |
| Message-ID | <tdf5o-Gy-11@gated-at.bofh.it> |
| In reply to | #1584797 |
On Mon, Feb 20, 2017 at 05:36:52PM +0000, Ian Abbott wrote:
> On 20/02/17 16:02, Cheah Kok Cheong wrote:
> >On Mon, Feb 20, 2017 at 10:03:39AM +0000, Ian Abbott wrote:
> >>On 20/02/17 08:28, Cheah Kok Cheong wrote:
> >>>Fix checkpatch warning "Avoid multiple line dereference"
> >>>using a local variable to avoid line wrap.
> >>>
> >>>Signed-off-by: Cheah Kok Cheong <thrust73@gmail.com>
> >>>---
> >>>drivers/staging/comedi/drivers/comedi_test.c | 6 ++----
> >>>1 file changed, 2 insertions(+), 4 deletions(-)
> >>>
> >>>diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
> >>>index 2a063f0..fde83e0 100644
> >>>--- a/drivers/staging/comedi/drivers/comedi_test.c
> >>>+++ b/drivers/staging/comedi/drivers/comedi_test.c
> >>>@@ -480,11 +480,9 @@ static void waveform_ao_timer(unsigned long arg)
> >>> /* output the last scan */
> >>> for (i = 0; i < cmd->scan_end_arg; i++) {
> >>> unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> >>>+ unsigned short d = devpriv->ao_loopbacks[chan];
> >>>
> >>>- if (comedi_buf_read_samples(s,
> >>>- &devpriv->
> >>>- ao_loopbacks[chan],
> >>>- 1) == 0) {
> >>>+ if (!comedi_buf_read_samples(s, &d, 1)) {
> >>> /* unexpected underrun! (cancelled?) */
> >>> async->events |= COMEDI_CB_OVERFLOW;
> >>> goto underrun;
> >>>
> >>
> >>NAK. This leaves devpriv->ao_loopbacks[chan] unchanged.
> >>
> >
> >Thanks for pointing this out. In that case will assigning the variable to
> >devpriv->ao_loopbacks[chan] be acceptable? Please review below snippet.
> >
> >Otherwise I'll just drop the variable and adjust the lines to avoid
> >checkpatch warning.
> >
> >Sorry for the inconvenience caused.
> >
> >[ Snip ]
> >
> > /* output the last scan */
> > for (i = 0; i < cmd->scan_end_arg; i++) {
> > unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> > unsigned short data;
> >
> > if (!comedi_buf_read_samples(s, &data, 1)) {
> > /* unexpected underrun! (cancelled?) */
> > async->events |= COMEDI_CB_OVERFLOW;
> > goto underrun;
> > }
> >
> > devpriv->ao_loopbacks[chan] = data;
> > }
> > /* advance time of last scan */
> >
> >[ Snip ]
>
> It will work, but you could just use a pointer variable set to
> &devpriv->ao_loopbacks[chan] and pass that to comedi_buf_read_samples().
>
Thanks for the suggestion. I tried below snippet 1 with the shortest pointer
name but 80 characters is exceeded. The declaration and initialisation
will have to be splitted. Will this be acceptable or am I doing it wrong
again?
Sorry for the trouble.
Snippet 1:
[ Snip ]
/* output the last scan */
for (i = 0; i < cmd->scan_end_arg; i++) {
unsigned int chan = CR_CHAN(cmd->chanlist[i]);
unsigned short *p = &devpriv->ao_loopbacks[chan];
if (!comedi_buf_read_samples(s, p, 1)) {
/* unexpected underrun! (cancelled?) */
async->events |= COMEDI_CB_OVERFLOW;
goto underrun;
}
}
/* advance time of last scan */
[ Snip ]
Snippet 2:
[ Snip ]
/* output the last scan */
for (i = 0; i < cmd->scan_end_arg; i++) {
unsigned int chan = CR_CHAN(cmd->chanlist[i]);
unsigned short *pd;
pd = &devpriv->ao_loopbacks[chan];
if (!comedi_buf_read_samples(s, pd, 1)) {
/* unexpected underrun! (cancelled?) */
async->events |= COMEDI_CB_OVERFLOW;
goto underrun;
}
}
[ Snip ]
Thks.
Brgds,
CheahKC
[toc] | [prev] | [next] | [standalone]
| From | Ian Abbott <abbotti@mev.co.uk> |
|---|---|
| Date | 2017-02-21 11:20 +0100 |
| Subject | Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference |
| Message-ID | <tdfI5-19o-13@gated-at.bofh.it> |
| In reply to | #1585164 |
On 21/02/2017 09:33, Cheah Kok Cheong wrote:
> On Mon, Feb 20, 2017 at 05:36:52PM +0000, Ian Abbott wrote:
>> On 20/02/17 16:02, Cheah Kok Cheong wrote:
>>> On Mon, Feb 20, 2017 at 10:03:39AM +0000, Ian Abbott wrote:
>>>> On 20/02/17 08:28, Cheah Kok Cheong wrote:
>>>>> Fix checkpatch warning "Avoid multiple line dereference"
>>>>> using a local variable to avoid line wrap.
>>>>>
>>>>> Signed-off-by: Cheah Kok Cheong <thrust73@gmail.com>
>>>>> ---
>>>>> drivers/staging/comedi/drivers/comedi_test.c | 6 ++----
>>>>> 1 file changed, 2 insertions(+), 4 deletions(-)
>>>>>
>>>>> diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
>>>>> index 2a063f0..fde83e0 100644
>>>>> --- a/drivers/staging/comedi/drivers/comedi_test.c
>>>>> +++ b/drivers/staging/comedi/drivers/comedi_test.c
>>>>> @@ -480,11 +480,9 @@ static void waveform_ao_timer(unsigned long arg)
>>>>> /* output the last scan */
>>>>> for (i = 0; i < cmd->scan_end_arg; i++) {
>>>>> unsigned int chan = CR_CHAN(cmd->chanlist[i]);
>>>>> + unsigned short d = devpriv->ao_loopbacks[chan];
>>>>>
>>>>> - if (comedi_buf_read_samples(s,
>>>>> - &devpriv->
>>>>> - ao_loopbacks[chan],
>>>>> - 1) == 0) {
>>>>> + if (!comedi_buf_read_samples(s, &d, 1)) {
>>>>> /* unexpected underrun! (cancelled?) */
>>>>> async->events |= COMEDI_CB_OVERFLOW;
>>>>> goto underrun;
>>>>>
>>>>
>>>> NAK. This leaves devpriv->ao_loopbacks[chan] unchanged.
>>>>
>>>
>>> Thanks for pointing this out. In that case will assigning the variable to
>>> devpriv->ao_loopbacks[chan] be acceptable? Please review below snippet.
>>>
>>> Otherwise I'll just drop the variable and adjust the lines to avoid
>>> checkpatch warning.
>>>
>>> Sorry for the inconvenience caused.
>>>
>>> [ Snip ]
>>>
>>> /* output the last scan */
>>> for (i = 0; i < cmd->scan_end_arg; i++) {
>>> unsigned int chan = CR_CHAN(cmd->chanlist[i]);
>>> unsigned short data;
>>>
>>> if (!comedi_buf_read_samples(s, &data, 1)) {
>>> /* unexpected underrun! (cancelled?) */
>>> async->events |= COMEDI_CB_OVERFLOW;
>>> goto underrun;
>>> }
>>>
>>> devpriv->ao_loopbacks[chan] = data;
>>> }
>>> /* advance time of last scan */
>>>
>>> [ Snip ]
>>
>> It will work, but you could just use a pointer variable set to
>> &devpriv->ao_loopbacks[chan] and pass that to comedi_buf_read_samples().
>>
>
> Thanks for the suggestion. I tried below snippet 1 with the shortest pointer
> name but 80 characters is exceeded. The declaration and initialisation
> will have to be splitted. Will this be acceptable or am I doing it wrong
> again?
>
> Sorry for the trouble.
>
> Snippet 1:
> [ Snip ]
>
> /* output the last scan */
> for (i = 0; i < cmd->scan_end_arg; i++) {
> unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> unsigned short *p = &devpriv->ao_loopbacks[chan];
>
> if (!comedi_buf_read_samples(s, p, 1)) {
> /* unexpected underrun! (cancelled?) */
> async->events |= COMEDI_CB_OVERFLOW;
> goto underrun;
> }
> }
> /* advance time of last scan */
>
> [ Snip ]
>
> Snippet 2:
> [ Snip ]
>
> /* output the last scan */
> for (i = 0; i < cmd->scan_end_arg; i++) {
> unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> unsigned short *pd;
>
> pd = &devpriv->ao_loopbacks[chan];
>
> if (!comedi_buf_read_samples(s, pd, 1)) {
> /* unexpected underrun! (cancelled?) */
> async->events |= COMEDI_CB_OVERFLOW;
> goto underrun;
> }
> }
>
> [ Snip ]
Snippet 2 looks fine. Alternatives are to modify Snippet 1 to split the
initialization of the pointer variable after the '=', or to shorten the
the name of the 'chan' variable.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@mev.co.uk> )=-
-=( Web: http://www.mev.co.uk/ )=-
[toc] | [prev] | [next] | [standalone]
| From | Valentin Rothberg <valentinrothberg@gmail.com> |
|---|---|
| Date | 2017-02-21 11:30 +0100 |
| Subject | Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference |
| Message-ID | <tdfRM-1cI-17@gated-at.bofh.it> |
| In reply to | #1585186 |
On Feb 21 '17 10:12, Ian Abbott wrote:
> On 21/02/2017 09:33, Cheah Kok Cheong wrote:
> > On Mon, Feb 20, 2017 at 05:36:52PM +0000, Ian Abbott wrote:
> > > On 20/02/17 16:02, Cheah Kok Cheong wrote:
> > > > On Mon, Feb 20, 2017 at 10:03:39AM +0000, Ian Abbott wrote:
> > > > > On 20/02/17 08:28, Cheah Kok Cheong wrote:
> > > > > > Fix checkpatch warning "Avoid multiple line dereference"
> > > > > > using a local variable to avoid line wrap.
> > > > > >
> > > > > > Signed-off-by: Cheah Kok Cheong <thrust73@gmail.com>
> > > > > > ---
> > > > > > drivers/staging/comedi/drivers/comedi_test.c | 6 ++----
> > > > > > 1 file changed, 2 insertions(+), 4 deletions(-)
> > > > > >
> > > > > > diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
> > > > > > index 2a063f0..fde83e0 100644
> > > > > > --- a/drivers/staging/comedi/drivers/comedi_test.c
> > > > > > +++ b/drivers/staging/comedi/drivers/comedi_test.c
> > > > > > @@ -480,11 +480,9 @@ static void waveform_ao_timer(unsigned long arg)
> > > > > > /* output the last scan */
> > > > > > for (i = 0; i < cmd->scan_end_arg; i++) {
> > > > > > unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> > > > > > + unsigned short d = devpriv->ao_loopbacks[chan];
> > > > > >
> > > > > > - if (comedi_buf_read_samples(s,
> > > > > > - &devpriv->
> > > > > > - ao_loopbacks[chan],
> > > > > > - 1) == 0) {
> > > > > > + if (!comedi_buf_read_samples(s, &d, 1)) {
> > > > > > /* unexpected underrun! (cancelled?) */
> > > > > > async->events |= COMEDI_CB_OVERFLOW;
> > > > > > goto underrun;
> > > > > >
> > > > >
> > > > > NAK. This leaves devpriv->ao_loopbacks[chan] unchanged.
> > > > >
> > > >
> > > > Thanks for pointing this out. In that case will assigning the variable to
> > > > devpriv->ao_loopbacks[chan] be acceptable? Please review below snippet.
> > > >
> > > > Otherwise I'll just drop the variable and adjust the lines to avoid
> > > > checkpatch warning.
> > > >
> > > > Sorry for the inconvenience caused.
> > > >
> > > > [ Snip ]
> > > >
> > > > /* output the last scan */
> > > > for (i = 0; i < cmd->scan_end_arg; i++) {
> > > > unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> > > > unsigned short data;
> > > >
> > > > if (!comedi_buf_read_samples(s, &data, 1)) {
> > > > /* unexpected underrun! (cancelled?) */
> > > > async->events |= COMEDI_CB_OVERFLOW;
> > > > goto underrun;
> > > > }
> > > >
> > > > devpriv->ao_loopbacks[chan] = data;
> > > > }
> > > > /* advance time of last scan */
> > > >
> > > > [ Snip ]
> > >
> > > It will work, but you could just use a pointer variable set to
> > > &devpriv->ao_loopbacks[chan] and pass that to comedi_buf_read_samples().
> > >
> >
> > Thanks for the suggestion. I tried below snippet 1 with the shortest pointer
> > name but 80 characters is exceeded. The declaration and initialisation
> > will have to be splitted. Will this be acceptable or am I doing it wrong
> > again?
> >
> > Sorry for the trouble.
> >
> > Snippet 1:
> > [ Snip ]
> >
> > /* output the last scan */
> > for (i = 0; i < cmd->scan_end_arg; i++) {
> > unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> > unsigned short *p = &devpriv->ao_loopbacks[chan];
> >
> > if (!comedi_buf_read_samples(s, p, 1)) {
> > /* unexpected underrun! (cancelled?) */
> > async->events |= COMEDI_CB_OVERFLOW;
> > goto underrun;
> > }
> > }
> > /* advance time of last scan */
> >
> > [ Snip ]
> >
> > Snippet 2:
> > [ Snip ]
> >
> > /* output the last scan */
> > for (i = 0; i < cmd->scan_end_arg; i++) {
> > unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> > unsigned short *pd;
> >
> > pd = &devpriv->ao_loopbacks[chan];
> >
> > if (!comedi_buf_read_samples(s, pd, 1)) {
> > /* unexpected underrun! (cancelled?) */
> > async->events |= COMEDI_CB_OVERFLOW;
> > goto underrun;
> > }
> > }
> >
> > [ Snip ]
>
> Snippet 2 looks fine. Alternatives are to modify Snippet 1 to split the
> initialization of the pointer variable after the '=', or to shorten the the
> name of the 'chan' variable.
Another option could be using the typedefs from include/linux/types.h,
e.g. ushort. However, this might require changing other declarations as
well to keep consistency.
> --
> -=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@mev.co.uk> )=-
> -=( Web: http://www.mev.co.uk/ )=-
[toc] | [prev] | [next] | [standalone]
| From | Cheah Kok Cheong <thrust73@gmail.com> |
|---|---|
| Date | 2017-02-21 17:40 +0100 |
| Subject | Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference |
| Message-ID | <tdlDR-55Q-39@gated-at.bofh.it> |
| In reply to | #1585194 |
On Tue, Feb 21, 2017 at 11:20:08AM +0100, Valentin Rothberg wrote:
> On Feb 21 '17 10:12, Ian Abbott wrote:
> > On 21/02/2017 09:33, Cheah Kok Cheong wrote:
> > > On Mon, Feb 20, 2017 at 05:36:52PM +0000, Ian Abbott wrote:
> > > > On 20/02/17 16:02, Cheah Kok Cheong wrote:
> > > > > On Mon, Feb 20, 2017 at 10:03:39AM +0000, Ian Abbott wrote:
> > > > > > On 20/02/17 08:28, Cheah Kok Cheong wrote:
> > > > > > > Fix checkpatch warning "Avoid multiple line dereference"
> > > > > > > using a local variable to avoid line wrap.
> > > > > > >
> > > > > > > Signed-off-by: Cheah Kok Cheong <thrust73@gmail.com>
> > > > > > > ---
> > > > > > > drivers/staging/comedi/drivers/comedi_test.c | 6 ++----
> > > > > > > 1 file changed, 2 insertions(+), 4 deletions(-)
> > > > > > >
> > > > > > > diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
> > > > > > > index 2a063f0..fde83e0 100644
> > > > > > > --- a/drivers/staging/comedi/drivers/comedi_test.c
> > > > > > > +++ b/drivers/staging/comedi/drivers/comedi_test.c
> > > > > > > @@ -480,11 +480,9 @@ static void waveform_ao_timer(unsigned long arg)
> > > > > > > /* output the last scan */
> > > > > > > for (i = 0; i < cmd->scan_end_arg; i++) {
> > > > > > > unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> > > > > > > + unsigned short d = devpriv->ao_loopbacks[chan];
> > > > > > >
> > > > > > > - if (comedi_buf_read_samples(s,
> > > > > > > - &devpriv->
> > > > > > > - ao_loopbacks[chan],
> > > > > > > - 1) == 0) {
> > > > > > > + if (!comedi_buf_read_samples(s, &d, 1)) {
> > > > > > > /* unexpected underrun! (cancelled?) */
> > > > > > > async->events |= COMEDI_CB_OVERFLOW;
> > > > > > > goto underrun;
> > > > > > >
> > > > > >
> > > > > > NAK. This leaves devpriv->ao_loopbacks[chan] unchanged.
> > > > > >
> > > > >
> > > > > Thanks for pointing this out. In that case will assigning the variable to
> > > > > devpriv->ao_loopbacks[chan] be acceptable? Please review below snippet.
> > > > >
> > > > > Otherwise I'll just drop the variable and adjust the lines to avoid
> > > > > checkpatch warning.
> > > > >
> > > > > Sorry for the inconvenience caused.
> > > > >
> > > > > [ Snip ]
> > > > >
> > > > > /* output the last scan */
> > > > > for (i = 0; i < cmd->scan_end_arg; i++) {
> > > > > unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> > > > > unsigned short data;
> > > > >
> > > > > if (!comedi_buf_read_samples(s, &data, 1)) {
> > > > > /* unexpected underrun! (cancelled?) */
> > > > > async->events |= COMEDI_CB_OVERFLOW;
> > > > > goto underrun;
> > > > > }
> > > > >
> > > > > devpriv->ao_loopbacks[chan] = data;
> > > > > }
> > > > > /* advance time of last scan */
> > > > >
> > > > > [ Snip ]
> > > >
> > > > It will work, but you could just use a pointer variable set to
> > > > &devpriv->ao_loopbacks[chan] and pass that to comedi_buf_read_samples().
> > > >
> > >
> > > Thanks for the suggestion. I tried below snippet 1 with the shortest pointer
> > > name but 80 characters is exceeded. The declaration and initialisation
> > > will have to be splitted. Will this be acceptable or am I doing it wrong
> > > again?
> > >
> > > Sorry for the trouble.
> > >
> > > Snippet 1:
> > > [ Snip ]
> > >
> > > /* output the last scan */
> > > for (i = 0; i < cmd->scan_end_arg; i++) {
> > > unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> > > unsigned short *p = &devpriv->ao_loopbacks[chan];
> > >
> > > if (!comedi_buf_read_samples(s, p, 1)) {
> > > /* unexpected underrun! (cancelled?) */
> > > async->events |= COMEDI_CB_OVERFLOW;
> > > goto underrun;
> > > }
> > > }
> > > /* advance time of last scan */
> > >
> > > [ Snip ]
> > >
> > > Snippet 2:
> > > [ Snip ]
> > >
> > > /* output the last scan */
> > > for (i = 0; i < cmd->scan_end_arg; i++) {
> > > unsigned int chan = CR_CHAN(cmd->chanlist[i]);
> > > unsigned short *pd;
> > >
> > > pd = &devpriv->ao_loopbacks[chan];
> > >
> > > if (!comedi_buf_read_samples(s, pd, 1)) {
> > > /* unexpected underrun! (cancelled?) */
> > > async->events |= COMEDI_CB_OVERFLOW;
> > > goto underrun;
> > > }
> > > }
> > >
> > > [ Snip ]
> >
> > Snippet 2 looks fine. Alternatives are to modify Snippet 1 to split the
> > initialization of the pointer variable after the '=', or to shorten the the
> > name of the 'chan' variable.
I'm tempted to shorten the 'chan' variable but this will break consistency
since it's also use in static int waveform_ai_insn_read() and
static int waveform_ao_insn_write(). I'll send Snippet 2 as V2.
>
> Another option could be using the typedefs from include/linux/types.h,
> e.g. ushort. However, this might require changing other declarations as
> well to keep consistency.
Thanks for the idea. I counted seven instances of 'unsigned short'
in this file so it's not viable for our situation.
Thks.
Brgds,
CheahKC
[toc] | [prev] | [next] | [standalone]
| From | Joe Perches <joe@perches.com> |
|---|---|
| Date | 2017-02-21 18:30 +0100 |
| Subject | Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference |
| Message-ID | <tdmqe-5F2-19@gated-at.bofh.it> |
| In reply to | #1585516 |
On Wed, 2017-02-22 at 00:31 +0800, Cheah Kok Cheong wrote: > > Another option could be using the typedefs from include/linux/types.h, > > e.g. ushort. However, this might require changing other declarations as > > well to keep consistency. > > Thanks for the idea. I counted seven instances of 'unsigned short' > in this file so it's not viable for our situation. I believe using ushort is relatively undesirable as "unsigned short" is preferred ~10:1 in the kernel $ git grep -w ushort | wc -l 1381 $ git grep -E "\bunsigned\s+short\b" | wc -l 11288 $ git grep --name-only -w "ushort" | wc -l 129 $ git grep --name-only -E "\bunsigned\s+short\b" | wc -l 2497
[toc] | [prev] | [next] | [standalone]
| From | Valentin Rothberg <valentinrothberg@gmail.com> |
|---|---|
| Date | 2017-02-22 09:40 +0100 |
| Subject | Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference |
| Message-ID | <tdACS-7m8-5@gated-at.bofh.it> |
| In reply to | #1585555 |
On Feb 21 '17 09:22, Joe Perches wrote: > On Wed, 2017-02-22 at 00:31 +0800, Cheah Kok Cheong wrote: > > > Another option could be using the typedefs from include/linux/types.h, > > > e.g. ushort. However, this might require changing other declarations as > > > well to keep consistency. > > > > Thanks for the idea. I counted seven instances of 'unsigned short' > > in this file so it's not viable for our situation. > > I believe using ushort is relatively undesirable as > "unsigned short" is preferred ~10:1 in the kernel Wow, that is suprising to me considering the 80 character limit. Thanks for pointing this out! Regards, Valentin > $ git grep -w ushort | wc -l > 1381 > $ git grep -E "\bunsigned\s+short\b" | wc -l > 11288 > > $ git grep --name-only -w "ushort" | wc -l > 129 > $ git grep --name-only -E "\bunsigned\s+short\b" | wc -l > 2497 >
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web