mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 00:51:51 -04:00
Input: 88pm860x - use cleanup facility for device_node
Use the '__free(device_node)' macro to simplify the code and error handling. This makes the code more robust by ensuring that the device node is always freed. Drop the first assignment to 'pdev->dev.parent->of_node', as it was only a shortcut, and tie 'np' to its usage as a child node. Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com> Link: https://lore.kernel.org/r/20241010-input_automate_of_node_put-v1-7-ebc62138fbf8@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
committed by
Dmitry Torokhov
parent
d3dcadd654
commit
8dee1ddafa
@@ -117,13 +117,14 @@ static int pm860x_touch_dt_init(struct platform_device *pdev,
|
||||
struct pm860x_chip *chip,
|
||||
int *res_x)
|
||||
{
|
||||
struct device_node *np = pdev->dev.parent->of_node;
|
||||
struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
|
||||
: chip->companion;
|
||||
int data, n, ret;
|
||||
if (!np)
|
||||
if (!pdev->dev.parent->of_node)
|
||||
return -ENODEV;
|
||||
np = of_get_child_by_name(np, "touch");
|
||||
|
||||
struct device_node *np __free(device_node) =
|
||||
of_get_child_by_name(pdev->dev.parent->of_node, "touch");
|
||||
if (!np) {
|
||||
dev_err(&pdev->dev, "Can't find touch node\n");
|
||||
return -EINVAL;
|
||||
@@ -141,13 +142,13 @@ static int pm860x_touch_dt_init(struct platform_device *pdev,
|
||||
if (data) {
|
||||
ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
|
||||
if (ret < 0)
|
||||
goto err_put_node;
|
||||
return -EINVAL;
|
||||
}
|
||||
/* set tsi prebias time */
|
||||
if (!of_property_read_u32(np, "marvell,88pm860x-tsi-prebias", &data)) {
|
||||
ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
|
||||
if (ret < 0)
|
||||
goto err_put_node;
|
||||
return -EINVAL;
|
||||
}
|
||||
/* set prebias & prechg time of pen detect */
|
||||
data = 0;
|
||||
@@ -158,18 +159,11 @@ static int pm860x_touch_dt_init(struct platform_device *pdev,
|
||||
if (data) {
|
||||
ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
|
||||
if (ret < 0)
|
||||
goto err_put_node;
|
||||
return -EINVAL;
|
||||
}
|
||||
of_property_read_u32(np, "marvell,88pm860x-resistor-X", res_x);
|
||||
|
||||
of_node_put(np);
|
||||
|
||||
return 0;
|
||||
|
||||
err_put_node:
|
||||
of_node_put(np);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
#else
|
||||
#define pm860x_touch_dt_init(x, y, z) (-1)
|
||||
|
||||
Reference in New Issue
Block a user