Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422783Ab2KNMlh (ORCPT ); Wed, 14 Nov 2012 07:41:37 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:48171 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422749Ab2KNMlg (ORCPT ); Wed, 14 Nov 2012 07:41:36 -0500 Date: Wed, 14 Nov 2012 15:41:11 +0300 From: Dan Carpenter To: YAMANE Toshiaki Cc: Greg Kroah-Hartman , Devendra Naga , Rusty Russell , Alan Stern , Mauro Carvalho Chehab , 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 Message-ID: <20121114124110.GG11515@mwanda> References: <1352496782-7246-1-git-send-email-yamanetoshi@gmail.com> <1352496836-7280-1-git-send-email-yamanetoshi@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1352496836-7280-1-git-send-email-yamanetoshi@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2396 Lines: 76 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 > --- > 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/