title: How do you link a device to a custom sysfs class?
body: <p>I'm writing drivers for several pieces of custom hardware.  All of the devices are attached via PCIe to a host computer. For convenience I would like to group all of these custom devices together into a sysfs class (which I believe is an acceptable thing to do?). Unfortunately the information in LDD3 is way out of date and I'm having trouble finding current documentation that discusses what I'm attempting to do.</p>
  
  <p>Creating my custom class is easy enough:</p>
  
  <pre><code>struct class MY_CLASS = class_create(THIS_MODULE, "myclass")
  </code></pre>
  
  <p>And inside of my probe calls I've got access to the <code>struct dev</code>:</p>
  
  <pre><code>static int probe(struct pci_dev *pcidev, const struct pci_device_id *id)
  {
      ...
  
      struct dev *my_dev = &amp;pcidev-&gt;dev;
  
      ...
  }
  </code></pre>
  
  <p>My question is this: now that I've got the class and the dev, how do I create a link between the two?</p>
  
  <p>The <code>device_create()</code> basically does what I want, but since I've already got a <code>struct dev</code> my understanding is that I shouldn't call <code>device_create</code> (i.e. create a new device) again.</p>
  
  <p>I've done a little more tracing and found that <code>device_add()</code> which is called by <code>device_create()</code>, calls <code>device_add_class_symlinks()</code> (not exported unfortunately) which does something like this:</p>
  
  <pre><code>...
  sysfs_create_link(&amp;dev-&gt;class-&gt;p-&gt;subsys.kobj,&amp;dev-&gt;kobj, dev_name(dev));
  ...
  </code></pre>
  
  <p>I tried something like this directly in my drivers to create the links I want but I can't get it to compile because <code>struct subsys_private</code> (the "p" member in the class struct) is not exposed anywhere?</p>
  
  <p>Any help is greatly appreciated! </p>