diff options
-rw-r--r-- | drivers/isdn/gigaset/interface.c | 105 |
1 files changed, 14 insertions, 91 deletions
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c index 648260b07f1a..8ff50b056285 100644 --- a/drivers/isdn/gigaset/interface.c +++ b/drivers/isdn/gigaset/interface.c | |||
@@ -151,8 +151,6 @@ static int if_open(struct tty_struct *tty, struct file *filp) | |||
151 | gig_dbg(DEBUG_IF, "%d+%d: %s()", | 151 | gig_dbg(DEBUG_IF, "%d+%d: %s()", |
152 | tty->driver->minor_start, tty->index, __func__); | 152 | tty->driver->minor_start, tty->index, __func__); |
153 | 153 | ||
154 | tty->driver_data = NULL; | ||
155 | |||
156 | cs = gigaset_get_cs_by_tty(tty); | 154 | cs = gigaset_get_cs_by_tty(tty); |
157 | if (!cs || !try_module_get(cs->driver->owner)) | 155 | if (!cs || !try_module_get(cs->driver->owner)) |
158 | return -ENODEV; | 156 | return -ENODEV; |
@@ -178,12 +176,11 @@ static int if_open(struct tty_struct *tty, struct file *filp) | |||
178 | 176 | ||
179 | static void if_close(struct tty_struct *tty, struct file *filp) | 177 | static void if_close(struct tty_struct *tty, struct file *filp) |
180 | { | 178 | { |
181 | struct cardstate *cs; | 179 | struct cardstate *cs = tty->driver_data; |
182 | unsigned long flags; | 180 | unsigned long flags; |
183 | 181 | ||
184 | cs = (struct cardstate *) tty->driver_data; | 182 | if (!cs) { /* happens if we didn't find cs in open */ |
185 | if (!cs) { | 183 | printk(KERN_DEBUG "%s: no cardstate\n", __func__); |
186 | pr_err("%s: no cardstate\n", __func__); | ||
187 | return; | 184 | return; |
188 | } | 185 | } |
189 | 186 | ||
@@ -211,18 +208,12 @@ static void if_close(struct tty_struct *tty, struct file *filp) | |||
211 | static int if_ioctl(struct tty_struct *tty, | 208 | static int if_ioctl(struct tty_struct *tty, |
212 | unsigned int cmd, unsigned long arg) | 209 | unsigned int cmd, unsigned long arg) |
213 | { | 210 | { |
214 | struct cardstate *cs; | 211 | struct cardstate *cs = tty->driver_data; |
215 | int retval = -ENODEV; | 212 | int retval = -ENODEV; |
216 | int int_arg; | 213 | int int_arg; |
217 | unsigned char buf[6]; | 214 | unsigned char buf[6]; |
218 | unsigned version[4]; | 215 | unsigned version[4]; |
219 | 216 | ||
220 | cs = (struct cardstate *) tty->driver_data; | ||
221 | if (!cs) { | ||
222 | pr_err("%s: no cardstate\n", __func__); | ||
223 | return -ENODEV; | ||
224 | } | ||
225 | |||
226 | gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd); | 217 | gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd); |
227 | 218 | ||
228 | if (mutex_lock_interruptible(&cs->mutex)) | 219 | if (mutex_lock_interruptible(&cs->mutex)) |
@@ -231,9 +222,7 @@ static int if_ioctl(struct tty_struct *tty, | |||
231 | if (!cs->connected) { | 222 | if (!cs->connected) { |
232 | gig_dbg(DEBUG_IF, "not connected"); | 223 | gig_dbg(DEBUG_IF, "not connected"); |
233 | retval = -ENODEV; | 224 | retval = -ENODEV; |
234 | } else if (!cs->open_count) | 225 | } else { |
235 | dev_warn(cs->dev, "%s: device not opened\n", __func__); | ||
236 | else { | ||
237 | retval = 0; | 226 | retval = 0; |
238 | switch (cmd) { | 227 | switch (cmd) { |
239 | case GIGASET_REDIR: | 228 | case GIGASET_REDIR: |
@@ -285,15 +274,9 @@ static int if_ioctl(struct tty_struct *tty, | |||
285 | 274 | ||
286 | static int if_tiocmget(struct tty_struct *tty) | 275 | static int if_tiocmget(struct tty_struct *tty) |
287 | { | 276 | { |
288 | struct cardstate *cs; | 277 | struct cardstate *cs = tty->driver_data; |
289 | int retval; | 278 | int retval; |
290 | 279 | ||
291 | cs = (struct cardstate *) tty->driver_data; | ||
292 | if (!cs) { | ||
293 | pr_err("%s: no cardstate\n", __func__); | ||
294 | return -ENODEV; | ||
295 | } | ||
296 | |||
297 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); | 280 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
298 | 281 | ||
299 | if (mutex_lock_interruptible(&cs->mutex)) | 282 | if (mutex_lock_interruptible(&cs->mutex)) |
@@ -309,16 +292,10 @@ static int if_tiocmget(struct tty_struct *tty) | |||
309 | static int if_tiocmset(struct tty_struct *tty, | 292 | static int if_tiocmset(struct tty_struct *tty, |
310 | unsigned int set, unsigned int clear) | 293 | unsigned int set, unsigned int clear) |
311 | { | 294 | { |
312 | struct cardstate *cs; | 295 | struct cardstate *cs = tty->driver_data; |
313 | int retval; | 296 | int retval; |
314 | unsigned mc; | 297 | unsigned mc; |
315 | 298 | ||
316 | cs = (struct cardstate *) tty->driver_data; | ||
317 | if (!cs) { | ||
318 | pr_err("%s: no cardstate\n", __func__); | ||
319 | return -ENODEV; | ||
320 | } | ||
321 | |||
322 | gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)", | 299 | gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)", |
323 | cs->minor_index, __func__, set, clear); | 300 | cs->minor_index, __func__, set, clear); |
324 | 301 | ||
@@ -341,16 +318,10 @@ static int if_tiocmset(struct tty_struct *tty, | |||
341 | 318 | ||
342 | static int if_write(struct tty_struct *tty, const unsigned char *buf, int count) | 319 | static int if_write(struct tty_struct *tty, const unsigned char *buf, int count) |
343 | { | 320 | { |
344 | struct cardstate *cs; | 321 | struct cardstate *cs = tty->driver_data; |
345 | struct cmdbuf_t *cb; | 322 | struct cmdbuf_t *cb; |
346 | int retval; | 323 | int retval; |
347 | 324 | ||
348 | cs = (struct cardstate *) tty->driver_data; | ||
349 | if (!cs) { | ||
350 | pr_err("%s: no cardstate\n", __func__); | ||
351 | return -ENODEV; | ||
352 | } | ||
353 | |||
354 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); | 325 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
355 | 326 | ||
356 | if (mutex_lock_interruptible(&cs->mutex)) | 327 | if (mutex_lock_interruptible(&cs->mutex)) |
@@ -361,11 +332,6 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count) | |||
361 | retval = -ENODEV; | 332 | retval = -ENODEV; |
362 | goto done; | 333 | goto done; |
363 | } | 334 | } |
364 | if (!cs->open_count) { | ||
365 | dev_warn(cs->dev, "%s: device not opened\n", __func__); | ||
366 | retval = -ENODEV; | ||
367 | goto done; | ||
368 | } | ||
369 | if (cs->mstate != MS_LOCKED) { | 335 | if (cs->mstate != MS_LOCKED) { |
370 | dev_warn(cs->dev, "can't write to unlocked device\n"); | 336 | dev_warn(cs->dev, "can't write to unlocked device\n"); |
371 | retval = -EBUSY; | 337 | retval = -EBUSY; |
@@ -397,15 +363,9 @@ done: | |||
397 | 363 | ||
398 | static int if_write_room(struct tty_struct *tty) | 364 | static int if_write_room(struct tty_struct *tty) |
399 | { | 365 | { |
400 | struct cardstate *cs; | 366 | struct cardstate *cs = tty->driver_data; |
401 | int retval = -ENODEV; | 367 | int retval = -ENODEV; |
402 | 368 | ||
403 | cs = (struct cardstate *) tty->driver_data; | ||
404 | if (!cs) { | ||
405 | pr_err("%s: no cardstate\n", __func__); | ||
406 | return -ENODEV; | ||
407 | } | ||
408 | |||
409 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); | 369 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
410 | 370 | ||
411 | if (mutex_lock_interruptible(&cs->mutex)) | 371 | if (mutex_lock_interruptible(&cs->mutex)) |
@@ -414,9 +374,7 @@ static int if_write_room(struct tty_struct *tty) | |||
414 | if (!cs->connected) { | 374 | if (!cs->connected) { |
415 | gig_dbg(DEBUG_IF, "not connected"); | 375 | gig_dbg(DEBUG_IF, "not connected"); |
416 | retval = -ENODEV; | 376 | retval = -ENODEV; |
417 | } else if (!cs->open_count) | 377 | } else if (cs->mstate != MS_LOCKED) { |
418 | dev_warn(cs->dev, "%s: device not opened\n", __func__); | ||
419 | else if (cs->mstate != MS_LOCKED) { | ||
420 | dev_warn(cs->dev, "can't write to unlocked device\n"); | 378 | dev_warn(cs->dev, "can't write to unlocked device\n"); |
421 | retval = -EBUSY; | 379 | retval = -EBUSY; |
422 | } else | 380 | } else |
@@ -429,23 +387,15 @@ static int if_write_room(struct tty_struct *tty) | |||
429 | 387 | ||
430 | static int if_chars_in_buffer(struct tty_struct *tty) | 388 | static int if_chars_in_buffer(struct tty_struct *tty) |
431 | { | 389 | { |
432 | struct cardstate *cs; | 390 | struct cardstate *cs = tty->driver_data; |
433 | int retval = 0; | 391 | int retval = 0; |
434 | 392 | ||
435 | cs = (struct cardstate *) tty->driver_data; | ||
436 | if (!cs) { | ||
437 | pr_err("%s: no cardstate\n", __func__); | ||
438 | return 0; | ||
439 | } | ||
440 | |||
441 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); | 393 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
442 | 394 | ||
443 | mutex_lock(&cs->mutex); | 395 | mutex_lock(&cs->mutex); |
444 | 396 | ||
445 | if (!cs->connected) | 397 | if (!cs->connected) |
446 | gig_dbg(DEBUG_IF, "not connected"); | 398 | gig_dbg(DEBUG_IF, "not connected"); |
447 | else if (!cs->open_count) | ||
448 | dev_warn(cs->dev, "%s: device not opened\n", __func__); | ||
449 | else if (cs->mstate != MS_LOCKED) | 399 | else if (cs->mstate != MS_LOCKED) |
450 | dev_warn(cs->dev, "can't write to unlocked device\n"); | 400 | dev_warn(cs->dev, "can't write to unlocked device\n"); |
451 | else | 401 | else |
@@ -458,13 +408,7 @@ static int if_chars_in_buffer(struct tty_struct *tty) | |||
458 | 408 | ||
459 | static void if_throttle(struct tty_struct *tty) | 409 | static void if_throttle(struct tty_struct *tty) |
460 | { | 410 | { |
461 | struct cardstate *cs; | 411 | struct cardstate *cs = tty->driver_data; |
462 | |||
463 | cs = (struct cardstate *) tty->driver_data; | ||
464 | if (!cs) { | ||
465 | pr_err("%s: no cardstate\n", __func__); | ||
466 | return; | ||
467 | } | ||
468 | 412 | ||
469 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); | 413 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
470 | 414 | ||
@@ -472,8 +416,6 @@ static void if_throttle(struct tty_struct *tty) | |||
472 | 416 | ||
473 | if (!cs->connected) | 417 | if (!cs->connected) |
474 | gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ | 418 | gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ |
475 | else if (!cs->open_count) | ||
476 | dev_warn(cs->dev, "%s: device not opened\n", __func__); | ||
477 | else | 419 | else |
478 | gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); | 420 | gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); |
479 | 421 | ||
@@ -482,13 +424,7 @@ static void if_throttle(struct tty_struct *tty) | |||
482 | 424 | ||
483 | static void if_unthrottle(struct tty_struct *tty) | 425 | static void if_unthrottle(struct tty_struct *tty) |
484 | { | 426 | { |
485 | struct cardstate *cs; | 427 | struct cardstate *cs = tty->driver_data; |
486 | |||
487 | cs = (struct cardstate *) tty->driver_data; | ||
488 | if (!cs) { | ||
489 | pr_err("%s: no cardstate\n", __func__); | ||
490 | return; | ||
491 | } | ||
492 | 428 | ||
493 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); | 429 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
494 | 430 | ||
@@ -496,8 +432,6 @@ static void if_unthrottle(struct tty_struct *tty) | |||
496 | 432 | ||
497 | if (!cs->connected) | 433 | if (!cs->connected) |
498 | gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ | 434 | gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ |
499 | else if (!cs->open_count) | ||
500 | dev_warn(cs->dev, "%s: device not opened\n", __func__); | ||
501 | else | 435 | else |
502 | gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); | 436 | gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); |
503 | 437 | ||
@@ -506,18 +440,12 @@ static void if_unthrottle(struct tty_struct *tty) | |||
506 | 440 | ||
507 | static void if_set_termios(struct tty_struct *tty, struct ktermios *old) | 441 | static void if_set_termios(struct tty_struct *tty, struct ktermios *old) |
508 | { | 442 | { |
509 | struct cardstate *cs; | 443 | struct cardstate *cs = tty->driver_data; |
510 | unsigned int iflag; | 444 | unsigned int iflag; |
511 | unsigned int cflag; | 445 | unsigned int cflag; |
512 | unsigned int old_cflag; | 446 | unsigned int old_cflag; |
513 | unsigned int control_state, new_state; | 447 | unsigned int control_state, new_state; |
514 | 448 | ||
515 | cs = (struct cardstate *) tty->driver_data; | ||
516 | if (!cs) { | ||
517 | pr_err("%s: no cardstate\n", __func__); | ||
518 | return; | ||
519 | } | ||
520 | |||
521 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); | 449 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
522 | 450 | ||
523 | mutex_lock(&cs->mutex); | 451 | mutex_lock(&cs->mutex); |
@@ -527,11 +455,6 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old) | |||
527 | goto out; | 455 | goto out; |
528 | } | 456 | } |
529 | 457 | ||
530 | if (!cs->open_count) { | ||
531 | dev_warn(cs->dev, "%s: device not opened\n", __func__); | ||
532 | goto out; | ||
533 | } | ||
534 | |||
535 | iflag = tty->termios->c_iflag; | 458 | iflag = tty->termios->c_iflag; |
536 | cflag = tty->termios->c_cflag; | 459 | cflag = tty->termios->c_cflag; |
537 | old_cflag = old ? old->c_cflag : cflag; | 460 | old_cflag = old ? old->c_cflag : cflag; |