title: sysfs_create_group(): Where to call?
body: <p>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:</p>
  
  <p>a) most commonly: In the probe() function of the Driver. Like adviced here
  <a href="https://stackoverflow.com/questions/37237835/how-to-attach-file-operations-to-sysfs-attribute-in-platform-driver">How to attach file operations to sysfs attribute in platform driver?</a></p>
  
  <p>Random Thing i looked at:
  <a href="https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/rtc/rtc-ds1307.c#n1580" rel="nofollow noreferrer">https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/rtc/rtc-ds1307.c#n1580</a></p>
  
  <p>b) In the driver struct. 
  <a href="http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/" rel="nofollow noreferrer">http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/</a></p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>To sum my question up:</p>
  
  <ol>
  <li>Why get the userspace notified about it, even when the kernel doesnt know if it can handle it?</li>
  <li>Where is the right place to call sysfs_create_group()? Is it a) or b) ?</li>
  </ol>
  
  <p>LDD3: <a href="https://static.lwn.net/images/pdf/LDD3/ch14.pdf" rel="nofollow noreferrer">https://static.lwn.net/images/pdf/LDD3/ch14.pdf</a> 
  PDF page 24</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>I am more confused than before ..... </p>
  
  <p>Best Regards
  Georg</p>