Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753100AbbGORA4 (ORCPT ); Wed, 15 Jul 2015 13:00:56 -0400 Received: from mail-ig0-f178.google.com ([209.85.213.178]:38148 "EHLO mail-ig0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751738AbbGORAz (ORCPT ); Wed, 15 Jul 2015 13:00:55 -0400 MIME-Version: 1.0 In-Reply-To: <1503739.gVWYM3p8QD@avalon> References: <1503739.gVWYM3p8QD@avalon> Date: Wed, 15 Jul 2015 10:00:54 -0700 Message-ID: Subject: Re: Is devm_* broken ? From: Dan Williams To: Laurent Pinchart Cc: Linux Kernel Mailing List , Tejun Heo Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1700 Lines: 41 [ adding Tejun ] On Tue, Jul 14, 2015 at 3:34 PM, Laurent Pinchart wrote: > Hello, > > I came to realize not too long ago that the following sequence of events will > lead to a crash with any platform driver that uses devm_* and creates device > nodes. > > 1. Get a platform device bound it its driver > 2. Open the corresponding device node in userspace and keep it open > 3. Unbind the platform device from its driver through sysfs > > echo > /sys/bus/platform/drivers//unbind > > (or for hotpluggable devices just unplug the device) > > 4. Close the device node > 5. Enjoy the fireworks > > While having a device node open prevents modules from being unloaded, it > doesn't prevent devices from being unbound from drivers. If the driver uses > devm_* helpers to allocate memory the memory will be freed when the device is > unbound from the driver, but that memory will still be used by any operation > touching an open device node. > > Is devm_* inherently broken ? It's so widely used, tell me I'm missing > something obvious. Sounds like a real problem. The drivers I've used devm with have an upper layer that prevents this crash, but that's not much consolation. I think adding lifetime to devm allocations would be useful that way ->probe() and open() can do a devres_get() while ->remove() and close() can do a devres_put(). Perhaps I'm also missing something obvious though... -- 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/