public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Johan Hovold <johan@kernel.org>
Cc: Pete Zaitcev <zaitcev@redhat.com>,
	linux-usb@vger.kernel.org,
	Dan Carpenter <dan.carpenter@oracle.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH] USB: usblp: fix DMA to stack
Date: Mon, 4 Jan 2021 15:59:02 +0100	[thread overview]
Message-ID: <X/MtNtTd96S39HQL@kroah.com> (raw)
In-Reply-To: <20210104145302.2087-1-johan@kernel.org>

On Mon, Jan 04, 2021 at 03:53:02PM +0100, Johan Hovold wrote:
> Stack-allocated buffers cannot be used for DMA (on all architectures).
> 
> Replace the HP-channel macro with a helper function that allocates a
> dedicated transfer buffer so that it can continue to be used with
> arguments from the stack.
> 
> Note that the buffer is cleared on allocation as usblp_ctrl_msg()
> returns success also on short transfers (the buffer is only used for
> debugging).
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/class/usblp.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
> index 67cbd42421be..134dc2005ce9 100644
> --- a/drivers/usb/class/usblp.c
> +++ b/drivers/usb/class/usblp.c
> @@ -274,8 +274,25 @@ static int usblp_ctrl_msg(struct usblp *usblp, int request, int type, int dir, i
>  #define usblp_reset(usblp)\
>  	usblp_ctrl_msg(usblp, USBLP_REQ_RESET, USB_TYPE_CLASS, USB_DIR_OUT, USB_RECIP_OTHER, 0, NULL, 0)
>  
> -#define usblp_hp_channel_change_request(usblp, channel, buffer) \
> -	usblp_ctrl_msg(usblp, USBLP_REQ_HP_CHANNEL_CHANGE_REQUEST, USB_TYPE_VENDOR, USB_DIR_IN, USB_RECIP_INTERFACE, channel, buffer, 1)
> +static int usblp_hp_channel_change_request(struct usblp *usblp, int channel, u8 *new_channel)
> +{
> +	u8 *buf;
> +	int ret;
> +
> +	buf = kzalloc(1, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
> +	ret = usblp_ctrl_msg(usblp, USBLP_REQ_HP_CHANNEL_CHANGE_REQUEST,
> +			USB_TYPE_VENDOR, USB_DIR_IN, USB_RECIP_INTERFACE,
> +			channel, buf, 1);
> +	if (ret == 0)
> +		*new_channel = buf[0];
> +
> +	kfree(buf);
> +
> +	return ret;
> +}

Wow, no one uses this driver anymore it seems, this should have
triggered a runtime warning on newer kernels :(

Thanks for this, will queue it up soon.

greg k-h

  reply	other threads:[~2021-01-04 14:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-04 14:53 [PATCH] USB: usblp: fix DMA to stack Johan Hovold
2021-01-04 14:59 ` Greg Kroah-Hartman [this message]
2021-01-04 15:11   ` Johan Hovold
2021-01-04 15:33     ` Michael Sweet
2021-01-04 15:48       ` Johan Hovold
2021-01-04 17:37 ` Pete Zaitcev
2021-01-06 11:25   ` 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=X/MtNtTd96S39HQL@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=dan.carpenter@oracle.com \
    --cc=johan@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zaitcev@redhat.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