Skip to content

Commit 0ba9d3a

Browse files
javiercarrascocruzdtor
authored andcommitted
Input: twl6040-vibra - use cleanup facility for device_node
Use the '__free(device_node)' macro to simplify the code and error handling. This makes the error handling more robust by ensuring that the device node is always freed. Signed-off-by: Javier Carrasco <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 0ec6f58 commit 0ba9d3a

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

drivers/input/misc/twl6040-vibra.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,20 @@ static DEFINE_SIMPLE_DEV_PM_OPS(twl6040_vibra_pm_ops,
229229
static int twl6040_vibra_probe(struct platform_device *pdev)
230230
{
231231
struct device *twl6040_core_dev = pdev->dev.parent;
232-
struct device_node *twl6040_core_node;
233232
struct vibra_info *info;
234233
int vddvibl_uV = 0;
235234
int vddvibr_uV = 0;
236235
int error;
237236

238-
twl6040_core_node = of_get_child_by_name(twl6040_core_dev->of_node,
239-
"vibra");
237+
struct device_node *twl6040_core_node __free(device_node) =
238+
of_get_child_by_name(twl6040_core_dev->of_node, "vibra");
240239
if (!twl6040_core_node) {
241240
dev_err(&pdev->dev, "parent of node is missing?\n");
242241
return -EINVAL;
243242
}
244243

245244
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
246245
if (!info) {
247-
of_node_put(twl6040_core_node);
248246
dev_err(&pdev->dev, "couldn't allocate memory\n");
249247
return -ENOMEM;
250248
}
@@ -264,8 +262,6 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
264262
of_property_read_u32(twl6040_core_node, "ti,vddvibl-uV", &vddvibl_uV);
265263
of_property_read_u32(twl6040_core_node, "ti,vddvibr-uV", &vddvibr_uV);
266264

267-
of_node_put(twl6040_core_node);
268-
269265
if ((!info->vibldrv_res && !info->viblmotor_res) ||
270266
(!info->vibrdrv_res && !info->vibrmotor_res)) {
271267
dev_err(info->dev, "invalid vibra driver/motor resistance\n");

0 commit comments

Comments
 (0)