Re: [PATCH 2/3] platform-drivers-x86: asus-wmi: fix resource leak in asus_wmi_led_exit

From: Corentin Chary
Date: Mon Aug 08 2011 - 08:18:19 EST


On Mon, Aug 8, 2011 at 11:16 AM, Axel Lin <axel.lin@xxxxxxxxx> wrote:
> This patch fixes wrong test for successful registered led_classdev,
> and also fixes a leak due to missing led_classdev_unregister call
> for asus->kbd_led in asus_wmi_led_exit.
>
> device_create returns &struct device pointer on success, or ERR_PTR() on error.
> Thus if led_classdev_register fails, led_cdev->dev is always not NULL.
>
> Thus to unregister a successful registered led_classdev, we should check
> (!IS_ERR_OR_NULL(asus->tpd_led.dev)) instead of (asus->tpd_led.dev).
>
> we use IS_ERR_OR_NULL instead of IS_ERR because if we havn't call
> led_classdev_register, the led_cdev->dev is NULL.
>
> Signed-off-by: Axel Lin <axel.lin@xxxxxxxxx>

Acked-by: Corentin Chary <corentin.chary@xxxxxxxxx>

> ---
> Âdrivers/platform/x86/asus-wmi.c | Â Â4 +++-
> Â1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index 95cba9e..d1049ee 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -453,7 +453,9 @@ static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
>
> Âstatic void asus_wmi_led_exit(struct asus_wmi *asus)
> Â{
> - Â Â Â if (asus->tpd_led.dev)
> + Â Â Â if (!IS_ERR_OR_NULL(asus->kbd_led.dev))
> + Â Â Â Â Â Â Â led_classdev_unregister(&asus->kbd_led);
> + Â Â Â if (!IS_ERR_OR_NULL(asus->tpd_led.dev))
> Â Â Â Â Â Â Â Âled_classdev_unregister(&asus->tpd_led);
> Â Â Â Âif (asus->led_workqueue)
> Â Â Â Â Â Â Â Âdestroy_workqueue(asus->led_workqueue);
> --
> 1.7.4.1
>
>
>
>



--
Corentin Chary
http://xf.iksaif.net
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/