Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp330850ybz; Wed, 29 Apr 2020 00:42:16 -0700 (PDT) X-Google-Smtp-Source: APiQypJ+CsviD9h4XVrwESHhC946y1w2r9OjU68JJ9OA2t+XCbiwD8x2JI2PDmozSrU+YLEtJ+Ev X-Received: by 2002:a50:d6d0:: with SMTP id l16mr1296982edj.317.1588146136596; Wed, 29 Apr 2020 00:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588146136; cv=none; d=google.com; s=arc-20160816; b=YYc8oyW1aVqagGz3MZ2vtWCDkfGSHI5gTai8q4OX5jkVvfJX85s54UhqBNJw9qDjld hMHu+JYFAx9rfuTp+fmsGd7Nzy02yUiUPDL2G8vgESCdzgccm13Z0sWSqRynTa6Kj2CD G0OCq9/37ci7EubJCWzyf7lQxK70FGgw5m2AyqiGsIkQK9jUwR26LqdnhTDC5P5pvuG6 H3VabuDK3ykgFOBiMUfgFjCZ6CZzQNn31KleLkdEGWuZsxazTkM4Ds3W4KnSw2MdixHp 3+juxwJd3+zApotlhiASddgBAuZl5CEULDd9XrbF4iPcMEYMUInGPOviQJYUXY6DMMgz 3aSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BkwTPzqqKXlCRnFSUPBwWSXSOFIJIPOU6VXaUHdfxig=; b=IPOHKOGGan2EGzRqtzwZAvWmO6ur0Wcji3GtnVbNjKRY21rNJaqlXcIWk7w4xJ9QW0 xrmDSwijbm3qJ0pR9P5lZPRPammhxWGsD452nsoyLCLUoo7BmlNvJRM39GOrW/8LY4Bm 6g48s0QrhJdvfZuXy7x2599DXLU/NBnJC6pY17sUANjP+0aQ+2fklvTIsdCQFfvt9vlE sQiFDkfysYd3aSeOc7cLNFIpI1RWAZeU2lwPA2BLILJik8HwoaQdlVSSg2sRtlwBskct hWHUsBQxI2poF3sbYsJVq1LR1IWK2JE56eEkGxEMMrWVGXiaJ6HCapVeCqndvYOUxBIw dtew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aOWD4Hla; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q10si3238505eju.123.2020.04.29.00.41.53; Wed, 29 Apr 2020 00:42:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aOWD4Hla; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726447AbgD2Hkg (ORCPT + 99 others); Wed, 29 Apr 2020 03:40:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:43846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726355AbgD2Hkf (ORCPT ); Wed, 29 Apr 2020 03:40:35 -0400 Received: from Mani-XPS-13-9360 (unknown [157.46.25.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F1AA42073E; Wed, 29 Apr 2020 07:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588146034; bh=vT0nc6JP1XAbhEu/xWlWApVMT/AgweeuCYtCLOPZvik=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aOWD4Hlawou5o0CTYK8q0icBT7hswPxiDZC3nVwT0Jo9Xd8Z2M8CP1kLZhS2/9AVs bYPgaHHY6+OCUhAEhO5SpvHoLtuS0cpNVRwQMuDPQAAGlomZT+ZrVwmx2zeW/+MCz5 qHQZTI8CawBO30E2PgMwf+HahaIU0UyIRIAD20e4= Date: Wed, 29 Apr 2020 13:10:26 +0530 From: Manivannan Sadhasivam To: Greg KH 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 Message-ID: <20200429074025.GA6443@Mani-XPS-13-9360> References: <20200428195651.6793-1-mani@kernel.org> <20200428195651.6793-2-mani@kernel.org> <20200429072036.GA2045202@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200429072036.GA2045202@kroah.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > > > 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 > > + * > > + * Copyright (c) 2020 Manivannan Sadhasivam > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#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. > > +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. But agree, I should've used le16_to_cpu() cast to avoid endian issues. If you think this hack is not required now, I can just use u8 and worry about compatibility later. > > --- /dev/null > > +++ b/drivers/usb/serial/xr_serial.h > > @@ -0,0 +1,103 @@ > > +/* SPDX-License-Identifier: GPL-2.0+ */ > > Are you sure about the "+"? I have to ask :) > I'm not a fan but since I've inherited the code from initial driver (which was GPL-2.0+), I kept it. > > + > > +#ifndef __LINUX_USB_SERIAL_XR_SERIAL_H > > +#define __LINUX_USB_SERIAL_XR_SERIAL_H > > As you will drop this file, just a general statement, no need for > __LINUX as this is all Linux :) > Sure. Thanks, Mani > thanks, > > greg k-h