diff mbox series

[21/24] usb: host: xhci: Move array of structs from the stack onto the heap

Message ID 20210526130037.856068-22-lee.jones@linaro.org (mailing list archive)
State New, archived
Headers show
Series Rid W=1 warnings from USB | expand

Commit Message

Lee Jones May 26, 2021, 1 p.m. UTC
Fixes the following W=1 kernel build warning(s):

 drivers/usb/host/xhci.c: In function ‘xhci_reserve_bandwidth’:
 drivers/usb/host/xhci.c:2859:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]

Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/usb/host/xhci.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Sergey Shtylyov May 26, 2021, 2:21 p.m. UTC | #1
On 5/26/21 4:00 PM, Lee Jones wrote:

> Fixes the following W=1 kernel build warning(s):
> 
>  drivers/usb/host/xhci.c: In function ‘xhci_reserve_bandwidth’:
>  drivers/usb/host/xhci.c:2859:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> 
> Cc: Mathias Nyman <mathias.nyman@intel.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: linux-usb@vger.kernel.org
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/usb/host/xhci.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> index ac2a7d4288883..40ce4b4eb12ad 100644
> --- a/drivers/usb/host/xhci.c
> +++ b/drivers/usb/host/xhci.c
[...]
> @@ -2788,6 +2788,10 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
>  		return -ENOMEM;
>  	}
>  
> +	ep_bw_info = kzalloc(sizeof(*ep_bw_info) * 31, GFP_KERNEL);

   Why not kcalloc()?

[...]

MBR, Sergei
Lee Jones May 26, 2021, 2:44 p.m. UTC | #2
On Wed, 26 May 2021, Sergei Shtylyov wrote:

> On 5/26/21 4:00 PM, Lee Jones wrote:
> 
> > Fixes the following W=1 kernel build warning(s):
> > 
> >  drivers/usb/host/xhci.c: In function ‘xhci_reserve_bandwidth’:
> >  drivers/usb/host/xhci.c:2859:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> > 
> > Cc: Mathias Nyman <mathias.nyman@intel.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: linux-usb@vger.kernel.org
> > Signed-off-by: Lee Jones <lee.jones@linaro.org>
> > ---
> >  drivers/usb/host/xhci.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> > index ac2a7d4288883..40ce4b4eb12ad 100644
> > --- a/drivers/usb/host/xhci.c
> > +++ b/drivers/usb/host/xhci.c
> [...]
> > @@ -2788,6 +2788,10 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
> >  		return -ENOMEM;
> >  	}
> >  
> > +	ep_bw_info = kzalloc(sizeof(*ep_bw_info) * 31, GFP_KERNEL);
> 
>    Why not kcalloc()?

No particular reason.  Muscle memory I guess.

Happy either way.
Sergey Shtylyov May 26, 2021, 2:59 p.m. UTC | #3
On 5/26/21 5:44 PM, Lee Jones wrote:

[...]
>>> Fixes the following W=1 kernel build warning(s):
>>>
>>>  drivers/usb/host/xhci.c: In function ‘xhci_reserve_bandwidth’:
>>>  drivers/usb/host/xhci.c:2859:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]
>>>
>>> Cc: Mathias Nyman <mathias.nyman@intel.com>
>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>> Cc: linux-usb@vger.kernel.org
>>> Signed-off-by: Lee Jones <lee.jones@linaro.org>
>>> ---
>>>  drivers/usb/host/xhci.c | 8 +++++++-
>>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
>>> index ac2a7d4288883..40ce4b4eb12ad 100644
>>> --- a/drivers/usb/host/xhci.c
>>> +++ b/drivers/usb/host/xhci.c
>> [...]
>>> @@ -2788,6 +2788,10 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
>>>  		return -ENOMEM;
>>>  	}
>>>  
>>> +	ep_bw_info = kzalloc(sizeof(*ep_bw_info) * 31, GFP_KERNEL);
>>
>>    Why not kcalloc()?
> 
> No particular reason.  Muscle memory I guess.
> 
> Happy either way.

    kcalloc( is designed for allocatiung arrays and clearing them, like calloc(),
so let's stick wuth it...

MBR, Sergei
Lee Jones May 26, 2021, 3:28 p.m. UTC | #4
On Wed, 26 May 2021, Sergei Shtylyov wrote:

> On 5/26/21 5:44 PM, Lee Jones wrote:
> 
> [...]
> >>> Fixes the following W=1 kernel build warning(s):
> >>>
> >>>  drivers/usb/host/xhci.c: In function ‘xhci_reserve_bandwidth’:
> >>>  drivers/usb/host/xhci.c:2859:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> >>>
> >>> Cc: Mathias Nyman <mathias.nyman@intel.com>
> >>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >>> Cc: linux-usb@vger.kernel.org
> >>> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> >>> ---
> >>>  drivers/usb/host/xhci.c | 8 +++++++-
> >>>  1 file changed, 7 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> >>> index ac2a7d4288883..40ce4b4eb12ad 100644
> >>> --- a/drivers/usb/host/xhci.c
> >>> +++ b/drivers/usb/host/xhci.c
> >> [...]
> >>> @@ -2788,6 +2788,10 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
> >>>  		return -ENOMEM;
> >>>  	}
> >>>  
> >>> +	ep_bw_info = kzalloc(sizeof(*ep_bw_info) * 31, GFP_KERNEL);
> >>
> >>    Why not kcalloc()?
> > 
> > No particular reason.  Muscle memory I guess.
> > 
> > Happy either way.
> 
>     kcalloc( is designed for allocatiung arrays and clearing them, like calloc(),
> so let's stick wuth it...

No problem.  Will fix.
Mathias Nyman May 27, 2021, 11:36 a.m. UTC | #5
On 26.5.2021 18.28, Lee Jones wrote:
> On Wed, 26 May 2021, Sergei Shtylyov wrote:
> 
>> On 5/26/21 5:44 PM, Lee Jones wrote:
>>
>> [...]
>>>>> Fixes the following W=1 kernel build warning(s):
>>>>>
>>>>>  drivers/usb/host/xhci.c: In function ‘xhci_reserve_bandwidth’:
>>>>>  drivers/usb/host/xhci.c:2859:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]
>>>>>
>>>>> Cc: Mathias Nyman <mathias.nyman@intel.com>
>>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>>>> Cc: linux-usb@vger.kernel.org
>>>>> Signed-off-by: Lee Jones <lee.jones@linaro.org>
>>>>> ---
>>>>>  drivers/usb/host/xhci.c | 8 +++++++-
>>>>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
>>>>> index ac2a7d4288883..40ce4b4eb12ad 100644
>>>>> --- a/drivers/usb/host/xhci.c
>>>>> +++ b/drivers/usb/host/xhci.c
>>>> [...]
>>>>> @@ -2788,6 +2788,10 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
>>>>>  		return -ENOMEM;
>>>>>  	}
>>>>>  
>>>>> +	ep_bw_info = kzalloc(sizeof(*ep_bw_info) * 31, GFP_KERNEL);

