gig_dbg(DEBUG_IF, "%d+%d: %s()",
tty->driver->minor_start, tty->index, __func__);
- tty->driver_data = NULL;
-
cs = gigaset_get_cs_by_tty(tty);
if (!cs || !try_module_get(cs->driver->owner))
return -ENODEV;
static void if_close(struct tty_struct *tty, struct file *filp)
{
- struct cardstate *cs;
+ struct cardstate *cs = tty->driver_data;
unsigned long flags;
- cs = (struct cardstate *) tty->driver_data;
- if (!cs) {
- pr_err("%s: no cardstate\n", __func__);
+ if (!cs) { /* happens if we didn't find cs in open */
+ printk(KERN_DEBUG "%s: no cardstate\n", __func__);
return;
}
static int if_ioctl(struct tty_struct *tty,
unsigned int cmd, unsigned long arg)
{
- struct cardstate *cs;
+ struct cardstate *cs = tty->driver_data;
int retval = -ENODEV;
int int_arg;
unsigned char buf[6];
unsigned version[4];
- cs = (struct cardstate *) tty->driver_data;
- if (!cs) {
- pr_err("%s: no cardstate\n", __func__);
- return -ENODEV;
- }
-
gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd);
if (mutex_lock_interruptible(&cs->mutex))
if (!cs->connected) {
gig_dbg(DEBUG_IF, "not connected");
retval = -ENODEV;
- } else if (!cs->open_count)
- dev_warn(cs->dev, "%s: device not opened\n", __func__);
- else {
+ } else {
retval = 0;
switch (cmd) {
case GIGASET_REDIR:
static int if_tiocmget(struct tty_struct *tty)
{
- struct cardstate *cs;
+ struct cardstate *cs = tty->driver_data;
int retval;
- cs = (struct cardstate *) tty->driver_data;
- if (!cs) {
- pr_err("%s: no cardstate\n", __func__);
- return -ENODEV;
- }
-
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
if (mutex_lock_interruptible(&cs->mutex))
static int if_tiocmset(struct tty_struct *tty,
unsigned int set, unsigned int clear)
{
- struct cardstate *cs;
+ struct cardstate *cs = tty->driver_data;
int retval;
unsigned mc;
- cs = (struct cardstate *) tty->driver_data;
- if (!cs) {
- pr_err("%s: no cardstate\n", __func__);
- return -ENODEV;
- }
-
gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)",
cs->minor_index, __func__, set, clear);
static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
{
- struct cardstate *cs;
+ struct cardstate *cs = tty->driver_data;
struct cmdbuf_t *cb;
int retval;
- cs = (struct cardstate *) tty->driver_data;
- if (!cs) {
- pr_err("%s: no cardstate\n", __func__);
- return -ENODEV;
- }
-
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
if (mutex_lock_interruptible(&cs->mutex))
retval = -ENODEV;
goto done;
}
- if (!cs->open_count) {
- dev_warn(cs->dev, "%s: device not opened\n", __func__);
- retval = -ENODEV;
- goto done;
- }
if (cs->mstate != MS_LOCKED) {
dev_warn(cs->dev, "can't write to unlocked device\n");
retval = -EBUSY;
static int if_write_room(struct tty_struct *tty)
{
- struct cardstate *cs;
+ struct cardstate *cs = tty->driver_data;
int retval = -ENODEV;
- cs = (struct cardstate *) tty->driver_data;
- if (!cs) {
- pr_err("%s: no cardstate\n", __func__);
- return -ENODEV;
- }
-
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
if (mutex_lock_interruptible(&cs->mutex))
if (!cs->connected) {
gig_dbg(DEBUG_IF, "not connected");
retval = -ENODEV;
- } else if (!cs->open_count)
- dev_warn(cs->dev, "%s: device not opened\n", __func__);
- else if (cs->mstate != MS_LOCKED) {
+ } else if (cs->mstate != MS_LOCKED) {
dev_warn(cs->dev, "can't write to unlocked device\n");
retval = -EBUSY;
} else
static int if_chars_in_buffer(struct tty_struct *tty)
{
- struct cardstate *cs;
+ struct cardstate *cs = tty->driver_data;
int retval = 0;
- cs = (struct cardstate *) tty->driver_data;
- if (!cs) {
- pr_err("%s: no cardstate\n", __func__);
- return 0;
- }
-
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
mutex_lock(&cs->mutex);
if (!cs->connected)
gig_dbg(DEBUG_IF, "not connected");
- else if (!cs->open_count)
- dev_warn(cs->dev, "%s: device not opened\n", __func__);
else if (cs->mstate != MS_LOCKED)
dev_warn(cs->dev, "can't write to unlocked device\n");
else
static void if_throttle(struct tty_struct *tty)
{
- struct cardstate *cs;
-
- cs = (struct cardstate *) tty->driver_data;
- if (!cs) {
- pr_err("%s: no cardstate\n", __func__);
- return;
- }
+ struct cardstate *cs = tty->driver_data;
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
if (!cs->connected)
gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
- else if (!cs->open_count)
- dev_warn(cs->dev, "%s: device not opened\n", __func__);
else
gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
static void if_unthrottle(struct tty_struct *tty)
{
- struct cardstate *cs;
-
- cs = (struct cardstate *) tty->driver_data;
- if (!cs) {
- pr_err("%s: no cardstate\n", __func__);
- return;
- }
+ struct cardstate *cs = tty->driver_data;
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
if (!cs->connected)
gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
- else if (!cs->open_count)
- dev_warn(cs->dev, "%s: device not opened\n", __func__);
else
gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
{
- struct cardstate *cs;
+ struct cardstate *cs = tty->driver_data;
unsigned int iflag;
unsigned int cflag;
unsigned int old_cflag;
unsigned int control_state, new_state;
- cs = (struct cardstate *) tty->driver_data;
- if (!cs) {
- pr_err("%s: no cardstate\n", __func__);
- return;
- }
-
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
mutex_lock(&cs->mutex);
goto out;
}
- if (!cs->open_count) {
- dev_warn(cs->dev, "%s: device not opened\n", __func__);
- goto out;
- }
-
iflag = tty->termios->c_iflag;
cflag = tty->termios->c_cflag;
old_cflag = old ? old->c_cflag : cflag;