diff mbox series

[v5,2/3] usb: typec: ucsi: do not allocate one extra unused connector

Message ID 1650597022-19793-3-git-send-email-quic_linyyuan@quicinc.com (mailing list archive)
State Superseded
Headers show
Series usb: typec: ucsi: allow retry to find role switch | expand

Commit Message

Linyu Yuan April 22, 2022, 3:10 a.m. UTC
In ucsi_init(), it allocate number of (ucsi->cap.num_connectors + 1)
connectors, there is one extra as the ending.
ucsi_unregister_connectors() is safe to unregister all ucsi connectors
according ucsi->cap.num_connectors.

Let's remove the extra one connector to save memory.

Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
---
v2: new change
v3: no change
v4: fix a typo extral -> extra in commit description
v5: update commit description

 drivers/usb/typec/ucsi/ucsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Heikki Krogerus April 25, 2022, 8:13 a.m. UTC | #1
On Fri, Apr 22, 2022 at 11:10:21AM +0800, Linyu Yuan wrote:
> In ucsi_init(), it allocate number of (ucsi->cap.num_connectors + 1)
> connectors, there is one extra as the ending.
> ucsi_unregister_connectors() is safe to unregister all ucsi connectors
> according ucsi->cap.num_connectors.
> 
> Let's remove the extra one connector to save memory.

Maybe you could just merge this one into the first patch.

> Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
> ---
> v2: new change
> v3: no change
> v4: fix a typo extral -> extra in commit description
> v5: update commit description
> 
>  drivers/usb/typec/ucsi/ucsi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index af9a2a1..ce9192e 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1251,7 +1251,7 @@ static int ucsi_init(struct ucsi *ucsi)
>  	}
>  
>  	/* Allocate the connectors. Released in ucsi_unregister() */
> -	ucsi->connector = kcalloc(ucsi->cap.num_connectors + 1,
> +	ucsi->connector = kcalloc(ucsi->cap.num_connectors,
>  				  sizeof(*ucsi->connector), GFP_KERNEL);
>  	if (!ucsi->connector) {
>  		ret = -ENOMEM;
> -- 
> 2.7.4

thanks,
Linyu Yuan April 25, 2022, 8:23 a.m. UTC | #2
> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Sent: Monday, April 25, 2022 4:14 PM
> To: Linyu Yuan (QUIC) <quic_linyyuan@quicinc.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>; linux-
> usb@vger.kernel.org; Jack Pham (QUIC) <quic_jackp@quicinc.com>
> Subject: Re: [PATCH v5 2/3] usb: typec: ucsi: do not allocate one extra
> unused connector
> 
> On Fri, Apr 22, 2022 at 11:10:21AM +0800, Linyu Yuan wrote:
> > In ucsi_init(), it allocate number of (ucsi->cap.num_connectors + 1)
> > connectors, there is one extra as the ending.
> > ucsi_unregister_connectors() is safe to unregister all ucsi connectors
> > according ucsi->cap.num_connectors.
> >
> > Let's remove the extra one connector to save memory.
> 
> Maybe you could just merge this one into the first patch.

Sure, thanks, will merge next version.

> 
> > Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
> > ---
> > v2: new change
> > v3: no change
> > v4: fix a typo extral -> extra in commit description
> > v5: update commit description
> >
> >  drivers/usb/typec/ucsi/ucsi.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> > index af9a2a1..ce9192e 100644
> > --- a/drivers/usb/typec/ucsi/ucsi.c
> > +++ b/drivers/usb/typec/ucsi/ucsi.c
> > @@ -1251,7 +1251,7 @@ static int ucsi_init(struct ucsi *ucsi)
> >  	}
> >
> >  	/* Allocate the connectors. Released in ucsi_unregister() */
> > -	ucsi->connector = kcalloc(ucsi->cap.num_connectors + 1,
> > +	ucsi->connector = kcalloc(ucsi->cap.num_connectors,
> >  				  sizeof(*ucsi->connector), GFP_KERNEL);
> >  	if (!ucsi->connector) {
> >  		ret = -ENOMEM;
> > --
> > 2.7.4
> 
> thanks,
> 
> --
> heikki
diff mbox series

Patch

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index af9a2a1..ce9192e 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1251,7 +1251,7 @@  static int ucsi_init(struct ucsi *ucsi)
 	}
 
 	/* Allocate the connectors. Released in ucsi_unregister() */
-	ucsi->connector = kcalloc(ucsi->cap.num_connectors + 1,
+	ucsi->connector = kcalloc(ucsi->cap.num_connectors,
 				  sizeof(*ucsi->connector), GFP_KERNEL);
 	if (!ucsi->connector) {
 		ret = -ENOMEM;