GFP_KERNEL might not be suitable for all cases.

xhci_reserve_bandwidth() is called from xhci_configure_endpoint(), which again
is called from a lot of places.
For example from xhci_update_hub_device() which can be called with GFP_NOIO mem_flags.

-Mathias
Lee Jones June 1, 2021, 9:25 a.m. UTC | #6
On Thu, 27 May 2021, Mathias Nyman wrote:

> On 26.5.2021 18.28, Lee Jones wrote:
> > On Wed, 26 May 2021, Sergei Shtylyov wrote:
> > 
> >> On 5/26/21 5:44 PM, Lee Jones wrote:
> >>
> >> [...]
> >>>>> Fixes the following W=1 kernel build warning(s):
> >>>>>
> >>>>>  drivers/usb/host/xhci.c: In function ‘xhci_reserve_bandwidth’:
> >>>>>  drivers/usb/host/xhci.c:2859:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> >>>>>
> >>>>> Cc: Mathias Nyman <mathias.nyman@intel.com>
> >>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >>>>> Cc: linux-usb@vger.kernel.org
> >>>>> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> >>>>> ---
> >>>>>  drivers/usb/host/xhci.c | 8 +++++++-
> >>>>>  1 file changed, 7 insertions(+), 1 deletion(-)
> >>>>>
> >>>>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> >>>>> index ac2a7d4288883..40ce4b4eb12ad 100644
> >>>>> --- a/drivers/usb/host/xhci.c
> >>>>> +++ b/drivers/usb/host/xhci.c
> >>>> [...]
> >>>>> @@ -2788,6 +2788,10 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
> >>>>>  		return -ENOMEM;
> >>>>>  	}
> >>>>>  
> >>>>> +	ep_bw_info = kzalloc(sizeof(*ep_bw_info) * 31, GFP_KERNEL);
> 
> GFP_KERNEL might not be suitable for all cases.
> 
> xhci_reserve_bandwidth() is called from xhci_configure_endpoint(), which again
> is called from a lot of places.
> For example from xhci_update_hub_device() which can be called with GFP_NOIO mem_flags.

What do you suggest as an alternative?
Lee Jones June 22, 2021, 10:47 a.m. UTC | #7
On Tue, 01 Jun 2021, Lee Jones wrote:

