static int hostaudio_open(struct inode *inode, struct file *file) { struct hostaudio_state *state; int r = 0, w = 0; int ret; #ifdef DEBUG kparam_block_sysfs_write(dsp); printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp); kparam_unblock_sysfs_write(dsp); #endif state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL); if (state == NULL) return -ENOMEM; if (file->f_mode & FMODE_READ) r = 1; if (file->f_mode & FMODE_WRITE) w = 1; kparam_block_sysfs_write(dsp); lock_kernel(); ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0); unlock_kernel(); kparam_unblock_sysfs_write(dsp); if (ret < 0) { kfree(state); return ret; } state->fd = ret; file->private_data = state; return 0; }
static int hostmixer_open_mixdev(struct inode *inode, struct file *file) { struct hostmixer_state *state; int r = 0, w = 0; int ret; #ifdef DEBUG printk(KERN_DEBUG "hostmixer: open called (host: %s)\n", mixer); #endif state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL); if (state == NULL) return -ENOMEM; if (file->f_mode & FMODE_READ) r = 1; if (file->f_mode & FMODE_WRITE) w = 1; kparam_block_sysfs_write(mixer); mutex_lock(&hostaudio_mutex); ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0); mutex_unlock(&hostaudio_mutex); kparam_unblock_sysfs_write(mixer); if (ret < 0) { kparam_block_sysfs_write(dsp); printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', " "err = %d\n", dsp, -ret); kparam_unblock_sysfs_write(dsp); kfree(state); return ret; } file->private_data = state; return 0; }
/** * if_usb_probe - sets the configuration values * @intf: &usb_interface pointer * @id: pointer to usb_device_id * returns: 0 on success, error code on failure */ static int if_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *udev; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; struct lbs_private *priv; struct if_usb_card *cardp; int i; udev = interface_to_usbdev(intf); cardp = kzalloc(sizeof(struct if_usb_card), GFP_KERNEL); if (!cardp) goto error; setup_timer(&cardp->fw_timeout, if_usb_fw_timeo, (unsigned long)cardp); init_waitqueue_head(&cardp->fw_wq); cardp->udev = udev; cardp->model = (uint32_t) id->driver_info; iface_desc = intf->cur_altsetting; lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X" " bDeviceSubClass = 0x%X, bDeviceProtocol = 0x%X\n", le16_to_cpu(udev->descriptor.bcdUSB), udev->descriptor.bDeviceClass, udev->descriptor.bDeviceSubClass, udev->descriptor.bDeviceProtocol); for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { endpoint = &iface_desc->endpoint[i].desc; if (usb_endpoint_is_bulk_in(endpoint)) { cardp->ep_in_size = le16_to_cpu(endpoint->wMaxPacketSize); cardp->ep_in = usb_endpoint_num(endpoint); lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n", cardp->ep_in); lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n", cardp->ep_in_size); } else if (usb_endpoint_is_bulk_out(endpoint)) { cardp->ep_out_size = le16_to_cpu(endpoint->wMaxPacketSize); cardp->ep_out = usb_endpoint_num(endpoint); lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n", cardp->ep_out); lbs_deb_usbd(&udev->dev, "Bulk out size is %d\n", cardp->ep_out_size); } } if (!cardp->ep_out_size || !cardp->ep_in_size) { lbs_deb_usbd(&udev->dev, "Endpoints not found\n"); goto dealloc; } if (!(cardp->rx_urb = usb_alloc_urb(0, GFP_KERNEL))) { lbs_deb_usbd(&udev->dev, "Rx URB allocation failed\n"); goto dealloc; } if (!(cardp->tx_urb = usb_alloc_urb(0, GFP_KERNEL))) { lbs_deb_usbd(&udev->dev, "Tx URB allocation failed\n"); goto dealloc; } cardp->ep_out_buf = kmalloc(MRVDRV_ETH_TX_PACKET_BUFFER_SIZE, GFP_KERNEL); if (!cardp->ep_out_buf) { lbs_deb_usbd(&udev->dev, "Could not allocate buffer\n"); goto dealloc; } /* Upload firmware */ kparam_block_sysfs_write(fw_name); if (__if_usb_prog_firmware(cardp, lbs_fw_name, BOOT_CMD_FW_BY_USB)) { kparam_unblock_sysfs_write(fw_name); lbs_deb_usbd(&udev->dev, "FW upload failed\n"); goto err_prog_firmware; } kparam_unblock_sysfs_write(fw_name); if (!(priv = lbs_add_card(cardp, &intf->dev))) goto err_prog_firmware; cardp->priv = priv; cardp->priv->fw_ready = 1; priv->hw_host_to_card = if_usb_host_to_card; priv->enter_deep_sleep = NULL; priv->exit_deep_sleep = NULL; priv->reset_deep_sleep_wakeup = NULL; #ifdef CONFIG_OLPC if (machine_is_olpc()) priv->reset_card = if_usb_reset_olpc_card; #endif cardp->boot2_version = udev->descriptor.bcdDevice; if_usb_submit_rx_urb(cardp); if (lbs_start_card(priv)) goto err_start_card; if_usb_setup_firmware(priv); usb_get_dev(udev); usb_set_intfdata(intf, cardp); if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_fw)) netdev_err(priv->dev, "cannot register lbs_flash_fw attribute\n"); if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_boot2)) netdev_err(priv->dev, "cannot register lbs_flash_boot2 attribute\n"); /* * EHS_REMOVE_WAKEUP is not supported on all versions of the firmware. */ priv->wol_criteria = EHS_REMOVE_WAKEUP; if (lbs_host_sleep_cfg(priv, priv->wol_criteria, NULL)) priv->ehs_remove_supported = false; return 0; err_start_card: lbs_remove_card(priv); err_prog_firmware: if_usb_reset_device(cardp); dealloc: if_usb_free(cardp); error: return -ENOMEM; }