linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Josh Boyer <jwboyer@fedoraproject.org>
Cc: Jiri Kosina <jikos@kernel.org>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] HID: lenovo: Don't use stack variables for DMA buffers
Date: Tue, 29 Mar 2016 08:50:27 +0200	[thread overview]
Message-ID: <20160329065027.GA20424@mail.corp.redhat.com> (raw)
In-Reply-To: <1459171334-22943-2-git-send-email-jwboyer@fedoraproject.org>

On Mar 28 2016 or thereabouts, Josh Boyer wrote:
> The lenovo_send_cmd_cptkbd function uses a stack variable to submit
> commands via hid_hw_raw_request.  Eventually this gets to the
> usb_hcd_map_urb_for_dma function, which causes a warning to be thrown
> if the CONFIG_DMA_API_DEBUG option is enabled.
> 
> Fix this by allocating a temporary buffer instead.
> 
> Reported-by: lejeczek <peljasz@yahoo.co.uk>
> Signed-off-by: Josh Boyer <jwboyer@fedoraproject.org>
> ---

The patch is
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

There is just one nitpick that can be solved while committing (or not,
depending on how Jiri handles it :-P ).

>  drivers/hid/hid-lenovo.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c
> index 0125e356bd8d..2ba5e8ea66a4 100644
> --- a/drivers/hid/hid-lenovo.c
> +++ b/drivers/hid/hid-lenovo.c
> @@ -184,21 +184,31 @@ static int lenovo_send_cmd_cptkbd(struct hid_device *hdev,
>  			unsigned char byte2, unsigned char byte3)
>  {
>  	int ret;
> -	unsigned char buf[] = {0x18, byte2, byte3};
> +	unsigned char *buf = NULL;

No need to initialized buf here :)

Cheers,
Benjamin

> +
> +	buf = kzalloc(3, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
> +	buf[0] = 0x18;
> +	buf[1] = byte2;
> +	buf[2] = byte3;
>  
>  	switch (hdev->product) {
>  	case USB_DEVICE_ID_LENOVO_CUSBKBD:
> -		ret = hid_hw_raw_request(hdev, 0x13, buf, sizeof(buf),
> +		ret = hid_hw_raw_request(hdev, 0x13, buf, 3,
>  					HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
>  		break;
>  	case USB_DEVICE_ID_LENOVO_CBTKBD:
> -		ret = hid_hw_output_report(hdev, buf, sizeof(buf));
> +		ret = hid_hw_output_report(hdev, buf, 3);
>  		break;
>  	default:
>  		ret = -EINVAL;
>  		break;
>  	}
>  
> +	kfree(buf);
> +
>  	return ret < 0 ? ret : 0; /* BT returns 0, USB returns sizeof(buf) */
>  }
>  
> -- 
> 2.5.5
> 

  reply	other threads:[~2016-03-29  6:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-28 13:22 [PATCH 0/1] Fix DMA_API_DEBUG warning in hid-lenovo Josh Boyer
2016-03-28 13:22 ` [PATCH] HID: lenovo: Don't use stack variables for DMA buffers Josh Boyer
2016-03-29  6:50   ` Benjamin Tissoires [this message]
2016-03-29 13:40     ` Jiri Kosina

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=20160329065027.GA20424@mail.corp.redhat.com \
    --to=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=jwboyer@fedoraproject.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@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).