From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933008AbcFOOou (ORCPT ); Wed, 15 Jun 2016 10:44:50 -0400 Received: from schorsch-tech.de ([5.9.96.165]:45592 "EHLO schorsch-tech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753426AbcFOOot (ORCPT ); Wed, 15 Jun 2016 10:44:49 -0400 X-Greylist: delayed 539 seconds by postgrey-1.27 at vger.kernel.org; Wed, 15 Jun 2016 10:44:49 EDT Message-ID: <28aa038c8879b4cafcbaff669f603b19.squirrel@wm.schorsch-tech.de> Date: Wed, 15 Jun 2016 16:35:28 +0200 Subject: sysfs_create_group(): Where to call? From: georg@schorsch-tech.de To: linux-kernel@vger.kernel.org User-Agent: SquirrelMail/1.4.23 [SVN] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7BIT X-Priority: 3 (Normal) Importance: Normal Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, currently i write an driver module which offers some entries in the sysfs. I read a lot through the driver source tree and the internet. I found two approches where the sysfs_create_group() is called: a) most commonly: In the probe() function of the Driver. Like adviced here http://stackoverflow.com/questions/37237835/how-to-attach-file-operations-to-sysfs-attribute-in-platform-driver Random Thing i looked at: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/rtc/rtc-ds1307.c#n1580 b) In the driver struct. http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/ I know, Greg KH is a very well known developer. So i tried to follow his advice. In the bla_show()/bla_store() functions i tried to get my Driver private data, but my printk()'s showed much different addresses than i printed in the probe() function. My private data is (null). Which is ofc wrong. When i use approch a) it works as expected, but as Greg KH suggests it is wrong too. I see it a lot in the stable tree in different Drivers. Greg writes, the userspace already got the notification that there is a new device, but the LDD3 book states, that the probe function is there to determine if the device is present. So why get the userspace notified about it, even when the kernel doesnt know if it can handle it? LDD3: https://static.lwn.net/images/pdf/LDD3/ch14.pdf PDF page 24 [Quote=LDD3 chapter 14] probe is a function called to query the existence of a specific device (and whether this driver can work with it), remove is called when the device is removed from the system,and shutdown is called at shutdown time to quiesce the device. [/Quote] I know, Greg KH is a very well known developer. So i tried to follow his advice. In the bla_show()/bla_store() functions i tried to get my Driver private data, but my printk()'s showed much different addresses than i printed in the probe() function. My private data is (null). Which is ofc wrong. When i use approch a) it works as expected, but as Greg KH suggests it is wrong too. I see it a lot in the stable tree in different drivers. Greg writes, the userspace already got the notification that there is a new device, but the LDD3 book states, that the probe function is there to determine if the device is present. To sum my question up: 1.Why get the userspace notified about it, even when the kernel doesnt know if it can handle it? 2.Where is the right place to call sysfs_create_group()? Is it a) or b) ? I am more confused than before ..... Best Regards Georg