Add package for sllin driver to image
[AGL/meta-agl-demo.git] / recipes-kernel / sllin / files / 0002_fix_null_operation_check.patch
1 diff --git a/sllin/sllin.c b/sllin/sllin.c
2 index 2db896f..2969448 100644
3 --- a/sllin/sllin.c
4 +++ b/sllin/sllin.c
5 @@ -869,7 +869,6 @@ static int sllin_send_tx_buff(struct sllin *sl)
6  #else
7                 remains = sl->tx_lim - sl->tx_cnt;
8  #endif
9 -
10                 res = tty->ops->write(tty, sl->tx_buff + sl->tx_cnt, remains);
11                 if (res < 0)
12                         goto error_in_write;
13 @@ -916,10 +915,25 @@ static int sllin_send_break(struct sllin *sl)
14         unsigned long break_baud;
15         int res;
16  
17 +       netdev_dbg(sl->dev, "%s()#<BREAK_BY_BAUD>  invoke.\n", __func__);
18 +       if (tty == NULL) {
19 +               netdev_dbg(sl->dev, "%s() tty == NULL.\n", __func__);
20 +               sl->lin_state = SLSTATE_IDLE;
21 +               return -1;
22 +       }
23 +       if (tty->ops == NULL) {
24 +               netdev_dbg(sl->dev, "%s() tty->ops == NULL.\n", __func__);
25 +               sl->lin_state = SLSTATE_IDLE;
26 +               return -1;
27 +       }
28         break_baud = ((sl->lin_baud * 2) / 3);
29         sltty_change_speed(tty, break_baud);
30  
31 -       tty->ops->flush_buffer(tty);
32 +       if (tty->ops->flush_buffer) {
33 +               tty->ops->flush_buffer(tty);
34 +       } else {
35 +               netdev_dbg(sl->dev, "%s() tty->ops->flush_buffer is NULL.\n", __func__);
36 +       }
37         sl->rx_cnt = SLLIN_BUFF_BREAK;
38  
39         sl->rx_expect = SLLIN_BUFF_BREAK + 1;
40 @@ -943,6 +957,17 @@ static int sllin_send_break(struct sllin *sl)
41         unsigned long usleep_range_min;
42         unsigned long usleep_range_max;
43  
44 +       netdev_dbg(sl->dev, "%s() invoke.\n", __func__);
45 +       if (tty == NULL) {
46 +               netdev_dbg(sl->dev, "%s() tty == NULL.\n", __func__);
47 +               sl->lin_state = SLSTATE_IDLE;
48 +               return -1;
49 +       }
50 +       if (tty->ops == NULL) {
51 +               netdev_dbg(sl->dev, "%s() tty->ops == NULL.\n", __func__);
52 +               sl->lin_state = SLSTATE_IDLE;
53 +               return -1;
54 +       }
55         break_baud = ((sl->lin_baud * 2) / 3);
56         sl->rx_cnt = SLLIN_BUFF_BREAK;
57         sl->rx_expect = SLLIN_BUFF_BREAK + 1;
58 @@ -950,21 +975,31 @@ static int sllin_send_break(struct sllin *sl)
59  
60         /* Do the break ourselves; Inspired by
61            http://lxr.linux.no/#linux+v3.1.2/drivers/tty/tty_io.c#L2452 */
62 -       retval = tty->ops->break_ctl(tty, -1);
63 -       if (retval)
64 -               return retval;
65 +       if (tty->ops->break_ctl) {
66 +               retval = tty->ops->break_ctl(tty, -1);
67 +               if (retval)
68 +                       return retval;
69 +       } else {
70 +               netdev_dbg(sl->dev, "%s() tty->ops->break_ctl is NULL.\n", __func__);
71 +       }
72  
73         /* udelay(712); */
74         usleep_range_min = (1000000l * SLLIN_SAMPLES_PER_CHAR) / break_baud;
75         usleep_range_max = usleep_range_min + 50;
76         usleep_range(usleep_range_min, usleep_range_max);
77  
78 -       retval = tty->ops->break_ctl(tty, 0);
79 +       if(tty->ops->break_ctl) {
80 +               retval = tty->ops->break_ctl(tty, 0);
81 +       } 
82         usleep_range_min = (1000000l * 1 /* 1 bit */) / break_baud;
83         usleep_range_max = usleep_range_min + 30;
84         usleep_range(usleep_range_min, usleep_range_max);
85  
86 -       tty->ops->flush_buffer(tty);
87 +       if ( tty->ops->flush_buffer) {
88 +               tty->ops->flush_buffer(tty);
89 +       } else {
90 +               netdev_dbg(sl->dev, "%s() tty->ops->flush_buffer is NULL.\n", __func__);
91 +       }
92  
93         sl->tx_cnt = SLLIN_BUFF_SYNC;
94  
95 @@ -1028,6 +1063,12 @@ static int sllin_kwthread(void *ptr)
96                 int lin_dlc;
97                 u8 lin_data_buff[SLLIN_DATA_MAX];
98  
99 +               if (sl == NULL) {
100 +                       pr_err("sllin: sl is NULL\n");
101 +               }
102 +               if (sl->dev == NULL) {
103 +                       pr_err("sllin: sl->dev is NULL\n");
104 +               }
105  
106                 if ((sl->lin_state == SLSTATE_IDLE) && sl->lin_master &&
107                         sl->id_to_send) {
108 @@ -1036,6 +1077,7 @@ static int sllin_kwthread(void *ptr)
109                         }
110                 }
111  
112 +               netdev_dbg(sl->dev, "sllin_kthread <WAIT_EVENT>\n");
113                 wait_event_killable(sl->kwt_wq, kthread_should_stop() ||
114                         test_bit(SLF_RXEVENT, &sl->flags) ||
115                         test_bit(SLF_TXEVENT, &sl->flags) ||
116 @@ -1046,6 +1088,7 @@ static int sllin_kwthread(void *ptr)
117                                 (sl->lin_state == SLSTATE_RESPONSE_WAIT))
118                                 && test_bit(SLF_MSGEVENT, &sl->flags)));
119  
120 +               netdev_dbg(sl->dev, "sllin_kthread <WAKEUPED>\n");
121                 if (test_and_clear_bit(SLF_RXEVENT, &sl->flags)) {
122                         netdev_dbg(sl->dev, "sllin_kthread RXEVENT\n");
123                 }
124 @@ -1078,21 +1121,25 @@ static int sllin_kwthread(void *ptr)
125                         sl->lin_state = SLSTATE_IDLE;
126                 }
127  
128 +               netdev_dbg(sl->dev, "sllin_kthread: lin_state <%08x>\n",sl->lin_state);
129                 switch (sl->lin_state) {
130                 case SLSTATE_IDLE:
131                         if (!test_bit(SLF_MSGEVENT, &sl->flags))
132                                 break;
133 -
134 +                       if (sl->tx_req_skb == NULL)
135 +                               netdev_dbg(sl->dev, "sl->tx_req_skb == NULL\n");
136 +                       if (sl->tx_req_skb->data == NULL)
137 +                               netdev_dbg(sl->dev, "sl->tx_req_skb->data == NULL\n");
138                         cf = (struct can_frame *)sl->tx_req_skb->data;
139  
140                         /* SFF RTR CAN frame -> LIN header */
141                         if (cf->can_id & CAN_RTR_FLAG) {
142                                 struct sllin_conf_entry *sce;
143  
144 -                               netdev_dbg(sl->dev, "%s: RTR SFF CAN frame, ID = %x\n",
145 -                                       __func__, cf->can_id & LIN_ID_MASK);
146  
147                                 sce = &sl->linfr_cache[cf->can_id & LIN_ID_MASK];
148 +                               netdev_dbg(sl->dev, "%s: RTR SFF CAN frame, ID = %x dlc=%d\n",
149 +                                       __func__, cf->can_id & LIN_ID_MASK, sce->dlc);
150                                 spin_lock_irqsave(&sl->linfr_lock, flags);
151  
152                                 /* Is there Slave response in linfr_cache to be sent? */
153 @@ -1114,8 +1161,8 @@ static int sllin_kwthread(void *ptr)
154                                 spin_unlock_irqrestore(&sl->linfr_lock, flags);
155  
156                         } else { /* SFF NON-RTR CAN frame -> LIN header + LIN response */
157 -                               netdev_dbg(sl->dev, "%s: NON-RTR SFF CAN frame, ID = %x\n",
158 -                                       __func__, (int)cf->can_id & LIN_ID_MASK);
159 +                               netdev_dbg(sl->dev, "%s: NON-RTR SFF CAN frame, ID = %x\n dlc=%d",
160 +                                       __func__, (int)cf->can_id & LIN_ID_MASK, cf->can_dlc);
161  
162                                 lin_data = cf->data;
163                                 lin_dlc = cf->can_dlc;
164 @@ -1140,6 +1187,7 @@ static int sllin_kwthread(void *ptr)
165                         hrtimer_start(&sl->rx_timer,
166                                 ktime_add(ktime_get(), sl->rx_timer_timeout),
167                                 HRTIMER_MODE_ABS);
168 +                       netdev_dbg(sl->dev, "sllin_kthread: SLSTATE finish\n");
169                         break;
170  
171                 case SLSTATE_BREAK_SENT:
172 @@ -1654,3 +1702,4 @@ static void __exit sllin_exit(void)
173  
174  module_init(sllin_init);
175  module_exit(sllin_exit);
176 +