From: R. Steve McKown Date: Fri, 14 May 2010 20:07:16 +0000 (-0600) Subject: Fix warnings generated by sparse tool. X-Git-Tag: debian/0.11.3-3tmi~14 X-Git-Url: https://oss.titaniummirror.com/gitweb?p=cp210x.git;a=commitdiff_plain;h=79c062bcfe6b86d99a1a0bfe17c148ecc2c9b252 Fix warnings generated by sparse tool. --- diff --git a/src/cp210x.c b/src/cp210x.c index 9ce96f4..e89ed3c 100644 --- a/src/cp210x.c +++ b/src/cp210x.c @@ -279,11 +279,13 @@ static size_t copy_buf_from_user(char *kbuf, unsigned long ubuf, size_t klen) cp210x_buffer_t t; if (!kbuf || !ubuf || !klen || - copy_from_user(&t, (cp210x_buffer_t *)ubuf, sizeof(t))) + copy_from_user(&t, (cp210x_buffer_t __user *)ubuf, + sizeof(t))) return 0; if (t.len < klen) klen = t.len; - if (!t.buf || !t.len || copy_from_user(kbuf, t.buf, klen)) + if (!t.buf || !t.len || + copy_from_user(kbuf, (char __user *)t.buf, klen)) return 0; return klen; } @@ -332,7 +334,7 @@ static int cp210x_reset(struct usb_serial_port *port) * connections are torn down. We also ignore the error return, since * the part resets and doesn't send one... */ - cp210x_ctlmsg(port, 0xff, 0x40, 0x0008, 0x00, 0, 0); + cp210x_ctlmsg(port, 0xff, 0x40, 0x0008, 0x00, NULL, 0); #else usb_reset_device(port->serial->dev); #endif @@ -366,7 +368,7 @@ static inline int cp210x_setu16(struct usb_serial_port *port, int cmd, unsigned int value) { return cp210x_ctlmsg(port, 0xff, 0x40, 0x3700 | (cmd & 0xff), - value, 0, 0); + value, NULL, 0); } /* Populates usbstr with: (len) + (0x03) + unicode(str). Each char in str @@ -424,7 +426,7 @@ static int cp210x_gpioset(struct usb_serial_port *port, u8 gpio) dbg("%s - port %d, gpio = 0x%.2x", __FUNCTION__, port->number, gpio); return cp210x_ctlmsg(port, 0xff, 0x40, 0x37e1, - ((uint16_t)gpio << 8) | GPIO_MASK, 0, 0); + ((uint16_t)gpio << 8) | GPIO_MASK, NULL, 0); } /* Set select gpio bits */ @@ -453,7 +455,7 @@ static int cp210x_gpiosetb(struct usb_serial_port *port, u8 set, u8 clear) dbg("%s - port %d, gpiob = 0x%.4x", __FUNCTION__, port->number, gpio); /* FIXME: how about REQTYPE_HOST_TO_DEVICE instead of 0x40? */ - return cp210x_ctlmsg(port, 0xff, 0x40, 0x37e1, gpio, 0, 0); + return cp210x_ctlmsg(port, 0xff, 0x40, 0x37e1, gpio, NULL, 0); } static int cp210x_gpioget(struct usb_serial_port *port, u8 *gpio) @@ -716,7 +718,7 @@ static int cp210x_ioctl(struct usb_serial_port *port, struct file *file, case TIOCMGET: { int result = cp210x_tiocmget(port, file); - if (copy_to_user(&arg, &result, sizeof(int))) + if (copy_to_user((int __user *)&arg, &result, sizeof(int))) return -EFAULT; return 0; } @@ -724,12 +726,11 @@ static int cp210x_ioctl(struct usb_serial_port *port, struct file *file, case TIOCMSET: case TIOCMBIS: - case TIOCMBIC: { int val = 0; - if (copy_from_user(&val, &arg, sizeof(int))) + if (copy_from_user(&val, (int __user *)&arg, sizeof(int))) return -EFAULT; /* this looks wrong: TIOCMSET isn't going to work right */ @@ -743,8 +744,8 @@ static int cp210x_ioctl(struct usb_serial_port *port, struct file *file, case IOCTL_GPIOGET: if (cp210x_get_partnum(port) == CP210x_CP2103_VERSION) { u8 gpio = 0; - if (!cp210x_gpioget(port, &gpio) && !copy_to_user((u8*)arg, - &gpio, sizeof(gpio))) + if (!cp210x_gpioget(port, &gpio) && !copy_to_user( + (u8 __user *)arg, &gpio, sizeof(gpio))) return 0; } return -EFAULT; @@ -774,8 +775,8 @@ static int cp210x_ioctl(struct usb_serial_port *port, struct file *file, { cp210x_port_config_t config; if (!cp210x_portconfget(port, &config) && !copy_to_user( - (cp210x_port_config_t*)arg, &config, - sizeof(config))) + (cp210x_port_config_t __user *)arg, + &config, sizeof(config))) return 0; } return -EFAULT; @@ -784,7 +785,7 @@ static int cp210x_ioctl(struct usb_serial_port *port, struct file *file, case IOCTL_PORTCONFSET: { cp210x_port_config_t config; - if (!copy_from_user(&config, (cp210x_port_config_t*)arg, + if (!copy_from_user(&config, (cp210x_port_config_t __user *)arg, sizeof(config)) && !cp210x_portconfset(port, &config)) return 0; @@ -795,7 +796,7 @@ static int cp210x_ioctl(struct usb_serial_port *port, struct file *file, case IOCTL_SETVID: { unsigned int vid; - if (!copy_from_user(&vid, (unsigned int *)arg, + if (!copy_from_user(&vid, (unsigned int __user *)arg, sizeof(unsigned int)) && !cp210x_setu16(port, 0x01, vid)) return 0; @@ -806,7 +807,7 @@ static int cp210x_ioctl(struct usb_serial_port *port, struct file *file, case IOCTL_SETPID: { unsigned int pid; - if (!copy_from_user(&pid, (unsigned int *)arg, + if (!copy_from_user(&pid, (unsigned int __user *)arg, sizeof(unsigned int)) && !cp210x_setu16(port, 0x02, pid)) return 0; @@ -858,7 +859,7 @@ static int cp210x_ioctl(struct usb_serial_port *port, struct file *file, case IOCTL_SETDEVVER: { unsigned int ver; - if (!copy_from_user(&ver, (unsigned int *)arg, + if (!copy_from_user(&ver, (unsigned int __user *)arg, sizeof(unsigned int)) && !cp210x_setu16(port, 0x07, ver)) return 0; diff --git a/src/cp210x.c.karmic b/src/cp210x.c.karmic index 60eb517..831a0f4 100644 --- a/src/cp210x.c.karmic +++ b/src/cp210x.c.karmic @@ -300,11 +300,13 @@ static size_t copy_buf_from_user(char *kbuf, unsigned long ubuf, size_t klen) cp210x_buffer_t t; if (!kbuf || !ubuf || !klen || - copy_from_user(&t, (cp210x_buffer_t *)ubuf, sizeof(t))) + copy_from_user(&t, (cp210x_buffer_t __user *)ubuf, + sizeof(t))) return 0; if (t.len < klen) klen = t.len; - if (!t.buf || !t.len || copy_from_user(kbuf, t.buf, klen)) + if (!t.buf || !t.len || + copy_from_user(kbuf, (char __user *)t.buf, klen)) return 0; return klen; } @@ -353,7 +355,7 @@ static int cp210x_reset(struct usb_serial_port *port) * connections are torn down. We also ignore the error return, since * the part resets and doesn't send one... */ - cp210x_ctlmsg(port, 0xff, 0x40, 0x0008, 0x00, 0, 0); + cp210x_ctlmsg(port, 0xff, 0x40, 0x0008, 0x00, NULL, 0); #else usb_reset_device(port->serial->dev); #endif @@ -387,7 +389,7 @@ static inline int cp210x_setu16(struct usb_serial_port *port, int cmd, unsigned int value) { return cp210x_ctlmsg(port, 0xff, 0x40, 0x3700 | (cmd & 0xff), - value, 0, 0); + value, NULL, 0); } /* Populates usbstr with: (len) + (0x03) + unicode(str). Each char in str @@ -445,7 +447,7 @@ static int cp210x_gpioset(struct usb_serial_port *port, u8 gpio) dbg("%s - port %d, gpio = 0x%.2x", __FUNCTION__, port->number, gpio); return cp210x_ctlmsg(port, 0xff, 0x40, 0x37e1, - ((uint16_t)gpio << 8) | GPIO_MASK, 0, 0); + ((uint16_t)gpio << 8) | GPIO_MASK, NULL, 0); } /* Set select gpio bits */ @@ -474,7 +476,7 @@ static int cp210x_gpiosetb(struct usb_serial_port *port, u8 set, u8 clear) dbg("%s - port %d, gpiob = 0x%.4x", __FUNCTION__, port->number, gpio); /* FIXME: how about REQTYPE_HOST_TO_DEVICE instead of 0x40? */ - return cp210x_ctlmsg(port, 0xff, 0x40, 0x37e1, gpio, 0, 0); + return cp210x_ctlmsg(port, 0xff, 0x40, 0x37e1, gpio, NULL, 0); } static int cp210x_gpioget(struct usb_serial_port *port, u8 *gpio) @@ -783,7 +785,7 @@ static int cp210x_ioctl(struct tty_struct *tty, struct file *file, case TIOCMGET: { int result = cp210x_tiocmget(tty, file); - if (copy_to_user(&arg, &result, sizeof(int))) + if (copy_to_user((int __user *)&arg, &result, sizeof(int))) return -EFAULT; return 0; } @@ -791,12 +793,11 @@ static int cp210x_ioctl(struct tty_struct *tty, struct file *file, case TIOCMSET: case TIOCMBIS: - case TIOCMBIC: { int val = 0; - if (copy_from_user(&val, &arg, sizeof(int))) + if (copy_from_user(&val, (int __user *)&arg, sizeof(int))) return -EFAULT; /* this looks wrong: TIOCMSET isn't going to work right */ @@ -810,8 +811,8 @@ static int cp210x_ioctl(struct tty_struct *tty, struct file *file, case IOCTL_GPIOGET: if (cp210x_get_partnum(port) == CP210x_CP2103_VERSION) { u8 gpio = 0; - if (!cp210x_gpioget(port, &gpio) && !copy_to_user((u8*)arg, - &gpio, sizeof(gpio))) + if (!cp210x_gpioget(port, &gpio) && !copy_to_user( + (u8 __user *)arg, &gpio, sizeof(gpio))) return 0; } return -EFAULT; @@ -841,8 +842,8 @@ static int cp210x_ioctl(struct tty_struct *tty, struct file *file, { cp210x_port_config_t config; if (!cp210x_portconfget(port, &config) && !copy_to_user( - (cp210x_port_config_t*)arg, &config, - sizeof(config))) + (cp210x_port_config_t __user *)arg, + &config, sizeof(config))) return 0; } return -EFAULT; @@ -851,7 +852,7 @@ static int cp210x_ioctl(struct tty_struct *tty, struct file *file, case IOCTL_PORTCONFSET: { cp210x_port_config_t config; - if (!copy_from_user(&config, (cp210x_port_config_t*)arg, + if (!copy_from_user(&config, (cp210x_port_config_t __user *)arg, sizeof(config)) && !cp210x_portconfset(port, &config)) return 0; @@ -862,7 +863,7 @@ static int cp210x_ioctl(struct tty_struct *tty, struct file *file, case IOCTL_SETVID: { unsigned int vid; - if (!copy_from_user(&vid, (unsigned int *)arg, + if (!copy_from_user(&vid, (unsigned int __user *)arg, sizeof(unsigned int)) && !cp210x_setu16(port, 0x01, vid)) return 0; @@ -873,7 +874,7 @@ static int cp210x_ioctl(struct tty_struct *tty, struct file *file, case IOCTL_SETPID: { unsigned int pid; - if (!copy_from_user(&pid, (unsigned int *)arg, + if (!copy_from_user(&pid, (unsigned int __user *)arg, sizeof(unsigned int)) && !cp210x_setu16(port, 0x02, pid)) return 0; @@ -925,7 +926,7 @@ static int cp210x_ioctl(struct tty_struct *tty, struct file *file, case IOCTL_SETDEVVER: { unsigned int ver; - if (!copy_from_user(&ver, (unsigned int *)arg, + if (!copy_from_user(&ver, (unsigned int __user *)arg, sizeof(unsigned int)) && !cp210x_setu16(port, 0x07, ver)) return 0;