diff mbox series

usb: typec: fix unreleased fwnode_handle in typec_port_register_altmodes()

Message ID 20241019-typec-class-fwnode_handle_put-v1-1-a3b5a0a02795@gmail.com (mailing list archive)
State Superseded
Headers show
Series usb: typec: fix unreleased fwnode_handle in typec_port_register_altmodes() | expand

Commit Message

Javier Carrasco Oct. 19, 2024, 8:40 p.m. UTC
The 'altmodes_node' fwnode_handle is never released after it is no
longer required, which leaks the resource.

Add the required call to fwnode_handle_put() when 'altmodes_node' is no
longer required.

Cc: stable@vger.kernel.org
Fixes: 7b458a4c5d73 ("usb: typec: Add typec_port_register_altmodes()")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/usb/typec/class.c | 1 +
 1 file changed, 1 insertion(+)


---
base-commit: f2493655d2d3d5c6958ed996b043c821c23ae8d3
change-id: 20241019-typec-class-fwnode_handle_put-b3648f5bc51b

Best regards,

Comments

Heikki Krogerus Oct. 21, 2024, 12:55 p.m. UTC | #1
On Sat, Oct 19, 2024 at 10:40:19PM +0200, Javier Carrasco wrote:
> The 'altmodes_node' fwnode_handle is never released after it is no
> longer required, which leaks the resource.
> 
> Add the required call to fwnode_handle_put() when 'altmodes_node' is no
> longer required.
> 
> Cc: stable@vger.kernel.org
> Fixes: 7b458a4c5d73 ("usb: typec: Add typec_port_register_altmodes()")
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/class.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index d61b4c74648d..1eb240604cf6 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -2341,6 +2341,7 @@ void typec_port_register_altmodes(struct typec_port *port,
>  		altmodes[index] = alt;
>  		index++;
>  	}
> +	fwnode_handle_put(altmodes_node);
>  }
>  EXPORT_SYMBOL_GPL(typec_port_register_altmodes);
>  
>
Heikki Krogerus Oct. 21, 2024, 1:42 p.m. UTC | #2
Hi,

On Mon, Oct 21, 2024 at 03:55:43PM +0300, Heikki Krogerus wrote:
> On Sat, Oct 19, 2024 at 10:40:19PM +0200, Javier Carrasco wrote:
> > The 'altmodes_node' fwnode_handle is never released after it is no
> > longer required, which leaks the resource.
> > 
> > Add the required call to fwnode_handle_put() when 'altmodes_node' is no
> > longer required.
> > 
> > Cc: stable@vger.kernel.org
> > Fixes: 7b458a4c5d73 ("usb: typec: Add typec_port_register_altmodes()")
> > Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> 
> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> 
> > ---
> >  drivers/usb/typec/class.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> > index d61b4c74648d..1eb240604cf6 100644
> > --- a/drivers/usb/typec/class.c
> > +++ b/drivers/usb/typec/class.c
> > @@ -2341,6 +2341,7 @@ void typec_port_register_altmodes(struct typec_port *port,
> >  		altmodes[index] = alt;
> >  		index++;
> >  	}
> > +	fwnode_handle_put(altmodes_node);
> >  }
> >  EXPORT_SYMBOL_GPL(typec_port_register_altmodes);

