From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755150AbZBRQuQ (ORCPT ); Wed, 18 Feb 2009 11:50:16 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753382AbZBRQuA (ORCPT ); Wed, 18 Feb 2009 11:50:00 -0500 Received: from ug-out-1314.google.com ([66.249.92.168]:42417 "EHLO ug-out-1314.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752941AbZBRQt7 (ORCPT ); Wed, 18 Feb 2009 11:49:59 -0500 MIME-Version: 1.0 In-Reply-To: References: <20090218151132.476.81706.stgit@localhost.localdomain> <20090218152913.GA26448@suse.de> Date: Wed, 18 Feb 2009 17:49:56 +0100 Message-ID: Subject: Re: [PATCH] Export device_add_attributes() so drivers can use it. From: Kay Sievers To: Grant Likely Cc: Greg KH , linux-kernel@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 18, 2009 at 17:34, Grant Likely wrote: > On Wed, Feb 18, 2009 at 8:53 AM, Kay Sievers wrote: >> On Wed, Feb 18, 2009 at 16:48, Grant Likely wrote: >>> On Wed, Feb 18, 2009 at 8:45 AM, Kay Sievers wrote: >>>> On Wed, Feb 18, 2009 at 16:29, Greg KH wrote: >>>>> On Wed, Feb 18, 2009 at 08:11:34AM -0700, Grant Likely wrote: >>>>>> From: Grant Likely >>>>>> >>>>>> I find myself using the pattern of device_add_attributes() and >>>>>> device_remove_attributes() frequently in my drivers. Rather than >>>>>> reinventing the wheel every time, I'm floating this patch to export >>>>>> the symbols to see how it is received. If this looks okay then I'll >>>>>> rework my drivers and post additional patches to use these functions. >>>>> >>>>> No objection from me, as long as the symbols are EXPORT_SYMBOL_GPL(), >>>>> like the rest of the driver core. Is that ok with you? >>>> >>>> These functions used outside the core create attributes after the >>>> uevent is sent, and userspace will not see these files at event time. >>>> This is in most cases a pretty broken behavior. Is that the expected >>>> behavior in your drivers? >>> >>> ??? I don't follow what you mean. >>> >>> I'm using these functions to allow the driver to add device attribs; >>> primarily for debugging knobs and controls. Userspace will see the >>> files after the driver is bound to the device. The uevent doesn't >>> really come into play. >> >> Sure, they do. Many things expect all files which are visible at the >> device to be readable also at event time. That's the whole way udev >> and device property matching works. There are only a few exceptions >> where creating files at a device later, after it is registered with >> the core, is not a bug. > > Let me make sure I understand you... > > Is it a bug for a device driver to call > device_create_file()/device_remove_file() at probe time? For example, > if I have a data capture device which is probed via the platform bus, > is it okay for the .probe() function for the driver to use > device_create_file() to add a 'rate_statistics' file which dumps out > some data rate statistics in ASCII form? > > I was under the impression that > device_create_file()/device_remove_file() were okay to use at probe > time. device_add_attributes()/device_remove_attributes() are only > wrappers around device_create_file()/device_remove_file() with error > checking and unwinding when things go wrong. > > Am I incorrect here? You are probing an existing "struct device", and then create attributes at this device when the probe succeeds? If yes, why don't you create a new child "struct device" with your functionality and add the attributes there? The new child device can just add the attributes by its default attributes, and all files will properly exist at event time, and the device probing result will be properly advertised with an uevent of the child device to userspace. That would be the way the core and userspace expect device probes to look like, if there are no special reasons that prevent this model from working, which should be properly documented, so nobody just copies that code without the need for such hacks. Thanks, Kay