diff mbox series

usb: hcd: add a flag for whether using shared_hcd priv

Message ID 1649299514-64014-1-git-send-email-quic_wat@quicinc.com
State New
Headers show
Series usb: hcd: add a flag for whether using shared_hcd priv | expand

Commit Message

Tao Wang April 7, 2022, 2:45 a.m. UTC
The shared_hcd->hcd_priv is not used in xhci, so not
need to malloc hcd priv memory for shared_hcd.

This change add a shared_hcd_no_priv flag to indicate
if shared_hcd use priv, and set the flag of xhci to 1.

Signed-off-by: Tao Wang <quic_wat@quicinc.com>
---
 drivers/usb/core/hcd.c       | 6 +++++-
 drivers/usb/host/xhci-plat.c | 1 +
 include/linux/usb/hcd.h      | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)

Comments

Greg Kroah-Hartman April 21, 2022, 4:48 p.m. UTC | #1
On Thu, Apr 07, 2022 at 10:45:14AM +0800, Tao Wang wrote:
> The shared_hcd->hcd_priv is not used in xhci, so not
> need to malloc hcd priv memory for shared_hcd.

What is the problem with allocating that memory?  Do you have systems
with thousands of USB host controllers where this memory is wasted?

> This change add a shared_hcd_no_priv flag to indicate
> if shared_hcd use priv, and set the flag of xhci to 1.

1 is not a boolean :(

> 
> Signed-off-by: Tao Wang <quic_wat@quicinc.com>
> ---
>  drivers/usb/core/hcd.c       | 6 +++++-
>  drivers/usb/host/xhci-plat.c | 1 +
>  include/linux/usb/hcd.h      | 1 +
>  3 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 99908d8..f339c3e 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -2419,7 +2419,11 @@ struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver,
>  {
>  	struct usb_hcd *hcd;
>  
> -	hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL);
> +	if (primary_hcd && driver->shared_hcd_no_priv)
> +		hcd = kzalloc(sizeof(*hcd), GFP_KERNEL);
> +	else
> +		hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL);
> +
>  	if (!hcd)
>  		return NULL;
>  	if (primary_hcd == NULL) {
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index 21280a6..223e508 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -236,6 +236,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
>  		return -ENODEV;
>  
>  	driver = &xhci_plat_hc_driver;
> +	driver->shared_hcd_no_priv = 1;

true?

>  
>  	irq = platform_get_irq(pdev, 0);
>  	if (irq < 0)
> diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
> index 2ffafbd..03ac312 100644
> --- a/include/linux/usb/hcd.h
> +++ b/include/linux/usb/hcd.h
> @@ -256,6 +256,7 @@ struct hc_driver {
>  	const char	*description;	/* "ehci-hcd" etc */
>  	const char	*product_desc;	/* product/vendor string */
>  	size_t		hcd_priv_size;	/* size of private data */
> +	bool		shared_hcd_no_priv;	/* 0 use priv, 1 not use priv*/

Did you check to see how much extra padding you just added to the
structure?  When writing a change to try to save memory, do not cause
extra memory to be wasted for everyone.

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 99908d8..f339c3e 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2419,7 +2419,11 @@  struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver,
 {
 	struct usb_hcd *hcd;
 
-	hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL);
+	if (primary_hcd && driver->shared_hcd_no_priv)
+		hcd = kzalloc(sizeof(*hcd), GFP_KERNEL);
+	else
+		hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL);
+
 	if (!hcd)
 		return NULL;
 	if (primary_hcd == NULL) {
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 21280a6..223e508 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -236,6 +236,7 @@  static int xhci_plat_probe(struct platform_device *pdev)
 		return -ENODEV;
 
 	driver = &xhci_plat_hc_driver;
+	driver->shared_hcd_no_priv = 1;
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 2ffafbd..03ac312 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -256,6 +256,7 @@  struct hc_driver {
 	const char	*description;	/* "ehci-hcd" etc */
 	const char	*product_desc;	/* product/vendor string */
 	size_t		hcd_priv_size;	/* size of private data */
+	bool		shared_hcd_no_priv;	/* 0 use priv, 1 not use priv*/
 
 	/* irq handler */
 	irqreturn_t	(*irq) (struct usb_hcd *hcd);