From: Manivannan Sadhasivam <mani@kernel.org>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: johan@kernel.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, patong.mxl@gmail.com
Subject: Re: [PATCH 1/2] usb: serial: Add MaxLinear/Exar USB to Serial driver
Date: Wed, 29 Apr 2020 18:31:26 +0530 [thread overview]
Message-ID: <20200429130126.GD6443@Mani-XPS-13-9360> (raw)
In-Reply-To: <20200429092904.GA2079263@kroah.com>
On Wed, Apr 29, 2020 at 11:29:04AM +0200, Greg KH wrote:
> On Wed, Apr 29, 2020 at 01:10:26PM +0530, Manivannan Sadhasivam wrote:
> > Hi Greg,
> >
> > On Wed, Apr 29, 2020 at 09:20:36AM +0200, Greg KH wrote:
> > > On Wed, Apr 29, 2020 at 01:26:50AM +0530, mani@kernel.org wrote:
> > > > From: Manivannan Sadhasivam <mani@kernel.org>
> > > >
> > > > Add support for MaxLinear/Exar USB to Serial converters. This driver
> > > > only supports XR21V141X series but provision has been made to support
> > > > other series in future.
> > > >
> > > > This driver is inspired from the initial one submitted by Patong Yang:
> > > >
> > > > https://patchwork.kernel.org/patch/10543261/
> > > >
> > > > While the initial driver was a custom tty USB driver exposing whole
> > > > new serial interface ttyXRUSBn, this version is completely based on USB
> > > > serial core thus exposing the interfaces as ttyUSBn. This will avoid
> > > > the overhead of exposing a new USB serial interface which the userspace
> > > > tools are unaware of.
> > >
> > > Nice work!
> > >
> > > Some comments below:
> > >
> > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > +/*
> > > > + * MaxLinear/Exar USB to Serial driver
> > > > + *
> > > > + * Based on initial driver written by Patong Yang <patong.mxl@gmail.com>
> > > > + *
> > > > + * Copyright (c) 2020 Manivannan Sadhasivam <mani@kernel.org>
> > > > + */
> > > > +
> > > > +#include <linux/kernel.h>
> > > > +#include <linux/module.h>
> > > > +#include <linux/slab.h>
> > > > +#include <linux/tty.h>
> > > > +#include <linux/usb.h>
> > > > +#include <linux/usb/serial.h>
> > > > +
> > > > +#include "xr_serial.h"
> > >
> > > No need for a .h file for a single .c file.
> > >
> >
> > Yeah but since this driver can support multiple series of XR chips (they
> > might have separate register definitions and such), I thought it is a good
> > idea to have a header file to keep the driver sane. But can club it to the
> > source file for now.
>
> Don't worry about future stuff, focus on what you need to do now :)
>
Alright, will do :)
> > > > +static int xr_get_reg(struct usb_serial_port *port, u8 block, u16 reg,
> > > > + u16 *val)
> > > > +{
> > > > + struct usb_serial *serial = port->serial;
> > > > + struct xr_port_private *port_priv = usb_get_serial_port_data(port);
> > > > + void *dmabuf;
> > > > + int ret = -EINVAL;
> > > > +
> > > > + dmabuf = kmalloc(sizeof(reg), GFP_KERNEL);
> > >
> > > So that is 2 bytes?
> > >
> >
> > Explanation below...
> >
> > > > + if (!dmabuf)
> > > > + return -ENOMEM;
> > > > +
> > > > + if (port_priv->idProduct == XR21V141X_ID) {
> > > > + /* XR21V141X uses custom command for reading UART registers */
> > > > + ret = usb_control_msg(serial->dev,
> > > > + usb_rcvctrlpipe(serial->dev, 0),
> > > > + XR_GET_XR21V141X,
> > > > + USB_DIR_IN | USB_TYPE_VENDOR, 0,
> > > > + reg | (block << 8), dmabuf,
> > > > + port_priv->reg_width,
> > > > + USB_CTRL_SET_TIMEOUT);
> > > > + }
> > > > +
> > > > + if (ret == port_priv->reg_width) {
> > > > + memcpy(val, dmabuf, port_priv->reg_width);
> > >
> > > But here you copy ->reg_width bytes in? How do you know val can hold
> > > that much? It's only set to be 1, so you copy 1 byte to a 16bit value?
> > > What part of the 16bits did you just copy those 8 bits to (hint, think
> > > cpu endian issues...)
> > >
> > > That feels really really odd and a bit broken.
> > >
> >
> > Right. The reason is, the other series which can be supported by this driver
> > have different register widths. For instance XR2280x. I haven't used them
> > personally but seen this in initial driver. So I just used the max u16 type
> > to make the reg_{set/get} routines work with those.
>
> Drop the whole "different register width" stuff for now, as the driver
> does not support it and it adds additional complexity that is hard to
> review for no good reason. If you want to add support for new devices
> later, _then_ we can add support for that.
>
> Don't over-engineer :)
>
Sure!
> > But agree, I should've used le16_to_cpu() cast to avoid endian issues.
>
> You have to, the code is broken as-is right now.
>
We don't need the conversion if u8 is used everywhere :)
Thanks,
Mani
> > If you think this hack is not required now, I can just use u8 and worry about
> > compatibility later.
>
> Please do so.
>
> thanks,
>
> greg k-h
next prev parent reply other threads:[~2020-04-29 13:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-28 19:56 [PATCH 0/2] Add support for MaxLinear/Exar USB to serial converters mani
2020-04-28 19:56 ` [PATCH 1/2] usb: serial: Add MaxLinear/Exar USB to Serial driver mani
2020-04-29 7:20 ` Greg KH
2020-04-29 7:40 ` Manivannan Sadhasivam
2020-04-29 9:29 ` Greg KH
2020-04-29 13:01 ` Manivannan Sadhasivam [this message]
2020-04-28 19:56 ` [PATCH 2/2] usb: serial: xr_serial: Add gpiochip support mani
2020-04-29 12:12 ` Linus Walleij
2020-04-29 12:49 ` Manivannan Sadhasivam
2020-05-19 8:57 ` Johan Hovold
2020-05-25 8:59 ` Linus Walleij
2020-05-25 11:12 ` Greg KH
2020-05-25 13:02 ` Linus Walleij
2020-05-25 13:35 ` Greg KH
2020-04-29 17:47 ` Manivannan Sadhasivam
2020-04-29 17:59 ` Greg KH
2020-05-19 9:08 ` Johan Hovold
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=20200429130126.GD6443@Mani-XPS-13-9360 \
--to=mani@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=patong.mxl@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