Skip to content

Commit ef42b90

Browse files
joehattorigregkh
authored andcommitted
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: e45d733 ("usb: typec: anx7411: Use of_get_child_by_name() instead of of_find_node_by_name()") Cc: [email protected] Signed-off-by: Joe Hattori <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 645d56e commit ef42b90

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

drivers/usb/typec/anx7411.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ struct anx7411_data {
290290
struct power_supply *psy;
291291
struct power_supply_desc psy_desc;
292292
struct device *dev;
293+
struct fwnode_handle *switch_node;
294+
struct fwnode_handle *mux_node;
293295
};
294296

295297
static u8 snk_identity[] = {
@@ -1099,6 +1101,7 @@ static void anx7411_unregister_mux(struct anx7411_data *ctx)
10991101
if (ctx->typec.typec_mux) {
11001102
typec_mux_unregister(ctx->typec.typec_mux);
11011103
ctx->typec.typec_mux = NULL;
1104+
fwnode_handle_put(ctx->mux_node);
11021105
}
11031106
}
11041107

@@ -1107,35 +1110,37 @@ static void anx7411_unregister_switch(struct anx7411_data *ctx)
11071110
if (ctx->typec.typec_switch) {
11081111
typec_switch_unregister(ctx->typec.typec_switch);
11091112
ctx->typec.typec_switch = NULL;
1113+
fwnode_handle_put(ctx->switch_node);
11101114
}
11111115
}
11121116

11131117
static int anx7411_typec_switch_probe(struct anx7411_data *ctx,
11141118
struct device *dev)
11151119
{
11161120
int ret;
1117-
struct device_node *node;
11181121

1119-
node = of_get_child_by_name(dev->of_node, "orientation_switch");
1120-
if (!node)
1122+
ctx->switch_node = device_get_named_child_node(dev, "orientation_switch");
1123+
if (!ctx->switch_node)
11211124
return 0;
11221125

1123-
ret = anx7411_register_switch(ctx, dev, &node->fwnode);
1126+
ret = anx7411_register_switch(ctx, dev, ctx->switch_node);
11241127
if (ret) {
11251128
dev_err(dev, "failed register switch");
1129+
fwnode_handle_put(ctx->switch_node);
11261130
return ret;
11271131
}
11281132

1129-
node = of_get_child_by_name(dev->of_node, "mode_switch");
1130-
if (!node) {
1133+
ctx->mux_node = device_get_named_child_node(dev, "mode_switch");
1134+
if (!ctx->mux_node) {
11311135
dev_err(dev, "no typec mux exist");
11321136
ret = -ENODEV;
11331137
goto unregister_switch;
11341138
}
11351139

1136-
ret = anx7411_register_mux(ctx, dev, &node->fwnode);
1140+
ret = anx7411_register_mux(ctx, dev, ctx->mux_node);
11371141
if (ret) {
11381142
dev_err(dev, "failed register mode switch");
1143+
fwnode_handle_put(ctx->mux_node);
11391144
ret = -ENODEV;
11401145
goto unregister_switch;
11411146
}

0 commit comments

Comments
 (0)