> On Thu, 27 May 2021, Mathias Nyman wrote:
> 
> > On 26.5.2021 18.28, Lee Jones wrote:
> > > On Wed, 26 May 2021, Sergei Shtylyov wrote:
> > > 
> > >> On 5/26/21 5:44 PM, Lee Jones wrote:
> > >>
> > >> [...]
> > >>>>> Fixes the following W=1 kernel build warning(s):
> > >>>>>
> > >>>>>  drivers/usb/host/xhci.c: In function ‘xhci_reserve_bandwidth’:
> > >>>>>  drivers/usb/host/xhci.c:2859:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> > >>>>>
> > >>>>> Cc: Mathias Nyman <mathias.nyman@intel.com>
> > >>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > >>>>> Cc: linux-usb@vger.kernel.org
> > >>>>> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> > >>>>> ---
> > >>>>>  drivers/usb/host/xhci.c | 8 +++++++-
> > >>>>>  1 file changed, 7 insertions(+), 1 deletion(-)
> > >>>>>
> > >>>>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> > >>>>> index ac2a7d4288883..40ce4b4eb12ad 100644
> > >>>>> --- a/drivers/usb/host/xhci.c
> > >>>>> +++ b/drivers/usb/host/xhci.c
> > >>>> [...]
> > >>>>> @@ -2788,6 +2788,10 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
> > >>>>>  		return -ENOMEM;
> > >>>>>  	}
> > >>>>>  
> > >>>>> +	ep_bw_info = kzalloc(sizeof(*ep_bw_info) * 31, GFP_KERNEL);
> > 
> > GFP_KERNEL might not be suitable for all cases.
> > 
> > xhci_reserve_bandwidth() is called from xhci_configure_endpoint(), which again
> > is called from a lot of places.
> > For example from xhci_update_hub_device() which can be called with GFP_NOIO mem_flags.
> 
> What do you suggest as an alternative?

Just working on rectifying this now.

Which Get Free Page flag do you suggest here please?
Mathias Nyman June 22, 2021, 11:32 a.m. UTC | #8
On 22.6.2021 13.47, Lee Jones wrote:
> On Tue, 01 Jun 2021, Lee Jones wrote:
> 
>> On Thu, 27 May 2021, Mathias Nyman wrote:
>>
>>> On 26.5.2021 18.28, Lee Jones wrote:
>>>> On Wed, 26 May 2021, Sergei Shtylyov wrote:
>>>>
>>>>> On 5/26/21 5:44 PM, Lee Jones wrote:
>>>>>
>>>>> [...]
>>>>>>>> Fixes the following W=1 kernel build warning(s):
>>>>>>>>
>>>>>>>>  drivers/usb/host/xhci.c: In function ‘xhci_reserve_bandwidth’:
>>>>>>>>  drivers/usb/host/xhci.c:2859:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]
>>>>>>>>
>>>>>>>> Cc: Mathias Nyman <mathias.nyman@intel.com>
>>>>>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>>>>>>> Cc: linux-usb@vger.kernel.org
>>>>>>>> Signed-off-by: Lee Jones <lee.jones@linaro.org>
>>>>>>>> ---
>>>>>>>>  drivers/usb/host/xhci.c | 8 +++++++-
>>>>>>>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>>>>>>>
>>>>>>>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
>>>>>>>> index ac2a7d4288883..40ce4b4eb12ad 100644
>>>>>>>> --- a/drivers/usb/host/xhci.c
>>>>>>>> +++ b/drivers/usb/host/xhci.c
>>>>>>> [...]
>>>>>>>> @@ -2788,6 +2788,10 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
>>>>>>>>  		return -ENOMEM;
>>>>>>>>  	}
>>>>>>>>  
>>>>>>>> +	ep_bw_info = kzalloc(sizeof(*ep_bw_info) * 31, GFP_KERNEL);
>>>
>>> GFP_KERNEL might not be suitable for all cases.
>>>
>>> xhci_reserve_bandwidth() is called from xhci_configure_endpoint(), which again
>>> is called from a lot of places.
>>> For example from xhci_update_hub_device() which can be called with GFP_NOIO mem_flags.
>>
>> What do you suggest as an alternative?
> 
> Just working on rectifying this now.
> 
> Which Get Free Page flag do you suggest here please?
> 

xhci_reserve_bandwidth() is called with spin lock held, so probably GFP_ATOMIC

But that whole function would need more attention.
It's always consuming  31 * sizeof(*ep_bw_info) bytes to store fallback values.
Normal use case is that just one, or a couple endpoints are changing, and we know which ones do.

-Mathias


just one enpoint changing.
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index ac2a7d4288883..40ce4b4eb12ad 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -2773,7 +2773,7 @@  static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
 		struct xhci_virt_device *virt_dev,
 		struct xhci_container_ctx *in_ctx)
 {
-	struct xhci_bw_info ep_bw_info[31];
+	struct xhci_bw_info *ep_bw_info;
 	int i;
 	struct xhci_input_control_ctx *ctrl_ctx;
 	int old_active_eps = 0;
@@ -2788,6 +2788,10 @@  static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
 		return -ENOMEM;
 	}
 
+	ep_bw_info = kzalloc(sizeof(*ep_bw_info) * 31, GFP_KERNEL);
+	if (!ep_bw_info)
+		return -ENOMEM;
+
 	for (i = 0; i < 31; i++) {
 		if (!EP_IS_ADDED(ctrl_ctx, i) && !EP_IS_DROPPED(ctrl_ctx, i))
 			continue;
@@ -2824,6 +2828,7 @@  static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
 		 * Update the number of active TTs.
 		 */
 		xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps);
+		kfree(ep_bw_info);
 		return 0;
 	}
 
@@ -2855,6 +2860,7 @@  static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
 					&virt_dev->eps[i],
 					virt_dev->tt_info);
 	}
+	kfree(ep_bw_info);
 	return -ENOMEM;
 }