From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754035AbaBMKI7 (ORCPT ); Thu, 13 Feb 2014 05:08:59 -0500 Received: from mail.mev.co.uk ([62.49.15.74]:56878 "EHLO mail.mev.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752519AbaBMKIr (ORCPT ); Thu, 13 Feb 2014 05:08:47 -0500 Message-ID: <52FC99AA.90508@mev.co.uk> Date: Thu, 13 Feb 2014 10:08:42 +0000 From: Ian Abbott User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: Chase Southwood , gregkh@linuxfoundation.org CC: hsweeten@visionengravers.com, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Staging: comedi: clean up conditional statement in addi_apci_3xxx.c References: <1392262167-4073-1-git-send-email-chase.southwood@yahoo.com> In-Reply-To: <1392262167-4073-1-git-send-email-chase.southwood@yahoo.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2014-02-13 03:29, 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 > --- > 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) Seems correct. Acked-by: Ian Abbott -- -=( Ian Abbott @ MEV Ltd. E-mail: )=- -=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-