From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751121AbcL0FFR (ORCPT ); Tue, 27 Dec 2016 00:05:17 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:50827 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750764AbcL0FFN (ORCPT ); Tue, 27 Dec 2016 00:05:13 -0500 MIME-version: 1.0 Content-type: text/plain; charset=utf-8 X-AuditID: b6c32a3c-f79646d000004d82-13-5861f6796564 Content-transfer-encoding: 8BIT Message-id: <5861F678.9010408@samsung.com> Date: Tue, 27 Dec 2016 14:04:56 +0900 From: Chanwoo Choi Organization: Samsung Electronics User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 To: Hans de Goede Cc: myungjoo.ham@samsung.com, Linux Kernel Mailing List Subject: Re: Unregistering extcon providers while they are in use leads to kernel crashes In-reply-to: <0c877df4-c5d7-1eae-bff9-469df9651d09@redhat.com> X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0hTURzHPbvz7houT7Psx3rNSyWZW7u3qaucWUkaKUhFjETmZbv42sN2 Nyuj0J4mUplZJJIGEaGGoeY0Q8uWQmGUoZmR2YOwd2RKED22XaL++5zv+f7O73e+/ChC8TVY SeXZXbzTzllpcoa0/fYyrbp4mjNq+5X6D/1nJfpH12tJ/dPSy2QSkfq5e4hMPd7WgFInWxZm EDv4hFyes/BOFW83Oyx59hwDvXmraYMpNk7LqJlV+nhaZedsvIFOTstQb8yz+vrQqiLO6vZJ GZwg0CsSE5wOt4tX5ToEl4HOZBhWw2jjNSzLanQrs1azsT5LNp/75Gs5UXgxbHd3cx9Rgs6E lqMQCrAO+sbvBIscAQ/GmslyNINS4A4EnZXHpP4LBT4qgfdt+G9B5bMLhGiqRdDd5A2Y5HgW fK8a8zFFEXgReAcL/DKBl8HEt1NS0T+GoKl1OOCR42j4ec3i90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6bmGeanlesWJucWleel6yfm5mxjBcfNMagfjwV3uhxgF OBiVeHh/LE+MEGJNLCuuzD3EKMHBrCTCG/8ZKMSbklhZlVqUH19UmpNafIjRFOjVicxSosn5 wJjOK4k3NDE3MTc2sDC3tDQxUhLnbZz9LFxIID2xJDU7NbUgtQimj4mDU6qBUdrmwhL/eyyL nL4YvnF9dfGpgfE0+dusjZntp9V2V18u+WOWGmd6lGHe8x/sOhPqBKSC9m88UGAiUDV/scDk g7GVRS0Hzlxdl1rQG3HpUon+qYc7f+Qy34+t/nDx1vygh9PPMbx78F54AdOmd2HX+puLr2sK WzxbnbF/NYO+0wE1H33bEL8VJ5VYijMSDbWYi4oTAUcu5JexAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161227050457epcas1p345d2cb1234c04169c94cbf1db6a7924b X-Msg-Generator: CA X-Sender-IP: 203.254.230.26 X-Local-Sender: =?UTF-8?B?7LWc7LCs7JqwG1RpemVuIFBsYXRmb3JtIExhYihTL1fshLw=?= =?UTF-8?B?7YSwKRvsgrzshLHsoITsnpAbUzUo7LGF7J6EKS9DaGFuZ2UgQWdlbnQ=?= X-Global-Sender: =?UTF-8?B?Q2hhbndvbyBDaG9pG1RpemVuIFBsYXRmb3JtIExhYi4bU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtTNS9TZW5pb3IgRW5naW5lZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG1NUQUYbQzEwVjgxMTE=?= CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-HopCount: 7 X-CMS-RootMailID: 20161221155432epcas2p4c811f99cc0c82bc1f29cb74f29228300 X-RootMTR: 20161221155432epcas2p4c811f99cc0c82bc1f29cb74f29228300 References: <0c877df4-c5d7-1eae-bff9-469df9651d09@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Hans, Thanks for your report. I'll check this problem and try to resolve it. On 2016년 12월 22일 00:54, Hans de Goede wrote: > Hi, > > With the recent extcon work I've been doing I noticed that > if I want to rmmod and then insmod say extcon_axp288 I can > do so without problems even if axp288_charger is holding > a reference to the extcon device returned by extcon_get_extcon_dev. > > The problem is that extcon_get_extcon_dev simply looks up > the extcon-device in the list of current registered extcon-s > and then returns a pointer to it, without any reference > counting. > > The rmmod scenario can be fixed by doing a module_get from > extcon_get_extcon_dev, but that still leaves the same problem > when root manually unbinds the driver through sysfs. > > A possible way fix this would be: > > 1) Make all extcon providers use devm_extcon_dev_allocate and document > using this to allocate an extcon_dev mandatory > > 2) Add a refcount to struct extcon_dev and introduce extcon_dev_get > and extcon_dev_put helpers which modify the refcount and only free > the memory on the final put (and make the evm_extcon_dev_allocate > cleanup function call extcon_dev_put) > > 3) On extcon_dev_unregister set a flag in the extcon_dev that it > has been free-ed, make all extcon consumer functions which take > an extcon_dev (extcon_get_state, extcon_register_notifier, etc.) > check this flag and return -ENODEV when the extcon has been unregistered > > 4) Make extcon_get_extcon_dev call extcon_dev_get on the returned edev > before returning it > > From here on we've fixed the crash, but we now leak the extcon_dev > when the consumer gets unbound. > > 5) Add a devm_extcon_get_extcon_dev which calls extcon_dev_put as the devm > cleanup function > > 6) Convert all extcon consumers to use devm_extcon_get_extcon_dev > > Regards, > > Hans > > > -- Regards, Chanwoo Choi