mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: SF Markus Elfring <elfring@users.sourceforge.net>,
	devel@driverdev.osuosl.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] staging: comedi: usbduxfast: Improve unlocking of a mutex in usbduxfast_ai_insn_read()
Date: Fri, 3 Nov 2017 14:00:18 +0000	[thread overview]
Message-ID: <faf75ea4-e1cf-1959-2705-7da1d49bddde@mev.co.uk> (raw)
In-Reply-To: <b0acc12a-e48c-d51a-f7e3-606e66e6fe7b@users.sourceforge.net>

On 02/11/17 19:40, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 2 Nov 2017 20:30:31 +0100
> 
> * Add a jump target so that a call of the function "mutex_unlock" is stored
>    only twice in this function implementation.
> 
> * Replace five calls by goto statements.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>   drivers/staging/comedi/drivers/usbduxfast.c | 24 ++++++++++++------------
>   1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c
> index 608403c7586b..e5884faf7275 100644
> --- a/drivers/staging/comedi/drivers/usbduxfast.c
> +++ b/drivers/staging/comedi/drivers/usbduxfast.c
> @@ -777,8 +777,8 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
>   	if (devpriv->ai_cmd_running) {
>   		dev_err(dev->class_dev,
>   			"ai_insn_read not possible, async cmd is running\n");
> -		mutex_unlock(&devpriv->mut);
> -		return -EBUSY;
> +		ret = -EBUSY;
> +		goto unlock;
>   	}
>   
>   	/* set command for the first channel */
> @@ -798,10 +798,8 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
>   	usbduxfast_cmd_data(dev, 6, 0x01, 0x00, rngmask, 0x00);
>   
>   	ret = usbduxfast_send_cmd(dev, SENDADCOMMANDS);
> -	if (ret < 0) {
> -		mutex_unlock(&devpriv->mut);
> -		return ret;
> -	}
> +	if (ret < 0)
> +		goto unlock;
>   
>   	for (i = 0; i < PACKETS_TO_IGNORE; i++) {
>   		ret = usb_bulk_msg(usb, usb_rcvbulkpipe(usb, BULKINEP),
> @@ -809,8 +807,7 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
>   				   &actual_length, 10000);
>   		if (ret < 0) {
>   			dev_err(dev->class_dev, "insn timeout, no data\n");
> -			mutex_unlock(&devpriv->mut);
> -			return ret;
> +			goto unlock;
>   		}
>   	}
>   
> @@ -820,14 +817,13 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
>   				   &actual_length, 10000);
>   		if (ret < 0) {
>   			dev_err(dev->class_dev, "insn data error: %d\n", ret);
> -			mutex_unlock(&devpriv->mut);
> -			return ret;
> +			goto unlock;
>   		}
>   		n = actual_length / sizeof(u16);
>   		if ((n % 16) != 0) {
>   			dev_err(dev->class_dev, "insn data packet corrupted\n");
> -			mutex_unlock(&devpriv->mut);
> -			return -EINVAL;
> +			ret = -EINVAL;
> +			goto unlock;
>   		}
>   		for (j = chan; (j < n) && (i < insn->n); j = j + 16) {
>   			data[i] = ((u16 *)(devpriv->inbuf))[j];
> @@ -838,6 +834,10 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
>   	mutex_unlock(&devpriv->mut);
>   
>   	return insn->n;

Minor niggle: You could also remove that call to mutex_unlock() by 
replacing the above three lines with:

	ret = insn->n;

which will fall through to the 'unlock:' label below.

> +
> +unlock:
> +	mutex_unlock(&devpriv->mut);
> +	return ret;
>   }
>   
>   static int usbduxfast_upload_firmware(struct comedi_device *dev,
> 


-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-

  reply	other threads:[~2017-11-03 14:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-02 19:40 SF Markus Elfring
2017-11-03 14:00 ` Ian Abbott [this message]
2017-11-03 14:14   ` Greg Kroah-Hartman
2017-11-03 17:07     ` SF Markus Elfring
2017-11-03 16:39   ` [PATCH] " SF Markus Elfring

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=faf75ea4-e1cf-1959-2705-7da1d49bddde@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=devel@driverdev.osuosl.org \
    --cc=elfring@users.sourceforge.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=hsweeten@visionengravers.com \
    --cc=kernel-janitors@vger.kernel.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

all inboxes | Powered by JetHome®