Sarah Bailey wrote:
> --- a/drivers/usb/core/endpoint_fops.c
> +++ b/drivers/usb/core/endpoint_fops.c
[...]
> @@ -21,15 +23,123 @@ int endpoint_open(struct inode *inode, struct file *filp)
>       return 0;
>  }
>  
> +void callback(struct urb *urb)

You should declare this static.

[...]
>  ssize_t control_read(struct file * filp, char __user *buff,
>               size_t count, loff_t * offp)
>  {
>       struct ep_device *ep_dev;
>       ep_dev = filp->private_data;
> -     dev_dbg(&ep_dev->dev, "%s called for %s\n", __FUNCTION__, 
> ep_dev->dev.bus_id);
> +     dev_dbg(&ep_dev->dev, "%s called for %s\n", __FUNCTION__,
> +                     ep_dev->dev.bus_id);

This looks like an unrelated whitespace change.

[...]
> +ssize_t ep_read(struct file * filp, char __user *buff,
> +             size_t count, loff_t * offp)

To parallel endpoint_open, how about endpoint_read, rather than ep_read?
Also, you should declare this static.

> +{
> +     struct ep_device *ep_dev;
> +     char *k_buff;
> +     struct urb *urb;
> +     unsigned int pipe;
> +     int retval = -ENOMEM;
> +     DECLARE_COMPLETION_ONSTACK(completion);
> +
> +     ep_dev = filp->private_data;
> +     dev_dbg(&ep_dev->dev, "%s called for %s\n", __FUNCTION__,
> +                     ep_dev->dev.bus_id);
> +
> +     if(!usb_endpoint_xfer_bulk(ep_dev->desc))
> +             return 0;
> +
> +     k_buff = kmalloc(count, GFP_KERNEL);
> +     if(k_buff == NULL)
> +             goto exit;
> +     urb = usb_alloc_urb(0, GFP_KERNEL);
> +     if(urb == NULL)
> +             goto error_urb_alloc;
> +     pipe = usb_rcvbulkpipe(ep_dev->udev, ep_dev->desc->bEndpointAddress);
> +     usb_fill_bulk_urb(urb, ep_dev->udev, pipe, k_buff, count,
> +                     callback, &completion);
> +     retval = usb_submit_urb(urb, GFP_KERNEL);
> +     if(retval)
> +             goto error_urb_submit;
> +     wait_for_completion(&completion);
> +
> +     if(urb->status)
> +             retval = urb->status;
> +     else {
> +             retval = urb->actual_length;
> +             if(copy_to_user(buff, k_buff, urb->actual_length))
> +                     retval = -EFAULT;
> +     }
> +
> +error_urb_submit:
> +     usb_free_urb(urb);
> +error_urb_alloc:
> +     kfree(k_buff);
> +exit:
> +     return retval;
> +}

This code looks good to me.

> +ssize_t ep_write(struct file * filp, const char __user *buff,
> +             size_t count, loff_t * offp)

To parallel endpoint_open, how about endpoint_write, rather than ep_write?
Also, you should declare this static.

> +{
> +     struct ep_device *ep_dev;
> +     char *k_buff;
> +     struct urb *urb;
> +     unsigned int pipe;
> +     int retval;
> +     DECLARE_COMPLETION_ONSTACK(completion);
> +
> +     ep_dev = filp->private_data;
> +     dev_dbg(&ep_dev->dev, "%s called for %s\n", __FUNCTION__,
> +                     ep_dev->dev.bus_id);
> +
> +     if(!usb_endpoint_xfer_bulk(ep_dev->desc))
> +             return 0;
> +
> +     k_buff = kmalloc(count, GFP_KERNEL);
> +     if(k_buff == NULL) {
> +             retval = -ENOMEM;
> +             goto exit;
> +     }
> +     if(copy_from_user(k_buff, buff, count)) {
> +             retval = -EFAULT;
> +             goto error_copy_buff;
> +     }
> +     urb = usb_alloc_urb(0, GFP_KERNEL);
> +     if(urb == NULL) {
> +             retval = -ENOMEM;
> +             goto error_copy_buff;
> +     }
> +
> +     // endpoint specific init
> +     pipe = usb_sndbulkpipe(ep_dev->udev, ep_dev->desc->bEndpointAddress);
> +     usb_fill_bulk_urb(urb, ep_dev->udev, pipe, k_buff, count,
> +                     callback, &completion);
> +
> +     retval = usb_submit_urb(urb, GFP_KERNEL);
> +     if(retval)
> +             goto error_urb_submit;
> +     wait_for_completion(&completion);
> +
> +     if(urb->status)
> +             retval = urb->status;
> +     else
> +             retval = urb->actual_length;
> +
> +error_urb_submit:
> +     usb_free_urb(urb);
> +error_copy_buff:
> +     kfree(k_buff);
> +exit:
> +     return retval;
> +}

This also looks good to me.

[...]
> @@ -39,9 +149,11 @@ struct file_operations usb_endpoint_control_fops = {
>  struct file_operations usb_endpoint_in_fops = {
>       .owner =        THIS_MODULE,
>       .open =         endpoint_open,
> +     .read =         ep_read,

If you change the name as suggested above, you'll need to change it here too.

>  };
>  
>  struct file_operations usb_endpoint_out_fops = {
>       .owner =        THIS_MODULE,
>       .open =         endpoint_open,
> +     .write =        ep_write,
>  };

Likewise.

- Josh Triplett

Attachment: signature.asc
Description: OpenPGP digital signature

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to