Sorry to go back to this, but I guess we should actually use those
scope based helpers with fwnodes in this case. So instead of a
dedicated fwnode_handle_put() call like that, just introduce
altmodes_node like this:

        ...
        struct fwnode_handle *altmodes_node __free(fwnode_handle) =
                device_get_named_child_node(&port->dev, "altmodes");

        if (IS_ERR(altmodes_node))
                return;

        fwnode_for_each_child_node(altmodes_node, child) {
        ...

thanks,
Javier Carrasco Oct. 21, 2024, 2:06 p.m. UTC | #3
On 21/10/2024 15:42, Heikki Krogerus wrote:
> Hi,
> 
> On Mon, Oct 21, 2024 at 03:55:43PM +0300, Heikki Krogerus wrote:
>> On Sat, Oct 19, 2024 at 10:40:19PM +0200, Javier Carrasco wrote:
>>> The 'altmodes_node' fwnode_handle is never released after it is no
>>> longer required, which leaks the resource.
>>>
>>> Add the required call to fwnode_handle_put() when 'altmodes_node' is no
>>> longer required.
>>>
>>> Cc: stable@vger.kernel.org
>>> Fixes: 7b458a4c5d73 ("usb: typec: Add typec_port_register_altmodes()")
>>> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
>>
>> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>>
>>> ---
>>>  drivers/usb/typec/class.c | 1 +
>>>  1 file changed, 1 insertion(+)
>>>
>>> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
>>> index d61b4c74648d..1eb240604cf6 100644
>>> --- a/drivers/usb/typec/class.c
>>> +++ b/drivers/usb/typec/class.c
>>> @@ -2341,6 +2341,7 @@ void typec_port_register_altmodes(struct typec_port *port,
>>>  		altmodes[index] = alt;
>>>  		index++;
>>>  	}
>>> +	fwnode_handle_put(altmodes_node);
>>>  }
>>>  EXPORT_SYMBOL_GPL(typec_port_register_altmodes);
> 
> Sorry to go back to this, but I guess we should actually use those
> scope based helpers with fwnodes in this case. So instead of a
> dedicated fwnode_handle_put() call like that, just introduce
> altmodes_node like this:
> 
>         ...
>         struct fwnode_handle *altmodes_node __free(fwnode_handle) =
>                 device_get_named_child_node(&port->dev, "altmodes");
> 
>         if (IS_ERR(altmodes_node))
>                 return;
> 
>         fwnode_for_each_child_node(altmodes_node, child) {
>         ...
> 
> thanks,
> 

That would have to be a second patch, because it does not apply to all
affected stable kernels. I can send it separately, though.

Best regards,
Javier Carrasco
Heikki Krogerus Oct. 21, 2024, 2:20 p.m. UTC | #4
On Mon, Oct 21, 2024 at 04:06:30PM +0200, Javier Carrasco wrote:
> On 21/10/2024 15:42, Heikki Krogerus wrote:
> > Hi,
> > 
> > On Mon, Oct 21, 2024 at 03:55:43PM +0300, Heikki Krogerus wrote:
> >> On Sat, Oct 19, 2024 at 10:40:19PM +0200, Javier Carrasco wrote:
> >>> The 'altmodes_node' fwnode_handle is never released after it is no
> >>> longer required, which leaks the resource.
> >>>
> >>> Add the required call to fwnode_handle_put() when 'altmodes_node' is no
> >>> longer required.
> >>>
> >>> Cc: stable@vger.kernel.org
> >>> Fixes: 7b458a4c5d73 ("usb: typec: Add typec_port_register_altmodes()")
> >>> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> >>
> >> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> >>
> >>> ---
> >>>  drivers/usb/typec/class.c | 1 +
> >>>  1 file changed, 1 insertion(+)
> >>>
> >>> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> >>> index d61b4c74648d..1eb240604cf6 100644
> >>> --- a/drivers/usb/typec/class.c
> >>> +++ b/drivers/usb/typec/class.c
> >>> @@ -2341,6 +2341,7 @@ void typec_port_register_altmodes(struct typec_port *port,
> >>>  		altmodes[index] = alt;
> >>>  		index++;
> >>>  	}
> >>> +	fwnode_handle_put(altmodes_node);
> >>>  }
> >>>  EXPORT_SYMBOL_GPL(typec_port_register_altmodes);
> > 
> > Sorry to go back to this, but I guess we should actually use those
> > scope based helpers with fwnodes in this case. So instead of a
> > dedicated fwnode_handle_put() call like that, just introduce
> > altmodes_node like this:
> > 
> >         ...
> >         struct fwnode_handle *altmodes_node __free(fwnode_handle) =
> >                 device_get_named_child_node(&port->dev, "altmodes");
> > 
> >         if (IS_ERR(altmodes_node))
> >                 return;
> > 
> >         fwnode_for_each_child_node(altmodes_node, child) {
> >         ...
> > 
> > thanks,
> > 
> 
> That would have to be a second patch, because it does not apply to all
> affected stable kernels. I can send it separately, though.

Great, thanks!
diff mbox series

Patch

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index d61b4c74648d..1eb240604cf6 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -2341,6 +2341,7 @@  void typec_port_register_altmodes(struct typec_port *port,
 		altmodes[index] = alt;
 		index++;
 	}
+	fwnode_handle_put(altmodes_node);
 }
 EXPORT_SYMBOL_GPL(typec_port_register_altmodes);