From: Ao Xu Date: Mon, 25 Dec 2017 08:19:30 +0000 (+0800) Subject: USB: gadget: add mtp 32bit ioctl support X-Git-Tag: khadas-vims-v0.9.6-release~2623 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c80085b5b78a7cf7a8887cd5eac6213c9fdc7a0;p=platform%2Fkernel%2Flinux-amlogic.git USB: gadget: add mtp 32bit ioctl support PD#156196: USB: gadget: add mtp 32bit ioctl support Change-Id: Ic83ca7f6b6736070e8ac435630a16a5a80014922 Signed-off-by: Ao Xu --- diff --git a/drivers/usb/gadget/function/f_mtp.c b/drivers/usb/gadget/function/f_mtp.c index 54f7ebb..bbbe1cb 100644 --- a/drivers/usb/gadget/function/f_mtp.c +++ b/drivers/usb/gadget/function/f_mtp.c @@ -1042,6 +1042,51 @@ out: return ret; } +#ifdef CONFIG_AMLOGIC_USB +#ifdef CONFIG_COMPAT + +struct mtp_event_compat { + compat_size_t length; + compat_uptr_t data; +}; + +#define COMPAT_MTP_SEND_EVENT _IOW('M', 3, struct mtp_event_compat) + +static long mtp_compat_ioctl(struct file *fp, + unsigned int cmd, + unsigned long arg) +{ + if (cmd == COMPAT_MTP_SEND_EVENT) { + struct mtp_event event; + struct mtp_event_compat event_compat; + struct mtp_dev *dev = fp->private_data; + int ret = -EINVAL; + + if (mtp_lock(&dev->ioctl_excl)) + return -EBUSY; + + memset(&event, 0, sizeof(event)); + memset(&event_compat, 0, sizeof(event_compat)); + + if (copy_from_user(&event_compat, + (void __user *)arg, sizeof(event_compat))) + ret = -EFAULT; + else { + event.length = event_compat.length; + event.data = compat_ptr(event_compat.data); + + ret = mtp_send_event(dev, &event); + } + mtp_unlock(&dev->ioctl_excl); + DBG(dev->cdev, "ioctl returning %d\n", ret); + return ret; + } else + return mtp_ioctl(fp, cmd, + (unsigned long) compat_ptr(arg)); +} +#endif +#endif + static int mtp_open(struct inode *ip, struct file *fp) { printk(KERN_INFO "mtp_open\n"); @@ -1070,6 +1115,11 @@ static const struct file_operations mtp_fops = { .read = mtp_read, .write = mtp_write, .unlocked_ioctl = mtp_ioctl, +#ifdef CONFIG_AMLOGIC_USB +#ifdef CONFIG_COMPAT + .compat_ioctl = mtp_compat_ioctl, +#endif +#endif .open = mtp_open, .release = mtp_release, };