Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1193076 > unrolled thread

Bad change in commit 297d716f6260cc9421d971b124ca196b957ee458?

Started by"H.J. Lu" <hjl.tools@gmail.com>
First post2015-07-27 15:20 +0200
Last post2015-07-28 01:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  Bad change in commit 297d716f6260cc9421d971b124ca196b957ee458? "H.J. Lu" <hjl.tools@gmail.com> - 2015-07-27 15:20 +0200
    Re: Bad change in commit 297d716f6260cc9421d971b124ca196b957ee458? Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2015-07-28 01:50 +0200

#1193076 — Bad change in commit 297d716f6260cc9421d971b124ca196b957ee458?

From"H.J. Lu" <hjl.tools@gmail.com>
Date2015-07-27 15:20 +0200
SubjectBad change in commit 297d716f6260cc9421d971b124ca196b957ee458?
Message-ID<pQQtY-2W3-5@gated-at.bofh.it>
Hi,

This commit:

commit 297d716f6260cc9421d971b124ca196b957ee458
Author: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Date:   Thu Mar 12 08:44:11 2015 +0100

    power_supply: Change ownership from driver to core

    Change the ownership of power_supply structure from each driver
    implementing the class to the power supply core.

has

static void hidinput_cleanup_battery(struct hid_device *dev)
 {
-       if (!dev->battery.name)
+       if (!dev->battery)
                return;

-       power_supply_unregister(&dev->battery);
-       kfree(dev->battery.name);
-       dev->battery.name = NULL;
+       power_supply_unregister(dev->battery);
+       kfree(dev->battery->desc->name);
+       kfree(dev->battery->desc);
+       dev->battery = NULL;
 }

Is this OK to access dev->battery after calling power_supply_unregister?

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

[toc] | [next] | [standalone]


#1193631

FromKrzysztof Kozlowski <k.kozlowski@samsung.com>
Date2015-07-28 01:50 +0200
Message-ID<pR0jE-fw-31@gated-at.bofh.it>
In reply to#1193076
On 27.07.2015 22:10, H.J. Lu wrote:
> Hi,
> 
> This commit:
> 
> commit 297d716f6260cc9421d971b124ca196b957ee458
> Author: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Date:   Thu Mar 12 08:44:11 2015 +0100
> 
>     power_supply: Change ownership from driver to core
> 
>     Change the ownership of power_supply structure from each driver
>     implementing the class to the power supply core.
> 
> has
> 
> static void hidinput_cleanup_battery(struct hid_device *dev)
>  {
> -       if (!dev->battery.name)
> +       if (!dev->battery)
>                 return;
> 
> -       power_supply_unregister(&dev->battery);
> -       kfree(dev->battery.name);
> -       dev->battery.name = NULL;
> +       power_supply_unregister(dev->battery);
> +       kfree(dev->battery->desc->name);
> +       kfree(dev->battery->desc);
> +       dev->battery = NULL;
>  }
> 
> Is this OK to access dev->battery after calling power_supply_unregister?

(+Cc Jiri, linux-input, linux-pm, Sebastian)

Good catch, it is not safe. The final device_unregister() will free the
structure.

We should access directly psy_desc here. I'll sent a proposal of fixing
this and check other drivers for this pattern.

Best regards,
Krzysztof
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web