Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp673062pxu; Wed, 14 Oct 2020 10:41:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA4j16EcoWAyLMkgQbkkeBjzvfGf0j6ECXpf9WH+U5hodDaPN9LPEOKcEyTBwsJRTZLgm4 X-Received: by 2002:a17:906:dbf7:: with SMTP id yd23mr126914ejb.281.1602697265799; Wed, 14 Oct 2020 10:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602697265; cv=none; d=google.com; s=arc-20160816; b=Eu9BOSWC2btxiQejrwyEJziXsBL22lhOiqChK20CwYR2lvZ6uNpr3T9zTGmPHhsEDY 8aUgyLCZqywiS9P9VS2WsGMTXyvjPnXBANWU/3z3fZvP2ZGnYBJuTbmIs+9Kx+aMZA9y IrRQbdCeSWwdDrxU4q5uopQvrBAPPNKHKLbQ1Y3eD8YQGVo5PshOroLsHdT0RLsXdB28 kDB6DtZWwW4yeZ1M6CBP2CJrofvyVFCouazhfs8frV28SXgzliyWWPxeqLEEKgrKNucs YvVSqhetRxkRscLt6MenGN75ZiO+wuJzrtDhtMOu3QAeBft34KbERCr5VoRQcS4qgHxB bR8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=IzXk7jT3zg7fulGGoz23SNTr+tGM/pUzNSuaAKCSgXI=; b=y5mNYqO9lrD/WwhvSg02UQcXfkqmnY/D8Fk9n5flxmcrbm4MUJt30CT/zS9FpR0+eq xYBCQrSpUxYNaV0zeuA1+v2XZcelyvN3lCUDaDPg0KcltJgqtRAptitL633M3SXJAnt1 iiSbVFBOcgcc+EOrOWoTE6HCA4ksrfoUjXI1wj+AbUhdvX7F4KWTV1w10kA4gI6J+wmX L2Kr5fr8jMljzd8xZ7jYb8E5VyCUJ4DEdv4az8ufeBMfnPIKAkc83bHjebPAFLLl5O7F V7RV5PdmJPHSkbI9S/XylYqhgN58eSewhQZkLDWmGi94BEGRxkeih3ZsUO0rz36h1edn 3nFA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id wp8si237775ejb.752.2020.10.14.10.40.43; Wed, 14 Oct 2020 10:41:05 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387688AbgJNQOf (ORCPT + 99 others); Wed, 14 Oct 2020 12:14:35 -0400 Received: from netrider.rowland.org ([192.131.102.5]:54815 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1731832AbgJNQOe (ORCPT ); Wed, 14 Oct 2020 12:14:34 -0400 Received: (qmail 718746 invoked by uid 1000); 14 Oct 2020 12:14:33 -0400 Date: Wed, 14 Oct 2020 12:14:33 -0400 From: Alan Stern To: Thomas Gleixner Cc: LKML , Peter Zijlstra , Sebastian Andrzej Siewior , Johan Hovold , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Thomas Winischhofer , "Ahmed S. Darwish" , Mathias Nyman , Valentina Manea , Shuah Khan , linux-omap@vger.kernel.org, Kukjin Kim , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Felipe Balbi , Duncan Sands Subject: Re: [patch 03/12] USB: serial: keyspan_pda: Consolidate room query Message-ID: <20201014161433.GB712494@rowland.harvard.edu> References: <20201014145215.518912759@linutronix.de> <20201014145727.338773481@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201014145727.338773481@linutronix.de> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 14, 2020 at 04:52:18PM +0200, Thomas Gleixner wrote: > From: Sebastian Andrzej Siewior > > Having two copies of the same code doesn't make the code more readable and > allocating a buffer of 1 byte for a synchronous operation is a pointless > exercise. Not so. In fact, it is required, because a portion of a structure cannot be mapped for DMA unless it is aligned at a cache line boundary. > Add a byte buffer to struct keyspan_pda_private which can be used > instead. The buffer is only used in open() and tty->write(). This won't work. > Console writes > are not calling into the query. open() obviously happens before write() and > the writes are serialized by bit 0 of port->write_urbs_free which protects > also the transaction itself. > > Move the actual query into a helper function and cleanup the usage sites in > keyspan_pda_write() and keyspan_pda_open(). > > Signed-off-by: Sebastian Andrzej Siewior > Signed-off-by: Thomas Gleixner > Cc: Johan Hovold > Cc: Greg Kroah-Hartman > Cc: linux-usb@vger.kernel.org > --- > drivers/usb/serial/keyspan_pda.c | 102 ++++++++++++++++----------------------- > 1 file changed, 43 insertions(+), 59 deletions(-) > > --- a/drivers/usb/serial/keyspan_pda.c > +++ b/drivers/usb/serial/keyspan_pda.c > @@ -47,6 +47,7 @@ struct keyspan_pda_private { > struct work_struct unthrottle_work; > struct usb_serial *serial; > struct usb_serial_port *port; > + u8 query_buf; > }; > > > @@ -436,6 +437,31 @@ static int keyspan_pda_tiocmset(struct t > return rc; > } > > +/* > + * Using priv->query_buf is safe here because this is only called for TTY > + * operations open() and write(). write() comes post open() obviously and > + * write() itself is serialized via bit 0 of port->write_urbs_free. Console > + * writes are never calling into this. > + */ > +static int keyspan_pda_query_room(struct usb_serial *serial, > + struct keyspan_pda_private *priv) > +{ > + int res; > + > + res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), > + 6, /* write_room */ > + USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_IN, > + 0, /* value */ > + 0, /* index */ > + &priv->query_buf, > + 1, > + 2000); Instead, consider using the new usb_control_msg_recv() API. But it might be better to allocate the buffer once and for all. Alan Stern