Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1311782

RE: [PATCH v3 1/4 RESEND] USB: serial: cp210x: New register access functions.

From Konstantin Shkolnyy <Konstantin.Shkolnyy@silabs.com>
Newsgroups linux.kernel
Subject RE: [PATCH v3 1/4 RESEND] USB: serial: cp210x: New register access functions.
Date 2016-01-18 21:10 +0100
Message-ID <qSohH-5As-5@gated-at.bofh.it> (permalink)
References <qRF1f-r4-3@gated-at.bofh.it> <qSlWy-3Wp-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


> -----Original Message-----
> From: linux-usb-owner@vger.kernel.org [mailto:linux-usb-
> owner@vger.kernel.org] On Behalf Of Johan Hovold
> Sent: Monday, January 18, 2016 11:33
> To: Konstantin Shkolnyy
> Cc: johan@kernel.org; linux-usb@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: Re: [PATCH v3 1/4 RESEND] USB: serial: cp210x: New register access
> functions.
> 
> On Sat, Jan 16, 2016 at 01:46:24PM -0600, Konstantin Shkolnyy wrote:
> > cp210x_get_config and cp210x_set_config are cumbersome to use. This
> change
> > introduces new register access functions to replace them. New functions
> > are not yet called - the switch is done gradually in following changes.
> >
> > Signed-off-by: Konstantin Shkolnyy <konstantin.shkolnyy@gmail.com>
> > ---
> > change in v3: Presented new function addition as a separate patch #1,
> > to simplify code review.
> 
> Thanks for the v3.
> 
> You should not be adding (static) functions before they have a caller as
> this generates compiler warnings.
> 
> Please define the new helper functions when converting their call
> sites. You can split the 8, 16 and 32-bit helpers in separate patches and
> possibly also separate read and write if that makes sense in order to
> keep the diffs smaller.

I did split 8, 16 and 32 into 3 patches in v2, then it seemed to me it would be easier to review if I also separated new functions.
I can just use an amended v2 as v4.

I add reads and writes together to avoid type mismatches in the code that reads/writes the same variable,

> >  drivers/usb/serial/cp210x.c | 166
> ++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 166 insertions(+)
> >
> > diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> > index fd67958..324eb7e 100644
> > --- a/drivers/usb/serial/cp210x.c
> > +++ b/drivers/usb/serial/cp210x.c
> > @@ -323,6 +323,172 @@ struct cp210x_comm_status {
> >  #define PURGE_ALL		0x000f
> >
> >  /*
> > + * Reads a variable-sized block of CP210X_ registers, identified by req.
> > + * Returns data into buf in native USB byte order.
> > + */
> > +static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req,
> > +		void *buf, int bufsize)
> > +{
> > +	struct usb_serial *serial = port->serial;
> > +	struct cp210x_port_private *port_priv =
> usb_get_serial_port_data(port);
> > +	void *dmabuf;
> > +	int result;
> > +
> > +	dmabuf = kmalloc(bufsize, GFP_KERNEL);
> > +	if (!dmabuf) {
> > +		/*
> > +		 * FIXME Some callers don't bother to check for error,
> > +		 * at least give them consistent junk until they are fixed
> > +		 */
> > +		memset(buf, 0, bufsize);
> 
> Instead of adding these FIXMEs and possibly risk introducing regressions
> (these functions used to leave the previous values unchanged on errors),

The current cp210x_get_config() does clear the caller's storage on an error. So my refactoring just preserves the old behavior.

> how about adding the missing error handling first?

It's easier to work with and see bugs in cleaned up code, that's why I do it in this order.
I do intend to fix the error handling later.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 1/4 RESEND] USB: serial: cp210x: New register access functions. Konstantin Shkolnyy <konstantin.shkolnyy@gmail.com> - 2016-01-16 20:50 +0100
  Re: [PATCH v3 1/4 RESEND] USB: serial: cp210x: New register access  functions. Johan Hovold <johan@kernel.org> - 2016-01-18 18:40 +0100
    RE: [PATCH v3 1/4 RESEND] USB: serial: cp210x: New register access  functions. Konstantin Shkolnyy <Konstantin.Shkolnyy@silabs.com> - 2016-01-18 21:10 +0100
      Re: [PATCH v3 1/4 RESEND] USB: serial: cp210x: New register access  functions. Johan Hovold <johan@kernel.org> - 2016-01-18 21:10 +0100

csiph-web