public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: YAMANE Toshiaki <yamanetoshi@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Devendra Naga <devendra.aaru@gmail.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Alan Stern <stern@rowland.harvard.edu>,
	Mauro Carvalho Chehab <mchehab@redhat.com>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] staging/serqt_usb2: refactor qt_read_bulk_callback() in serqt_usb2.c
Date: Wed, 14 Nov 2012 15:41:11 +0300	[thread overview]
Message-ID: <20121114124110.GG11515@mwanda> (raw)
In-Reply-To: <1352496836-7280-1-git-send-email-yamanetoshi@gmail.com>

On Sat, Nov 10, 2012 at 06:33:56AM +0900, YAMANE Toshiaki wrote:
> Modified to eliminate the deep nesting and redundant description.
> 
> Signed-off-by: YAMANE Toshiaki <yamanetoshi@gmail.com>
> ---
>  drivers/staging/serqt_usb2/serqt_usb2.c |  147 +++++++++++++++++--------------
>  1 file changed, 80 insertions(+), 67 deletions(-)
> 
> diff --git a/drivers/staging/serqt_usb2/serqt_usb2.c b/drivers/staging/serqt_usb2/serqt_usb2.c
> index 9bc8923..0395bdf 100644
> --- a/drivers/staging/serqt_usb2/serqt_usb2.c
> +++ b/drivers/staging/serqt_usb2/serqt_usb2.c
> @@ -291,22 +291,89 @@ static void qt_interrupt_callback(struct urb *urb)
>  	/* FIXME */
>  }
>  
> +static int qt_status_change(unsigned int limit,
> +			    unsigned char *data,
> +			    int i,
> +			    struct quatech_port *qt_port,
> +			    struct usb_serial_port *port)
> +{
> +	void (*fn)(struct quatech_port *, unsigned char);
> +
> +	if (0x00 == data[i + 2]) {
> +		dev_dbg(&port->dev, "Line status status.\n");
> +		fn = ProcessLineStatus;
> +	} else {
> +		dev_dbg(&port->dev, "Modem status status.\n");
> +		fn = ProcessModemStatus;
> +	}
> +
> +	if (i > limit) {

Why can't we test whether i == (RxCount - 3) earlier and handle
the errors there?  That way we wouldn't need to pass the limit
variable.

In fact, this whole function is sort of nasty.  We start by doing
a switch (data[i + 2]) { then we combine the 0x00 and 0x01 and call
this function which separates them out and sets a function pointer
and then calls the function point?  Get rid of this whole function.

You shouldn't need to use function pointers to do this; that's too
many levels of abstraction.

> +		dev_dbg(&port->dev,
> +			"Illegal escape seuences in received data\n");
> +		return 0;
> +	}
> +
> +	(*fn)(qt_port, data[i + 3]);
> +
> +	return 1;
> +}
> +

[snip]

>  	if (urb->status) {
>  		qt_port->ReadBulkStopped = 1;
> -		dev_dbg(&urb->dev->dev, "%s - nonzero write bulk status received: %d\n",
> +		dev_dbg(&urb->dev->dev,
> +			"%s - nonzero write bulk status received: %d\n",
>  			__func__, urb->status);

Don't mix in these unrelated 80 character limit changes.

regards,
dan carpenter


  reply	other threads:[~2012-11-14 12:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-09 21:33 [PATCH 1/4] staging/serqt_usb2: fixed line over issue in serqt_usb2.c YAMANE Toshiaki
2012-11-09 21:33 ` [PATCH 2/4] staging/serqt_usb2: refactor qt_read_bulk_callback() " YAMANE Toshiaki
2012-11-14 12:41   ` Dan Carpenter [this message]
2012-11-14 20:09     ` YAMANE Toshiaki
2012-11-15 20:01     ` YAMANE Toshiaki
2012-11-15 20:18       ` Dan Carpenter
2012-11-15 20:32         ` YAMANE Toshiaki
2012-11-15 20:43           ` Dan Carpenter
2012-11-15 20:53             ` YAMANE Toshiaki
2012-11-09 21:34 ` [PATCH 3/4] staging/serqt_usb2: refactor qt_open() " YAMANE Toshiaki
2012-11-09 21:34 ` [PATCH 4/4] staging/serqt_usb2: refactor qt_unthrottle() " YAMANE Toshiaki

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=20121114124110.GG11515@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=devendra.aaru@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=stern@rowland.harvard.edu \
    --cc=yamanetoshi@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