Staging: comedi: drivers: comedi_test: Avoid multiple line dereference
PATCH 1/1 Staging: comedi: drivers: comedi_test: Avoid multiple line dereference
Fix checkpatch warning "Avoid multiple line dereference" using a local variable to avoid line wrap.
--- drivers/staging/comedi/drivers/comedi_test.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/comedi/drivers/comedi_test.c +2 -4
@@ -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;
Signature · 1 line
2.7.4
Quoted 17 lines · Cheah Kok Cheong
Fix checkpatch warning "Avoid multiple line dereference" using a local variable to avoid line wrap.
Signed-off-by Cheah Kok Cheong <[email protected]>--- drivers/staging/comedi/drivers/comedi_test.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/staging/comedi/drivers/comedi_test.c +0
-0@@ -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]);
drivers/staging/comedi/drivers/comedi_test.c static void waveform_ao_timer(unsigned long arg) · line 488
Quoted 10 lines
drivers/staging/comedi/drivers/comedi_test.c +2
-4+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.
Signature · 2 lines
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=- -=( Web: http://www.mev.co.uk/ )=-
Quoted 19 lines · Ian Abbott
Quoted 18 lines · Cheah Kok Cheong
Fix checkpatch warning "Avoid multiple line dereference" using a local variable to avoid line wrap.
Signed-off-by Cheah Kok Cheong <[email protected]>---
drivers/staging/comedi/drivers/comedi_test.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)drivers/staging/comedi/drivers/comedi_test.c +1
-0@@ -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];
Quoted 12 lines
drivers/staging/comedi/drivers/comedi_test.c static void waveform_ao_timer(unsigned long arg) · line 488
Quoted 9 lines
drivers/staging/comedi/drivers/comedi_test.c +1
-4-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
Quoted 58 lines · Cheah Kok Cheong
Quoted 19 lines · Ian Abbott
Quoted 18 lines · Cheah Kok Cheong
Fix checkpatch warning "Avoid multiple line dereference" using a local variable to avoid line wrap.
Signed-off-by Cheah Kok Cheong <[email protected]>---
drivers/staging/comedi/drivers/comedi_test.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)drivers/staging/comedi/drivers/comedi_test.c +1
-0@@ -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];Quoted 12 lines
drivers/staging/comedi/drivers/comedi_test.c static void waveform_ao_timer(unsigned long arg) · line 488
Quoted 9 lines
drivers/staging/comedi/drivers/comedi_test.c +1
-4-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 */
Quoted 1 line
[ 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().
Signature · 2 lines
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=- -=( Web: http://www.mev.co.uk/ )=-
Quoted 55 lines · Ian Abbott
Quoted 54 lines · Cheah Kok Cheong
Quoted 19 lines · Ian Abbott
Quoted 18 lines · Cheah Kok Cheong
Fix checkpatch warning "Avoid multiple line dereference" using a local variable to avoid line wrap.
Signed-off-by Cheah Kok Cheong <[email protected]>---
drivers/staging/comedi/drivers/comedi_test.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)drivers/staging/comedi/drivers/comedi_test.c +1
-0@@ -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];Quoted 12 lines
drivers/staging/comedi/drivers/comedi_test.c static void waveform_ao_timer(unsigned long arg) · line 488
Quoted 9 lines
drivers/staging/comedi/drivers/comedi_test.c +1
-4-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; }
Quoted 9 lines
Quoted 5 lines
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
Quoted 108 lines · Cheah Kok Cheong
Quoted 55 lines · Ian Abbott
Quoted 54 lines · Cheah Kok Cheong
Quoted 19 lines · Ian Abbott
Quoted 18 lines · Cheah Kok Cheong
Fix checkpatch warning "Avoid multiple line dereference" using a local variable to avoid line wrap.
Signed-off-by Cheah Kok Cheong <[email protected]>---
drivers/staging/comedi/drivers/comedi_test.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)drivers/staging/comedi/drivers/comedi_test.c +1
-0@@ -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];Quoted 12 lines
drivers/staging/comedi/drivers/comedi_test.c static void waveform_ao_timer(unsigned long arg) · line 488
Quoted 9 lines
drivers/staging/comedi/drivers/comedi_test.c +1
-4-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; }Quoted 9 lines
Quoted 5 lines
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; } }
Quoted 1 line
[ 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.
Signature · 2 lines
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=- -=( Web: http://www.mev.co.uk/ )=-
Quoted 109 lines · Ian Abbott
Quoted 108 lines · Cheah Kok Cheong
Quoted 55 lines · Ian Abbott
Quoted 54 lines · Cheah Kok Cheong
Quoted 19 lines · Ian Abbott
Quoted 18 lines · Cheah Kok Cheong
Fix checkpatch warning "Avoid multiple line dereference" using a local variable to avoid line wrap.
Signed-off-by Cheah Kok Cheong <[email protected]>---
drivers/staging/comedi/drivers/comedi_test.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)drivers/staging/comedi/drivers/comedi_test.c +1
-0@@ -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];Quoted 12 lines
drivers/staging/comedi/drivers/comedi_test.c static void waveform_ao_timer(unsigned long arg) · line 488
Quoted 9 lines
drivers/staging/comedi/drivers/comedi_test.c +1
-4-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; }Quoted 9 lines
Quoted 5 lines
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; } }
Quoted 5 lines
Quoted 1 line
[ 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.
Quoted 3 lines
Signature · 2 lines
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=- -=( Web: http://www.mev.co.uk/ )=-
Quoted 110 lines · Valentin Rothberg
Quoted 109 lines · Ian Abbott
Quoted 108 lines · Cheah Kok Cheong
Quoted 55 lines · Ian Abbott
Quoted 54 lines · Cheah Kok Cheong
Quoted 19 lines · Ian Abbott
Quoted 18 lines · Cheah Kok Cheong
Fix checkpatch warning "Avoid multiple line dereference" using a local variable to avoid line wrap.
Signed-off-by Cheah Kok Cheong <[email protected]>---
drivers/staging/comedi/drivers/comedi_test.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)drivers/staging/comedi/drivers/comedi_test.c +1
-0@@ -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];Quoted 12 lines
drivers/staging/comedi/drivers/comedi_test.c static void waveform_ao_timer(unsigned long arg) · line 488
Quoted 9 lines
drivers/staging/comedi/drivers/comedi_test.c +1
-4-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; }Quoted 9 lines
Quoted 5 lines
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; } }
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
[ 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.
Quoted 4 lines
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
Quoted 6 lines · Cheah Kok Cheong
Quoted 3 lines
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
Quoted 10 lines · Joe Perches
Quoted 6 lines · Cheah Kok Cheong
Quoted 3 lines
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
Quoted 10 lines
$ 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