Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: e45d7337dc0e ("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>

authored by

Joe Hattori and committed by
Greg Kroah-Hartman
ef42b906 645d56e4

+12 -7
+12 -7
drivers/usb/typec/anx7411.c
··· 290 290 struct power_supply *psy; 291 291 struct power_supply_desc psy_desc; 292 292 struct device *dev; 293 + struct fwnode_handle *switch_node; 294 + struct fwnode_handle *mux_node; 293 295 }; 294 296 295 297 static u8 snk_identity[] = { ··· 1101 1099 if (ctx->typec.typec_mux) { 1102 1100 typec_mux_unregister(ctx->typec.typec_mux); 1103 1101 ctx->typec.typec_mux = NULL; 1102 + fwnode_handle_put(ctx->mux_node); 1104 1103 } 1105 1104 } 1106 1105 ··· 1110 1107 if (ctx->typec.typec_switch) { 1111 1108 typec_switch_unregister(ctx->typec.typec_switch); 1112 1109 ctx->typec.typec_switch = NULL; 1110 + fwnode_handle_put(ctx->switch_node); 1113 1111 } 1114 1112 } 1115 1113 ··· 1118 1114 struct device *dev) 1119 1115 { 1120 1116 int ret; 1121 - struct device_node *node; 1122 1117 1123 - node = of_get_child_by_name(dev->of_node, "orientation_switch"); 1124 - if (!node) 1118 + ctx->switch_node = device_get_named_child_node(dev, "orientation_switch"); 1119 + if (!ctx->switch_node) 1125 1120 return 0; 1126 1121 1127 - ret = anx7411_register_switch(ctx, dev, &node->fwnode); 1122 + ret = anx7411_register_switch(ctx, dev, ctx->switch_node); 1128 1123 if (ret) { 1129 1124 dev_err(dev, "failed register switch"); 1125 + fwnode_handle_put(ctx->switch_node); 1130 1126 return ret; 1131 1127 } 1132 1128 1133 - node = of_get_child_by_name(dev->of_node, "mode_switch"); 1134 - if (!node) { 1129 + ctx->mux_node = device_get_named_child_node(dev, "mode_switch"); 1130 + if (!ctx->mux_node) { 1135 1131 dev_err(dev, "no typec mux exist"); 1136 1132 ret = -ENODEV; 1137 1133 goto unregister_switch; 1138 1134 } 1139 1135 1140 - ret = anx7411_register_mux(ctx, dev, &node->fwnode); 1136 + ret = anx7411_register_mux(ctx, dev, ctx->mux_node); 1141 1137 if (ret) { 1142 1138 dev_err(dev, "failed register mode switch"); 1139 + fwnode_handle_put(ctx->mux_node); 1143 1140 ret = -ENODEV; 1144 1141 goto unregister_switch; 1145 1142 }