static void
 tty3270_write_callback(struct raw3270_request *rq, void *data)
 {
-       struct tty3270 *tp;
+       struct tty3270 *tp = container_of(rq->view, struct tty3270, view);
 
-       tp = (struct tty3270 *) rq->view;
        if (rq->rc != 0) {
                /* Write wasn't successful. Refresh all. */
                tp->update_flags = TTY_UPDATE_ALL;
 tty3270_read_tasklet(struct raw3270_request *rrq)
 {
        static char kreset_data = TW_KR;
-       struct tty3270 *tp;
+       struct tty3270 *tp = container_of(rrq->view, struct tty3270, view);
        char *input;
        int len;
 
-       tp = (struct tty3270 *) rrq->view;
        spin_lock_bh(&tp->view.lock);
        /*
         * Two AID keys are special: For 0x7d (enter) the input line
 static void
 tty3270_read_callback(struct raw3270_request *rq, void *data)
 {
+       struct tty3270 *tp = container_of(rq->view, struct tty3270, view);
        raw3270_get_view(rq->view);
        /* Schedule tasklet to pass input to tty. */
-       tasklet_schedule(&((struct tty3270 *) rq->view)->readlet);
+       tasklet_schedule(&tp->readlet);
 }
 
 /*
 static int
 tty3270_activate(struct raw3270_view *view)
 {
-       struct tty3270 *tp;
+       struct tty3270 *tp = container_of(view, struct tty3270, view);
 
-       tp = (struct tty3270 *) view;
        tp->update_flags = TTY_UPDATE_ALL;
        tty3270_set_timer(tp, 1);
        return 0;
 static void
 tty3270_deactivate(struct raw3270_view *view)
 {
-       struct tty3270 *tp;
+       struct tty3270 *tp = container_of(view, struct tty3270, view);
 
-       tp = (struct tty3270 *) view;
        del_timer(&tp->timer);
 }
 
 static void
 tty3270_release(struct raw3270_view *view)
 {
-       struct tty3270 *tp;
+       struct tty3270 *tp = container_of(view, struct tty3270, view);
        struct tty_struct *tty;
 
-       tp = (struct tty3270 *) view;
        tty = tp->tty;
        if (tty) {
                tty->driver_data = NULL;
 static void
 tty3270_free(struct raw3270_view *view)
 {
-       tty3270_free_screen((struct tty3270 *) view);
-       tty3270_free_view((struct tty3270 *) view);
+       struct tty3270 *tp = container_of(view, struct tty3270, view);
+       tty3270_free_screen(tp);
+       tty3270_free_view(tp);
 }
 
 /*
 static void
 tty3270_del_views(void)
 {
-       struct tty3270 *tp;
        int i;
 
        for (i = 0; i < tty3270_max_index; i++) {
-               tp = (struct tty3270 *)
+               struct raw3270_view *view =
                        raw3270_find_view(&tty3270_fn, i + RAW3270_FIRSTMINOR);
-               if (!IS_ERR(tp))
-                       raw3270_del_view(&tp->view);
+               if (!IS_ERR(view))
+                       raw3270_del_view(view);
        }
 }
 
 static int
 tty3270_open(struct tty_struct *tty, struct file * filp)
 {
+       struct raw3270_view *view;
        struct tty3270 *tp;
        int i, rc;
 
        if (tty->count > 1)
                return 0;
        /* Check if the tty3270 is already there. */
-       tp = (struct tty3270 *)
-               raw3270_find_view(&tty3270_fn,
+       view = raw3270_find_view(&tty3270_fn,
                                  tty->index + RAW3270_FIRSTMINOR);
-       if (!IS_ERR(tp)) {
+       if (!IS_ERR(view)) {
+               tp = container_of(view, struct tty3270, view);
                tty->driver_data = tp;
                tty->winsize.ws_row = tp->view.rows - 2;
                tty->winsize.ws_col = tp->view.cols;
                tty3270_max_index = tty->index + 1;
 
        /* Quick exit if there is no device for tty->index. */
-       if (PTR_ERR(tp) == -ENODEV)
+       if (PTR_ERR(view) == -ENODEV)
                return -ENODEV;
 
        /* Allocate tty3270 structure on first open. */
 static void
 tty3270_close(struct tty_struct *tty, struct file * filp)
 {
-       struct tty3270 *tp;
+       struct tty3270 *tp = tty->driver_data;
 
        if (tty->count > 1)
                return;
-       tp = (struct tty3270 *) tty->driver_data;
        if (tp) {
                tty->driver_data = NULL;
                tp->tty = tp->kbd->tty = NULL;