mirror of https://github.com/torvalds/linux.git
usb: typec: anx7411: fix OF node reference leaks in anx7411_typec_switch_probe()
The refcounts of the OF nodes obtained by of_get_child_by_name() calls
in anx7411_typec_switch_probe() are not decremented. Replace them with
device_get_named_child_node() calls and store the return values to the
newly created fwnode_handle fields in anx7411_data, and call
fwnode_handle_put() on them in the error path and in the unregister
functions.
Fixes: e45d7337dc ("usb: typec: anx7411: Use of_get_child_by_name() instead of of_find_node_by_name()")
Cc: stable@vger.kernel.org
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20241126014909.3687917-1-joe@pf.is.s.u-tokyo.ac.jp
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
645d56e4cc
commit
ef42b906df
|
|
@ -290,6 +290,8 @@ struct anx7411_data {
|
|||
struct power_supply *psy;
|
||||
struct power_supply_desc psy_desc;
|
||||
struct device *dev;
|
||||
struct fwnode_handle *switch_node;
|
||||
struct fwnode_handle *mux_node;
|
||||
};
|
||||
|
||||
static u8 snk_identity[] = {
|
||||
|
|
@ -1099,6 +1101,7 @@ static void anx7411_unregister_mux(struct anx7411_data *ctx)
|
|||
if (ctx->typec.typec_mux) {
|
||||
typec_mux_unregister(ctx->typec.typec_mux);
|
||||
ctx->typec.typec_mux = NULL;
|
||||
fwnode_handle_put(ctx->mux_node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1107,6 +1110,7 @@ static void anx7411_unregister_switch(struct anx7411_data *ctx)
|
|||
if (ctx->typec.typec_switch) {
|
||||
typec_switch_unregister(ctx->typec.typec_switch);
|
||||
ctx->typec.typec_switch = NULL;
|
||||
fwnode_handle_put(ctx->switch_node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1114,28 +1118,29 @@ static int anx7411_typec_switch_probe(struct anx7411_data *ctx,
|
|||
struct device *dev)
|
||||
{
|
||||
int ret;
|
||||
struct device_node *node;
|
||||
|
||||
node = of_get_child_by_name(dev->of_node, "orientation_switch");
|
||||
if (!node)
|
||||
ctx->switch_node = device_get_named_child_node(dev, "orientation_switch");
|
||||
if (!ctx->switch_node)
|
||||
return 0;
|
||||
|
||||
ret = anx7411_register_switch(ctx, dev, &node->fwnode);
|
||||
ret = anx7411_register_switch(ctx, dev, ctx->switch_node);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed register switch");
|
||||
fwnode_handle_put(ctx->switch_node);
|
||||
return ret;
|
||||
}
|
||||
|
||||
node = of_get_child_by_name(dev->of_node, "mode_switch");
|
||||
if (!node) {
|
||||
ctx->mux_node = device_get_named_child_node(dev, "mode_switch");
|
||||
if (!ctx->mux_node) {
|
||||
dev_err(dev, "no typec mux exist");
|
||||
ret = -ENODEV;
|
||||
goto unregister_switch;
|
||||
}
|
||||
|
||||
ret = anx7411_register_mux(ctx, dev, &node->fwnode);
|
||||
ret = anx7411_register_mux(ctx, dev, ctx->mux_node);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed register mode switch");
|
||||
fwnode_handle_put(ctx->mux_node);
|
||||
ret = -ENODEV;
|
||||
goto unregister_switch;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue