Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / usb / misc / phidgetkit.c
index ace44a7..997db5d 100644 (file)
@@ -88,7 +88,7 @@ static int change_outputs(struct phidget_interfacekit *kit, int output_num, int
        int retval;
        int n;
 
-       buffer = kmalloc(4, GFP_KERNEL);
+       buffer = kzalloc(4, GFP_KERNEL);
        if (!buffer) {
                dev_err(&kit->udev->dev, "%s - out of memory\n",
                        __FUNCTION__);
@@ -96,21 +96,21 @@ static int change_outputs(struct phidget_interfacekit *kit, int output_num, int
        }
 
        kit->outputs[output_num] = enable;
-       memset(buffer, 0, 4);
        for (n=0; n<8; n++) {
                if (kit->outputs[n]) {
                        buffer[0] |= 1 << n;
                }
        }
 
-       dev_dbg(&kit->udev->dev, "data: %02x %02x\n", buffer[0], buffer[1]);
+       dev_dbg(&kit->udev->dev, "sending data: %02x\n", buffer[0]);
 
        retval = usb_control_msg(kit->udev,
                         usb_sndctrlpipe(kit->udev, 0),
-                        0x09, 0x21, 0x0200, 0x0000, buffer, 4, 2 * HZ);
+                        0x09, 0x21, 0x0200, 0x0000, buffer, 4, 2000);
 
        if (retval != 4)
-               dev_err(&kit->udev->dev, "retval = %d\n", retval);
+               dev_err(&kit->udev->dev, "usb_control_msg returned %d\n", 
+                               retval);
        kfree(buffer);
 
        return retval < 0 ? retval : 0;
@@ -158,7 +158,7 @@ static int change_string(struct phidget_interfacekit *kit, const char *display,
 
                retval = usb_control_msg(kit->udev,
                                 usb_sndctrlpipe(kit->udev, 0),
-                                0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2 * HZ);
+                                0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000);
                if (retval < 0)
                        goto exit;
        }
@@ -172,7 +172,7 @@ exit:
 }
 
 #define set_lcd_line(number)   \
-static ssize_t lcd_line_##number(struct device *dev, const char *buf, size_t count)    \
+static ssize_t lcd_line_##number(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)     \
 {                                                                                      \
        struct usb_interface *intf = to_usb_interface(dev);                             \
        struct phidget_interfacekit *kit = usb_get_intfdata(intf);                      \
@@ -183,7 +183,7 @@ static DEVICE_ATTR(lcd_line_##number, S_IWUGO, NULL, lcd_line_##number);
 set_lcd_line(1);
 set_lcd_line(2);
 
-static ssize_t set_backlight(struct device *dev, const char *buf, size_t count)
+static ssize_t set_backlight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
        struct usb_interface *intf = to_usb_interface(dev);
        struct phidget_interfacekit *kit = usb_get_intfdata(intf);
@@ -191,7 +191,7 @@ static ssize_t set_backlight(struct device *dev, const char *buf, size_t count)
        unsigned char *buffer;
        int retval = -ENOMEM;
        
-       buffer = kmalloc(8, GFP_KERNEL);
+       buffer = kzalloc(8, GFP_KERNEL);
        if (!buffer) {
                dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__);
                goto exit;
@@ -201,7 +201,6 @@ static ssize_t set_backlight(struct device *dev, const char *buf, size_t count)
                retval = -EINVAL;
                goto exit;
        }
-       memset(buffer, 0x00, 8);
        if (enabled)
                buffer[0] = 0x01;
        buffer[7] = 0x11;
@@ -210,7 +209,7 @@ static ssize_t set_backlight(struct device *dev, const char *buf, size_t count)
        
        retval = usb_control_msg(kit->udev,
                         usb_sndctrlpipe(kit->udev, 0),
-                        0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2 * HZ);
+                        0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000);
        if (retval < 0)
                goto exit;
 
@@ -231,7 +230,7 @@ static void remove_lcd_files(struct phidget_interfacekit *kit)
        }
 }
 
-static ssize_t enable_lcd_files(struct device *dev, const char *buf, size_t count)
+static ssize_t enable_lcd_files(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
        struct usb_interface *intf = to_usb_interface(dev);
        struct phidget_interfacekit *kit = usb_get_intfdata(intf);
@@ -306,7 +305,7 @@ resubmit:
 }
 
 #define show_set_output(value)         \
-static ssize_t set_output##value(struct device *dev, const char *buf,  \
+static ssize_t set_output##value(struct device *dev, struct device_attribute *attr, const char *buf,   \
                                                        size_t count)   \
 {                                                                      \
        struct usb_interface *intf = to_usb_interface(dev);             \
@@ -323,12 +322,12 @@ static ssize_t set_output##value(struct device *dev, const char *buf,     \
        return retval ? retval : count;                                 \
 }                                                                      \
                                                                        \
