linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Johan Hovold <johan@kernel.org>
Cc: linux-usb@vger.kernel.org, stable <stable@vger.kernel.org>
Subject: Re: [PATCH 5/5] USB: serial: quatech2: handle unbound ports
Date: Fri, 17 Jan 2020 11:36:39 +0100	[thread overview]
Message-ID: <20200117103639.GA1835567@kroah.com> (raw)
In-Reply-To: <20200117095026.27655-6-johan@kernel.org>

On Fri, Jan 17, 2020 at 10:50:26AM +0100, Johan Hovold wrote:
> Check for NULL port data in the event handlers to avoid dereferencing a
> NULL pointer in the unlikely case where a port device isn't bound to a
> driver (e.g. after an allocation failure on port probe).
> 
> Fixes: f7a33e608d9a ("USB: serial: add quatech2 usb to serial driver")
> Cc: stable <stable@vger.kernel.org>     # 3.5
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/serial/quatech2.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c
> index a62981ca7a73..c76a2c0c32ff 100644
> --- a/drivers/usb/serial/quatech2.c
> +++ b/drivers/usb/serial/quatech2.c
> @@ -470,6 +470,13 @@ static int get_serial_info(struct tty_struct *tty,
>  
>  static void qt2_process_status(struct usb_serial_port *port, unsigned char *ch)
>  {
> +	struct qt2_port_private *port_priv;
> +
> +	/* May be called from qt2_process_read_urb() for an unbound port. */
> +	port_priv = usb_get_serial_port_data(port);
> +	if (!port_priv)
> +		return;
> +

Where is the null dereference here?  Will port be NULL somehow?

>  	switch (*ch) {
>  	case QT2_LINE_STATUS:
>  		qt2_update_lsr(port, ch + 1);
> @@ -484,14 +491,27 @@ static void qt2_process_status(struct usb_serial_port *port, unsigned char *ch)
>  static void qt2_process_xmit_empty(struct usb_serial_port *port,
>  				   unsigned char *ch)
>  {
> +	struct qt2_port_private *port_priv;
>  	int bytes_written;
>  
> +	/* May be called from qt2_process_read_urb() for an unbound port. */
> +	port_priv = usb_get_serial_port_data(port);
> +	if (!port_priv)
> +		return;
> +
>  	bytes_written = (int)(*ch) + (int)(*(ch + 1) << 4);

What's the harm in doing a pointless calculation here?  Nothing seems to
happen in this function at all.

>  }
>  
>  /* not needed, kept to document functionality */
>  static void qt2_process_flush(struct usb_serial_port *port, unsigned char *ch)
>  {
> +	struct qt2_port_private *port_priv;
> +
> +	/* May be called from qt2_process_read_urb() for an unbound port. */
> +	port_priv = usb_get_serial_port_data(port);
> +	if (!port_priv)
> +		return;
> +
>  	return;
>  }

This whole function can just be removed, right?

thanks,

greg k-h

  reply	other threads:[~2020-01-17 10:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-17  9:50 [PATCH 0/5] USB: serial: handle unbound ports Johan Hovold
2020-01-17  9:50 ` [PATCH 1/5] USB: ch341: handle unbound port at reset_resume Johan Hovold
2020-01-17  9:50 ` [PATCH 2/5] USB: serial: io_edgeport: handle unbound ports on URB completion Johan Hovold
2020-01-17  9:50 ` [PATCH 3/5] USB: serial: io_edgeport: add missing active-port sanity check Johan Hovold
2020-01-17  9:50 ` [PATCH 4/5] USB: serial: keyspan: handle unbound ports Johan Hovold
2020-01-17  9:50 ` [PATCH 5/5] USB: serial: quatech2: " Johan Hovold
2020-01-17 10:36   ` Greg KH [this message]
2020-01-17 10:53     ` Johan Hovold
2020-01-17 13:13       ` Greg KH
2020-01-17 14:29         ` Johan Hovold
2020-01-17 13:13 ` [PATCH 0/5] USB: serial: " Greg KH

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=20200117103639.GA1835567@kroah.com \
    --to=greg@kroah.com \
    --cc=johan@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).