mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
cyclades: ioctls cleanup
- add a cy_ prefix to functions with changed prototypes - cy_get_serial_info: initialize serial_struct by initializer, save a memset - inline simple functions (get_mon_info, {s,g}et_default_threshold, {s,g}et_default_timeout) directly in the ioctl handler - add a cy_cflags_changed helper to not copy its code by wait_event_interruptible - remove some ret_val = 0 assignments, it's preset to 0 - TIOCGICOUNT: don't do many put_user's, do one copy_to_user Signed-off-by: Jiri Slaby <jirislaby@gmail.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
cc7fdf49d6
commit
6c28181cf8
1 changed files with 67 additions and 112 deletions
|
@ -2411,29 +2411,25 @@ static void cy_set_line_char(struct cyclades_port *info, struct tty_struct *tty)
|
||||||
}
|
}
|
||||||
} /* set_line_char */
|
} /* set_line_char */
|
||||||
|
|
||||||
static int
|
static int cy_get_serial_info(struct cyclades_port *info,
|
||||||
get_serial_info(struct cyclades_port *info,
|
|
||||||
struct serial_struct __user *retinfo)
|
struct serial_struct __user *retinfo)
|
||||||
{
|
{
|
||||||
struct serial_struct tmp;
|
|
||||||
struct cyclades_card *cinfo = info->card;
|
struct cyclades_card *cinfo = info->card;
|
||||||
|
struct serial_struct tmp = {
|
||||||
if (!retinfo)
|
.type = info->type,
|
||||||
return -EFAULT;
|
.line = info->line,
|
||||||
memset(&tmp, 0, sizeof(tmp));
|
.port = (info->card - cy_card) * 0x100 + info->line -
|
||||||
tmp.type = info->type;
|
cinfo->first_line,
|
||||||
tmp.line = info->line;
|
.irq = cinfo->irq,
|
||||||
tmp.port = (info->card - cy_card) * 0x100 + info->line -
|
.flags = info->port.flags,
|
||||||
cinfo->first_line;
|
.close_delay = info->port.close_delay,
|
||||||
tmp.irq = cinfo->irq;
|
.closing_wait = info->port.closing_wait,
|
||||||
tmp.flags = info->port.flags;
|
.baud_base = info->baud,
|
||||||
tmp.close_delay = info->port.close_delay;
|
.custom_divisor = info->custom_divisor,
|
||||||
tmp.closing_wait = info->port.closing_wait;
|
.hub6 = 0, /*!!! */
|
||||||
tmp.baud_base = info->baud;
|
};
|
||||||
tmp.custom_divisor = info->custom_divisor;
|
|
||||||
tmp.hub6 = 0; /*!!! */
|
|
||||||
return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
|
return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
|
||||||
} /* get_serial_info */
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cy_set_serial_info(struct cyclades_port *info, struct tty_struct *tty,
|
cy_set_serial_info(struct cyclades_port *info, struct tty_struct *tty,
|
||||||
|
@ -2712,18 +2708,6 @@ static int cy_break(struct tty_struct *tty, int break_state)
|
||||||
return retval;
|
return retval;
|
||||||
} /* cy_break */
|
} /* cy_break */
|
||||||
|
|
||||||
static int get_mon_info(struct cyclades_port *info,
|
|
||||||
struct cyclades_monitor __user *mon)
|
|
||||||
{
|
|
||||||
if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
|
|
||||||
return -EFAULT;
|
|
||||||
info->mon.int_count = 0;
|
|
||||||
info->mon.char_count = 0;
|
|
||||||
info->mon.char_max = 0;
|
|
||||||
info->mon.char_last = 0;
|
|
||||||
return 0;
|
|
||||||
} /* get_mon_info */
|
|
||||||
|
|
||||||
static int set_threshold(struct cyclades_port *info, unsigned long value)
|
static int set_threshold(struct cyclades_port *info, unsigned long value)
|
||||||
{
|
{
|
||||||
struct cyclades_card *card;
|
struct cyclades_card *card;
|
||||||
|
@ -2773,19 +2757,6 @@ static int get_threshold(struct cyclades_port *info,
|
||||||
return 0;
|
return 0;
|
||||||
} /* get_threshold */
|
} /* get_threshold */
|
||||||
|
|
||||||
static int set_default_threshold(struct cyclades_port *info,
|
|
||||||
unsigned long value)
|
|
||||||
{
|
|
||||||
info->default_threshold = value & 0x0f;
|
|
||||||
return 0;
|
|
||||||
} /* set_default_threshold */
|
|
||||||
|
|
||||||
static int get_default_threshold(struct cyclades_port *info,
|
|
||||||
unsigned long __user *value)
|
|
||||||
{
|
|
||||||
return put_user(info->default_threshold, value);
|
|
||||||
} /* get_default_threshold */
|
|
||||||
|
|
||||||
static int set_timeout(struct cyclades_port *info, unsigned long value)
|
static int set_timeout(struct cyclades_port *info, unsigned long value)
|
||||||
{
|
{
|
||||||
struct cyclades_card *card;
|
struct cyclades_card *card;
|
||||||
|
@ -2830,17 +2801,26 @@ static int get_timeout(struct cyclades_port *info,
|
||||||
return 0;
|
return 0;
|
||||||
} /* get_timeout */
|
} /* get_timeout */
|
||||||
|
|
||||||
static int set_default_timeout(struct cyclades_port *info, unsigned long value)
|
static int cy_cflags_changed(struct cyclades_port *info, unsigned long arg,
|
||||||
|
struct cyclades_icount *cprev)
|
||||||
{
|
{
|
||||||
info->default_timeout = value & 0xff;
|
struct cyclades_icount cnow;
|
||||||
return 0;
|
unsigned long flags;
|
||||||
} /* set_default_timeout */
|
int ret;
|
||||||
|
|
||||||
static int get_default_timeout(struct cyclades_port *info,
|
spin_lock_irqsave(&info->card->card_lock, flags);
|
||||||
unsigned long __user *value)
|
cnow = info->icount; /* atomic copy */
|
||||||
{
|
spin_unlock_irqrestore(&info->card->card_lock, flags);
|
||||||
return put_user(info->default_timeout, value);
|
|
||||||
} /* get_default_timeout */
|
ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
|
||||||
|
((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
|
||||||
|
((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
|
||||||
|
((arg & TIOCM_CTS) && (cnow.cts != cprev->cts));
|
||||||
|
|
||||||
|
*cprev = cnow;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This routine allows the tty driver to implement device-
|
* This routine allows the tty driver to implement device-
|
||||||
|
@ -2852,8 +2832,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
|
||||||
unsigned int cmd, unsigned long arg)
|
unsigned int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
struct cyclades_port *info = tty->driver_data;
|
struct cyclades_port *info = tty->driver_data;
|
||||||
struct cyclades_icount cprev, cnow; /* kernel counter temps */
|
struct cyclades_icount cnow; /* kernel counter temps */
|
||||||
struct serial_icounter_struct __user *p_cuser; /* user space */
|
|
||||||
int ret_val = 0;
|
int ret_val = 0;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
void __user *argp = (void __user *)arg;
|
void __user *argp = (void __user *)arg;
|
||||||
|
@ -2869,7 +2848,11 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case CYGETMON:
|
case CYGETMON:
|
||||||
ret_val = get_mon_info(info, argp);
|
if (copy_to_user(argp, &info->mon, sizeof(info->mon))) {
|
||||||
|
ret_val = -EFAULT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memset(&info->mon, 0, sizeof(info->mon));
|
||||||
break;
|
break;
|
||||||
case CYGETTHRESH:
|
case CYGETTHRESH:
|
||||||
ret_val = get_threshold(info, argp);
|
ret_val = get_threshold(info, argp);
|
||||||
|
@ -2878,10 +2861,11 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
|
||||||
ret_val = set_threshold(info, arg);
|
ret_val = set_threshold(info, arg);
|
||||||
break;
|
break;
|
||||||
case CYGETDEFTHRESH:
|
case CYGETDEFTHRESH:
|
||||||
ret_val = get_default_threshold(info, argp);
|
ret_val = put_user(info->default_threshold,
|
||||||
|
(unsigned long __user *)argp);
|
||||||
break;
|
break;
|
||||||
case CYSETDEFTHRESH:
|
case CYSETDEFTHRESH:
|
||||||
ret_val = set_default_threshold(info, arg);
|
info->default_threshold = arg & 0x0f;
|
||||||
break;
|
break;
|
||||||
case CYGETTIMEOUT:
|
case CYGETTIMEOUT:
|
||||||
ret_val = get_timeout(info, argp);
|
ret_val = get_timeout(info, argp);
|
||||||
|
@ -2890,21 +2874,20 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
|
||||||
ret_val = set_timeout(info, arg);
|
ret_val = set_timeout(info, arg);
|
||||||
break;
|
break;
|
||||||
case CYGETDEFTIMEOUT:
|
case CYGETDEFTIMEOUT:
|
||||||
ret_val = get_default_timeout(info, argp);
|
ret_val = put_user(info->default_timeout,
|
||||||
|
(unsigned long __user *)argp);
|
||||||
break;
|
break;
|
||||||
case CYSETDEFTIMEOUT:
|
case CYSETDEFTIMEOUT:
|
||||||
ret_val = set_default_timeout(info, arg);
|
info->default_timeout = arg & 0xff;
|
||||||
break;
|
break;
|
||||||
case CYSETRFLOW:
|
case CYSETRFLOW:
|
||||||
info->rflow = (int)arg;
|
info->rflow = (int)arg;
|
||||||
ret_val = 0;
|
|
||||||
break;
|
break;
|
||||||
case CYGETRFLOW:
|
case CYGETRFLOW:
|
||||||
ret_val = info->rflow;
|
ret_val = info->rflow;
|
||||||
break;
|
break;
|
||||||
case CYSETRTSDTR_INV:
|
case CYSETRTSDTR_INV:
|
||||||
info->rtsdtr_inv = (int)arg;
|
info->rtsdtr_inv = (int)arg;
|
||||||
ret_val = 0;
|
|
||||||
break;
|
break;
|
||||||
case CYGETRTSDTR_INV:
|
case CYGETRTSDTR_INV:
|
||||||
ret_val = info->rtsdtr_inv;
|
ret_val = info->rtsdtr_inv;
|
||||||
|
@ -2915,7 +2898,6 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
|
||||||
#ifndef CONFIG_CYZ_INTR
|
#ifndef CONFIG_CYZ_INTR
|
||||||
case CYZSETPOLLCYCLE:
|
case CYZSETPOLLCYCLE:
|
||||||
cyz_polling_cycle = (arg * HZ) / 1000;
|
cyz_polling_cycle = (arg * HZ) / 1000;
|
||||||
ret_val = 0;
|
|
||||||
break;
|
break;
|
||||||
case CYZGETPOLLCYCLE:
|
case CYZGETPOLLCYCLE:
|
||||||
ret_val = (cyz_polling_cycle * 1000) / HZ;
|
ret_val = (cyz_polling_cycle * 1000) / HZ;
|
||||||
|
@ -2923,13 +2905,12 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
|
||||||
#endif /* CONFIG_CYZ_INTR */
|
#endif /* CONFIG_CYZ_INTR */
|
||||||
case CYSETWAIT:
|
case CYSETWAIT:
|
||||||
info->port.closing_wait = (unsigned short)arg * HZ / 100;
|
info->port.closing_wait = (unsigned short)arg * HZ / 100;
|
||||||
ret_val = 0;
|
|
||||||
break;
|
break;
|
||||||
case CYGETWAIT:
|
case CYGETWAIT:
|
||||||
ret_val = info->port.closing_wait / (HZ / 100);
|
ret_val = info->port.closing_wait / (HZ / 100);
|
||||||
break;
|
break;
|
||||||
case TIOCGSERIAL:
|
case TIOCGSERIAL:
|
||||||
ret_val = get_serial_info(info, argp);
|
ret_val = cy_get_serial_info(info, argp);
|
||||||
break;
|
break;
|
||||||
case TIOCSSERIAL:
|
case TIOCSSERIAL:
|
||||||
ret_val = cy_set_serial_info(info, tty, argp);
|
ret_val = cy_set_serial_info(info, tty, argp);
|
||||||
|
@ -2948,17 +2929,8 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
|
||||||
/* note the counters on entry */
|
/* note the counters on entry */
|
||||||
cnow = info->icount;
|
cnow = info->icount;
|
||||||
spin_unlock_irqrestore(&info->card->card_lock, flags);
|
spin_unlock_irqrestore(&info->card->card_lock, flags);
|
||||||
ret_val = wait_event_interruptible(info->delta_msr_wait, ({
|
ret_val = wait_event_interruptible(info->delta_msr_wait,
|
||||||
cprev = cnow;
|
cy_cflags_changed(info, arg, &cnow));
|
||||||
spin_lock_irqsave(&info->card->card_lock, flags);
|
|
||||||
cnow = info->icount; /* atomic copy */
|
|
||||||
spin_unlock_irqrestore(&info->card->card_lock, flags);
|
|
||||||
|
|
||||||
((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
|
|
||||||
((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
|
|
||||||
((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
|
|
||||||
((arg & TIOCM_CTS) && (cnow.cts != cprev.cts));
|
|
||||||
}));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2967,46 +2939,29 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
|
||||||
* NB: both 1->0 and 0->1 transitions are counted except for
|
* NB: both 1->0 and 0->1 transitions are counted except for
|
||||||
* RI where only 0->1 is counted.
|
* RI where only 0->1 is counted.
|
||||||
*/
|
*/
|
||||||
case TIOCGICOUNT:
|
case TIOCGICOUNT: {
|
||||||
|
struct serial_icounter_struct sic = { };
|
||||||
|
|
||||||
spin_lock_irqsave(&info->card->card_lock, flags);
|
spin_lock_irqsave(&info->card->card_lock, flags);
|
||||||
cnow = info->icount;
|
cnow = info->icount;
|
||||||
spin_unlock_irqrestore(&info->card->card_lock, flags);
|
spin_unlock_irqrestore(&info->card->card_lock, flags);
|
||||||
p_cuser = argp;
|
|
||||||
ret_val = put_user(cnow.cts, &p_cuser->cts);
|
sic.cts = cnow.cts;
|
||||||
if (ret_val)
|
sic.dsr = cnow.dsr;
|
||||||
break;
|
sic.rng = cnow.rng;
|
||||||
ret_val = put_user(cnow.dsr, &p_cuser->dsr);
|
sic.dcd = cnow.dcd;
|
||||||
if (ret_val)
|
sic.rx = cnow.rx;
|
||||||
break;
|
sic.tx = cnow.tx;
|
||||||
ret_val = put_user(cnow.rng, &p_cuser->rng);
|
sic.frame = cnow.frame;
|
||||||
if (ret_val)
|
sic.overrun = cnow.overrun;
|
||||||
break;
|
sic.parity = cnow.parity;
|
||||||
ret_val = put_user(cnow.dcd, &p_cuser->dcd);
|
sic.brk = cnow.brk;
|
||||||
if (ret_val)
|
sic.buf_overrun = cnow.buf_overrun;
|
||||||
break;
|
|
||||||
ret_val = put_user(cnow.rx, &p_cuser->rx);
|
if (copy_to_user(argp, &sic, sizeof(sic)))
|
||||||
if (ret_val)
|
ret_val = -EFAULT;
|
||||||
break;
|
|
||||||
ret_val = put_user(cnow.tx, &p_cuser->tx);
|
|
||||||
if (ret_val)
|
|
||||||
break;
|
|
||||||
ret_val = put_user(cnow.frame, &p_cuser->frame);
|
|
||||||
if (ret_val)
|
|
||||||
break;
|
|
||||||
ret_val = put_user(cnow.overrun, &p_cuser->overrun);
|
|
||||||
if (ret_val)
|
|
||||||
break;
|
|
||||||
ret_val = put_user(cnow.parity, &p_cuser->parity);
|
|
||||||
if (ret_val)
|
|
||||||
break;
|
|
||||||
ret_val = put_user(cnow.brk, &p_cuser->brk);
|
|
||||||
if (ret_val)
|
|
||||||
break;
|
|
||||||
ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
|
|
||||||
if (ret_val)
|
|
||||||
break;
|
|
||||||
ret_val = 0;
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
ret_val = -ENOIOCTLCMD;
|
ret_val = -ENOIOCTLCMD;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue