public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Konstantin Aladyshev <aladyshev22@gmail.com>
Cc: benjamin.tissoires@redhat.com, ivan.orlov0322@gmail.com,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	john@keeping.me.uk, lee@kernel.org
Subject: Re: [PATCH 1/1] usb: gadget: f_hid: fix report descriptor allocation
Date: Wed, 6 Dec 2023 02:33:58 +0900	[thread overview]
Message-ID: <2023120650-scroll-studio-1083@gregkh> (raw)
In-Reply-To: <20231205085404.175-2-aladyshev22@gmail.com>

On Tue, Dec 05, 2023 at 11:54:03AM +0300, Konstantin Aladyshev wrote:
> The commit "usb: gadget: f_hid: fix f_hidg lifetime vs cdev"
> (89ff3dfac604614287ad5aad9370c3f984ea3f4b) has introduced a bug
> that leads to hid device corruption after the replug operation.

Nit, this should be written as
	89ff3dfac604 ("usb: gadget: f_hid: fix f_hidg lifetime vs cdev")
right?

> Reverse device managed memory allocation for the report descriptor
> to fix the issue.
> 
> Tested:
> This change was tested on the AMD EthanolX CRB server with the BMC
> based on the OpenBMC distribution. The BMC provides KVM functionality
> via the USB gadget device:
> - before: KVM page refresh results in a broken USB device,
> - after: KVM page refresh works without any issues.
> 
> Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>

We need a Fixes: tag here and also a cc: stable so that this gets
properly backported.

> ---
>  drivers/usb/gadget/function/f_hid.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
> index ea85e2c701a1..3c8a9dd585c0 100644
> --- a/drivers/usb/gadget/function/f_hid.c
> +++ b/drivers/usb/gadget/function/f_hid.c
> @@ -92,6 +92,7 @@ static void hidg_release(struct device *dev)
>  {
>  	struct f_hidg *hidg = container_of(dev, struct f_hidg, dev);
>  
> +	kfree(hidg->report_desc);
>  	kfree(hidg->set_report_buf);
>  	kfree(hidg);
>  }
> @@ -1287,9 +1288,9 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
>  	hidg->report_length = opts->report_length;
>  	hidg->report_desc_length = opts->report_desc_length;
>  	if (opts->report_desc) {
> -		hidg->report_desc = devm_kmemdup(&hidg->dev, opts->report_desc,
> -						 opts->report_desc_length,
> -						 GFP_KERNEL);
> +		hidg->report_desc = kmemdup(opts->report_desc,
> +					    opts->report_desc_length,
> +					    GFP_KERNEL);

Yet one more reason why devm_*() functions are dangerous to use :(

Nice fix.

thanks,

greg k-h

      reply	other threads:[~2023-12-05 17:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05  8:54 [PATCH 0/1] usb: gadget: f_hid: fix report descriptor allocation Konstantin Aladyshev
2023-12-05  8:54 ` [PATCH 1/1] " Konstantin Aladyshev
2023-12-05 17:33   ` Greg KH [this message]

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=2023120650-scroll-studio-1083@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=aladyshev22@gmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=ivan.orlov0322@gmail.com \
    --cc=john@keeping.me.uk \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@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