title: Why is my kernel module throwing "broken pipe" errors when I try to write to a device?
body: <p>I am currently in the process of writing a Linux kernel module in C. The module provides an extremely basic driver for a USB light (the device consists of three colored LEDs). I have managed to get the driver to load and unload without problems and also create the device (<code>/dev/wn0</code>, <code>/dev/wn1</code>, etc.). However, I keep getting errors when attempting to write to the device:</p>
  
  <pre><code>$ echo "1" &gt;/dev/wn0
  bash: echo: write error: Broken pipe
  </code></pre>
  
  <p>The entire code for the module is <a href="https://github.com/nathan-osman/Webmail-Notifier-Linux-Driver/blob/master/webmail_notifier.c" rel="nofollow">here</a>. However, the interesting part is the <code>wn_set_color()</code> function:</p>
  
  <pre><code>/* Create the data buffer to be sent to the device. */
  u8 buf[8] = {
      red, green, blue, 0, 0, 0, 0x1F, 0x05
  };
  
  /* Send the data to the device. */
  return usb_control_msg(udev,
                         usb_sndctrlpipe(udev, 0),
                         0, 0, 0, 0,
                         buf, 8, 0);
  </code></pre>
  
  <p>For some reason, it returns <code>-32</code> instead of sending the data to the device.</p>
  
  <p>I am completely new to Linux kernel programming so I'm likely doing something silly. If you can shed some light on this at all, it would be greatly appreciated.</p>
  
  <hr>
  
  <p><strong>Edit:</strong> here is some further information:</p>
  
  <ul>
  <li><p><code>lsusb -v</code> output is <a href="https://github.com/nathan-osman/Webmail-Notifier-Linux-Driver/blob/7c6d510af86b85a2fbc73dc095e1d2fad03e30d2/lsusb.txt" rel="nofollow">here</a></p></li>
  <li><p>the <code>bDescriptorType</code> member of the <code>usb_endpoint_descriptor</code> class contains '5' for the single endpoint exposed by the device (<code>bEndpointAddress</code> is <code>129</code> - or <code>0x81</code> in hex)</p></li>
  <li><p><a href="http://i.stack.imgur.com/KbyZd.png" rel="nofollow">here</a> is a screengrab of one of the control URBs sent to the device</p></li>
  </ul>