static int asus_oled_probe(struct usb_interface *interface, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(interface); struct asus_oled_dev *odev = NULL; int retval = -ENOMEM; odev = kzalloc(sizeof(struct asus_oled_dev), GFP_KERNEL); if (odev == NULL) { dev_err(&interface->dev, "Out of memory\n"); goto error_mem; } odev->udev = usb_get_dev(udev); odev->pic_mode = ASUS_OLED_STATIC; odev->height = 0; odev->width = 0; odev->x_shift = 0; odev->y_shift = 0; odev->buf_offs = 0; odev->buf_size = 0; odev->last_val = 0; odev->buf = NULL; usb_set_intfdata (interface, odev); if ((retval = device_create_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(enabled)))) { device_remove_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(enabled)); goto error; } if ((retval = device_create_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(picture)))) { device_remove_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(picture)); goto error; } dev_info(&interface->dev, "Attached Asus OLED device\n"); if (start_off) enable_oled(odev, 0); return 0; error: usb_set_intfdata (interface, NULL); usb_put_dev(odev->udev); kfree(odev); error_mem: return retval; }
static void asus_oled_disconnect(struct usb_interface *interface) { struct asus_oled_dev *odev; odev = usb_get_intfdata (interface); usb_set_intfdata (interface, NULL); device_remove_file(&interface->dev, & ASUS_OLED_DEVICE_ATTR(picture)); device_remove_file(&interface->dev, & ASUS_OLED_DEVICE_ATTR(enabled)); usb_put_dev(odev->udev); if (odev->buf) kfree(odev->buf); kfree(odev); dev_info(&interface->dev, "Disconnected Asus OLED device\n"); }
static int asus_oled_probe(struct usb_interface *interface, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(interface); struct asus_oled_dev *odev = NULL; int retval = -ENOMEM; uint16_t dev_width = 0; enum oled_pack_mode pack_mode = PACK_MODE_LAST; const struct oled_dev_desc_str *dev_desc = oled_dev_desc_table; const char *desc = NULL; if (!id) { /* Even possible? Just to make sure...*/ dev_err(&interface->dev, "No usb_device_id provided!\n"); return -ENODEV; } for (; dev_desc->idVendor; dev_desc++) { if (dev_desc->idVendor == id->idVendor && dev_desc->idProduct == id->idProduct) { dev_width = dev_desc->devWidth; desc = dev_desc->devDesc; pack_mode = dev_desc->packMode; break; } } if (!desc || dev_width < 1 || pack_mode == PACK_MODE_LAST) { dev_err(&interface->dev, "Missing or incomplete device description!\n"); return -ENODEV; } odev = kzalloc(sizeof(struct asus_oled_dev), GFP_KERNEL); if (odev == NULL) { dev_err(&interface->dev, "Out of memory\n"); return -ENOMEM; } odev->udev = usb_get_dev(udev); odev->pic_mode = ASUS_OLED_STATIC; odev->dev_width = dev_width; odev->pack_mode = pack_mode; odev->height = 0; odev->width = 0; odev->x_shift = 0; odev->y_shift = 0; odev->buf_offs = 0; odev->buf_size = 0; odev->last_val = 0; odev->buf = NULL; odev->enabled = 1; odev->dev = NULL; usb_set_intfdata(interface, odev); retval = device_create_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(enabled)); if (retval) goto err_files; retval = device_create_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(picture)); if (retval) goto err_files; odev->dev = device_create(oled_class, &interface->dev, MKDEV(0, 0), NULL, "oled_%d", ++oled_num); if (IS_ERR(odev->dev)) { retval = PTR_ERR(odev->dev); goto err_files; } dev_set_drvdata(odev->dev, odev); retval = device_create_file(odev->dev, &dev_attr_enabled); if (retval) goto err_class_enabled; retval = device_create_file(odev->dev, &dev_attr_picture); if (retval) goto err_class_picture; dev_info(&interface->dev, "Attached Asus OLED device: %s [width %u, pack_mode %d]\n", desc, odev->dev_width, odev->pack_mode); if (start_off) enable_oled(odev, 0); return 0; err_class_picture: device_remove_file(odev->dev, &dev_attr_picture); err_class_enabled: device_remove_file(odev->dev, &dev_attr_enabled); device_unregister(odev->dev); err_files: device_remove_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(enabled)); device_remove_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(picture)); usb_set_intfdata(interface, NULL); usb_put_dev(odev->udev); kfree(odev); return retval; }