-static ssize_t show_output##value(struct device *dev, char *buf)       \
+static ssize_t show_output##value(struct device *dev, struct device_attribute *attr, char *buf)        \
 {                                                                      \
        struct usb_interface *intf = to_usb_interface(dev);             \
        struct phidget_interfacekit *kit = usb_get_intfdata(intf);      \
                                                                        \
-       return sprintf(buf, "%d\n", kit->outputs[value - 1 ]);          \
+       return sprintf(buf, "%d\n", kit->outputs[value - 1]);           \
 }                                                                      \
 static DEVICE_ATTR(output##value, S_IWUGO | S_IRUGO,                   \
                show_output##value, set_output##value);
@@ -342,7 +341,7 @@ show_set_output(7);
 show_set_output(8);    /* should be MAX_INTERFACES - 1 */
 
 #define show_input(value)      \
-static ssize_t show_input##value(struct device *dev, char *buf)        \
+static ssize_t show_input##value(struct device *dev, struct device_attribute *attr, char *buf) \
 {                                                                      \
        struct usb_interface *intf = to_usb_interface(dev);             \
        struct phidget_interfacekit *kit = usb_get_intfdata(intf);      \
@@ -361,7 +360,7 @@ show_input(7);
 show_input(8);         /* should be MAX_INTERFACES - 1 */
 
 #define show_sensor(value)     \
-static ssize_t show_sensor##value(struct device *dev, char *buf)       \
+static ssize_t show_sensor##value(struct device *dev, struct device_attribute *attr, char *buf)        \
 {                                                                      \
        struct usb_interface *intf = to_usb_interface(dev);             \
        struct phidget_interfacekit *kit = usb_get_intfdata(intf);      \
@@ -405,12 +404,11 @@ static int interfacekit_probe(struct usb_interface *intf, const struct usb_devic
        pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
        maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
        
-       kit = kmalloc(sizeof(*kit), GFP_KERNEL);
+       kit = kzalloc(sizeof(*kit), GFP_KERNEL);
        if (kit  == NULL) {
                dev_err(&intf->dev, "%s - out of memory\n", __FUNCTION__);
                return -ENOMEM;
        }
-       memset(kit, 0, sizeof(*kit));
        kit->ifkit = ifkit;
 
        kit->data = usb_buffer_alloc(dev, 8, SLAB_ATOMIC, &kit->data_dma);
@@ -440,11 +438,13 @@ static int interfacekit_probe(struct usb_interface *intf, const struct usb_devic
                return -EIO;
        }
 
-       if (ifkit->outputs == 8) {
+       if (ifkit->outputs >= 4) {
                device_create_file(&intf->dev, &dev_attr_output1);
                device_create_file(&intf->dev, &dev_attr_output2);
                device_create_file(&intf->dev, &dev_attr_output3);
                device_create_file(&intf->dev, &dev_attr_output4);
+       }
+       if (ifkit->outputs == 8) {
                device_create_file(&intf->dev, &dev_attr_output5);
                device_create_file(&intf->dev, &dev_attr_output6);
                device_create_file(&intf->dev, &dev_attr_output7);
@@ -483,7 +483,7 @@ static int interfacekit_probe(struct usb_interface *intf, const struct usb_devic
                device_create_file(&intf->dev, &dev_attr_lcd);
 
        dev_info(&intf->dev, "USB PhidgetInterfaceKit %d/%d/%d attached\n",
-                       ifkit->inputs, ifkit->outputs, ifkit->sensors);
+                       ifkit->sensors, ifkit->inputs, ifkit->outputs);
 
        return 0;
 }
@@ -497,15 +497,17 @@ static void interfacekit_disconnect(struct usb_interface *interface)
        if (!kit)
                return;
 
-       if (kit->ifkit->outputs == MAX_INTERFACES) {
+       if (kit->ifkit->outputs >= 4) {
                device_remove_file(&interface->dev, &dev_attr_output1);
                device_remove_file(&interface->dev, &dev_attr_output2);
                device_remove_file(&interface->dev, &dev_attr_output3);
                device_remove_file(&interface->dev, &dev_attr_output4);
+       }
+       if (kit->ifkit->outputs == 8) {
                device_remove_file(&interface->dev, &dev_attr_output5);
                device_remove_file(&interface->dev, &dev_attr_output6);
                device_remove_file(&interface->dev, &dev_attr_output7);
-               device_remove_file(&interface->dev, &dev_attr_output7);
+               device_remove_file(&interface->dev, &dev_attr_output8);
        }
 
        if (kit->ifkit->inputs >= 4) {
@@ -536,10 +538,10 @@ static void interfacekit_disconnect(struct usb_interface *interface)
                device_remove_file(&interface->dev, &dev_attr_sensor8);
        }
        if (kit->ifkit->has_lcd)
-               device_create_file(&interface->dev, &dev_attr_lcd);
+               device_remove_file(&interface->dev, &dev_attr_lcd);
 
        dev_info(&interface->dev, "USB PhidgetInterfaceKit %d/%d/%d detached\n",
-               kit->ifkit->inputs, kit->ifkit->outputs, kit->ifkit->sensors);
+               kit->ifkit->sensors, kit->ifkit->inputs, kit->ifkit->outputs);
 
        usb_kill_urb(kit->irq);
        usb_free_urb(kit->irq);
@@ -550,7 +552,6 @@ static void interfacekit_disconnect(struct usb_interface *interface)
 }
 
 static struct usb_driver interfacekit_driver = {
-       .owner = THIS_MODULE,
        .name = "phidgetkit",
        .probe = interfacekit_probe,
        .disconnect = interfacekit_disconnect,