From: Ian Abbott <abbotti@mev.co.uk>
To: Hartley Sweeten <HartleyS@visionengravers.com>,
Chase Southwood <chase.southwood@yahoo.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Staging: comedi: clean up conditional statement in addi_apci_3xxx.c
Date: Fri, 14 Feb 2014 11:49:45 +0000 [thread overview]
Message-ID: <52FE02D9.1090205@mev.co.uk> (raw)
In-Reply-To: <DC148C5AA1CEBA4E87973D432B1C2D8817EBF5B2@P3PWEX4MB008.ex4.secureserver.net>
On 2014-02-13 18:25, Hartley Sweeten wrote:
> On Wednesday, February 12, 2014 8:29 PM, Chase Southwood wrote:
>> In this if-else conditional statement, if (chan < 16), but
>> (data[0] == INSN_CONFIG_DIO_QUERY), the function does not return early,
>> but the else-branch does not get executed either. As a result, mask
>> would be used uninitialized in the next line. What we want here is if
>> (chan < 16) and (data[0] != INSN_CONFIG_DIO_QUERY), return an error, but
>> in every other case, initialize mask and then proceed. Found by a static
>> checker.
>>
>> Signed-off-by: Chase Southwood <chase.southwood@yahoo.com>
>> ---
>> drivers/staging/comedi/drivers/addi_apci_3xxx.c | 12 +++++-------
>> 1 file changed, 5 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
>> index ceadf8e..04c5153 100644
>> --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c
>> +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
>> @@ -688,13 +688,11 @@ static int apci3xxx_dio_insn_config(struct comedi_device *dev,
>> * Port 1 (channels 8-15) are always outputs
>> * Port 2 (channels 16-23) are programmable i/o
>> */
>> - if (chan < 16) {
>> - if (data[0] != INSN_CONFIG_DIO_QUERY)
>> - return -EINVAL;
>> - } else {
>> - /* changing any channel in port 2 changes the entire port */
>> - mask = 0xff0000;
>> - }
>> + if ((chan < 16) && (data[0] != INSN_CONFIG_DIO_QUERY))
>> + return -EINVAL;
>> +
>> + /* changing any channel in port 2 changes the entire port */
>> + mask = 0xff0000;
>>
>> ret = comedi_dio_insn_config(dev, s, insn, data, mask);
>> if (ret)
>
> The uninitialized mask when chan < 16 is an issue. But your patch is not quite correct.
>
> The original code was intending to limit the valid instructions for channels < 16 to only
> INSN_CONFIG_DIO_QUERY. These channels have fixed directions: 0-7 (port 0) are
> always inputs and 8-15 (port 1) are always outputs. Channels 16-23 (port 2) have
> programmable direction but changing any channel effects the entire port, that's
> what the 0xff0000 mask is for.
>
> Changing the mask to 0xff0000 for any chanspec will result in the INSN_CONFIG_DIO_QUERY
> instruction returning the direction of port 2 regardless of what the chanspec is.
>
> The "right" fix would be:
> 1) Default the mask to 0 so that comedi_dio_insn_config() will use a chan_mask
> based on the chanspec for the INSN_CONFIG_DIO_QUERY instruction.
> 2) Ignore all instructions except INSN_CONFIG_DIO_QUERY when the chan < 16.
> 3) Modify the mask for chan >= 16 when the instruction is not INSN_CONFIG_DIO_QUERY
> so that the INSN_CONFIG_DIO_{INPUT,OUTPUT} instructions update the entire
> port.
Agreed, but another question is why does comedi_dio_insn_config() in
drivers.c need to look at the supplied mask at all for
INSN_CONFIG_DIO_QUERY?
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-
next prev parent reply other threads:[~2014-02-14 11:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-13 3:29 [PATCH] Staging: comedi: clean up conditional statement in addi_apci_3xxx.c Chase Southwood
2014-02-13 10:08 ` Ian Abbott
2014-02-14 11:52 ` Ian Abbott
2014-02-13 18:25 ` Hartley Sweeten
2014-02-14 11:49 ` Ian Abbott [this message]
2014-02-14 17:54 ` Hartley Sweeten
2014-02-14 1:02 ` [PATCH v2] " Chase Southwood
2014-02-14 11:54 ` Ian Abbott
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=52FE02D9.1090205@mev.co.uk \
--to=abbotti@mev.co.uk \
--cc=HartleyS@visionengravers.com \
--cc=chase.southwood@yahoo.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/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