Re: [PATCH linux-next] hwmon/ams: Add missing of_node_put inams-core.c

From: Stephen Rothwell
Date: Tue Dec 02 2008 - 18:31:21 EST


On Tue, 2 Dec 2008 14:48:13 +0100 Nicolas Palix <npalix@xxxxxxx> wrote:
>
> of_node_put is needed before discarding a value received from
> of_find_node_by_name, eg in error handling code or when the device
> node is no longer used.
>
> Signed-off-by: Nicolas Palix <npalix@xxxxxxx>
> Signed-off-by: Julia Lawall <julia@xxxxxxx>
> ---
> drivers/hwmon/ams/ams-core.c | 2 ++
> 1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/hwmon/ams/ams-core.c b/drivers/hwmon/ams/ams-core.c
> index 6c9ace1..e612af9 100644
> --- a/drivers/hwmon/ams/ams-core.c
> +++ b/drivers/hwmon/ams/ams-core.c
> @@ -202,6 +202,7 @@ int __init ams_init(void)
> if (np && of_device_is_compatible(np, "AAPL,accelerometer_1"))
> /* Found I2C motion sensor */
> return ams_i2c_init(np);
> + of_node_put(np);

This is wrong because if CONFIG_SENSORS_AMS_PMU is set, np is used again
below.

> #endif
>
> #ifdef CONFIG_SENSORS_AMS_PMU
> @@ -209,6 +210,7 @@ int __init ams_init(void)
> if (np && of_device_is_compatible(np, "sms"))
> /* Found PMU motion sensor */
> return ams_pmu_init(np);
> + of_node_put(np);
> #endif
> return -ENODEV;
> }

Also, I don't like this code since each of ams_i2c_init and ams_pmu_init
keep a reference to np, so they should be doing an of_node_get(np) and
this code above should be unconditionally doing an of_node_put(np). This
is not your problem, though.

--
Cheers,
Stephen Rothwell sfr@xxxxxxxxxxxxxxxx
http://www.canb.auug.org.au/~sfr/

Attachment: pgp00000.pgp
Description: PGP signature