mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: Cheah Kok Cheong <thrust73@gmail.com>
Cc: hsweeten@visionengravers.com, gregkh@linuxfoundation.org,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Staging: comedi: drivers: comedi_test: Avoid multiple line dereference
Date: Tue, 21 Feb 2017 10:12:57 +0000	[thread overview]
Message-ID: <4b35e656-8fc2-13a5-663b-c8db45bed832@mev.co.uk> (raw)
In-Reply-To: <20170221093333.GA2775@linux-Precision-WorkStation-T5500>

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/  )=-

  reply	other threads:[~2017-02-21 10:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-20  8:28 Cheah Kok Cheong
2017-02-20 10:03 ` Ian Abbott
2017-02-20 16:02   ` Cheah Kok Cheong
2017-02-20 17:36     ` Ian Abbott
2017-02-21  9:33       ` Cheah Kok Cheong
2017-02-21 10:12         ` Ian Abbott [this message]
2017-02-21 10:20           ` Valentin Rothberg
2017-02-21 16:31             ` Cheah Kok Cheong
2017-02-21 17:22               ` Joe Perches
2017-02-22  8:30                 ` Valentin Rothberg

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=4b35e656-8fc2-13a5-663b-c8db45bed832@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hsweeten@visionengravers.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thrust73@gmail.com \
    /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

all inboxes | Powered by JetHome®