All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hongren Zheng <i@zenithal.me>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Valentina Manea <valentina.manea.m@gmail.com>,
	Shuah Khan <shuah@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	sfr@canb.auug.org.au
Subject: Re: [PATCH v2 1/1] usbip: Use platform_device_register_full()
Date: Fri, 13 Oct 2023 17:56:54 +0800	[thread overview]
Message-ID: <ZSkUZpMhiwweSPX5@Sun> (raw)
In-Reply-To: <20231006164312.3528524-1-andriy.shevchenko@linux.intel.com>

On Fri, Oct 06, 2023 at 07:43:12PM +0300, Andy Shevchenko wrote:
> The code to create the child platform device is essentially the same as
> what platform_device_register_full() does, so change over to use
> that same function to reduce duplication.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: (hopefully) fixed run-time NULL-dereference (LKP)
>  drivers/usb/usbip/vhci_hcd.c | 55 +++++++++++++-----------------------
>  1 file changed, 20 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
> index 37d1fc34e8a5..f845b91848b9 100644
> --- a/drivers/usb/usbip/vhci_hcd.c
> +++ b/drivers/usb/usbip/vhci_hcd.c
  
> -	for (i = 0; i < vhci_num_controllers; i++) {
> -		void *vhci = &vhcis[i];

The void *vhci here is intended

platform_device_add_data "Add a copy of platform specific data to the
platform device's platform_data pointer"

however, vhcis is static so it is not intended to be copied (the
pdev inside struct vhci might be the cause)

> -		ret = platform_device_add_data(vhcis[i].pdev, &vhci, sizeof(void *));
> -		if (ret)
> -			goto err_driver_register;
> -	}
> -
>  	ret = platform_driver_register(&vhci_driver);
>  	if (ret)
>  		goto err_driver_register;
>  
>  	for (i = 0; i < vhci_num_controllers; i++) {
> -		ret = platform_device_add(vhcis[i].pdev);
> +		struct platform_device_info pdevinfo = {
> +			.name = driver_name,
> +			.id = i,
> +			.data = &vhcis[i],

here should be a &vhci

> +			.size_data = sizeof(void *),
> +		};
> +
> +		vhcis[i].pdev = platform_device_register_full(&pdevinfo);
> +		ret = PTR_ERR_OR_ZERO(vhcis[i].pdev);
>  }
> -- 
> 2.40.0.1.gaa8946217a0b

I have reproduced the boot error reported by syzbot in
https://lore.kernel.org/linux-usb/00000000000029242706077f3145@google.com/
https://lore.kernel.org/linux-usb/0000000000007634c1060793197c@google.com/

and adding back void *vhci fixed it

I'll send a patch.

      parent reply	other threads:[~2023-10-13  9:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-06 16:43 [PATCH v2 1/1] usbip: Use platform_device_register_full() Andy Shevchenko
2023-10-06 19:43 ` Shuah Khan
2023-10-13  9:56 ` Hongren Zheng [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=ZSkUZpMhiwweSPX5@Sun \
    --to=i@zenithal.me \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    --cc=shuah@kernel.org \
    --cc=valentina.manea.m@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.