Commit c6a56fe4 authored by Ralf Bächle's avatar Ralf Bächle

[PATCH] mkiss

Below patch cleans the mkiss driver.  After the previous cleanup in
2.4.0-prerelease various code had become unreachable because nothing
was ever setting MKISS_DRIVER_MAGIC.  This fixes fixes an oops - the
mkiss pointer was potencially NULL.  And it also removes the
MOD_{INC,DEC}_USE_COUNT calls.

Alan, lemme know if you want me to cook a 2.4 patch also.

Patch from Jeroen Vreeken PE1RXQ.

Ralf
parent 72517c81
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
* Matthias (DG2FEF) Added support for FlexNet CRC (on special request) * Matthias (DG2FEF) Added support for FlexNet CRC (on special request)
* Fixed bug in ax25_close(): dev_lock_wait() was * Fixed bug in ax25_close(): dev_lock_wait() was
* called twice, causing a deadlock. * called twice, causing a deadlock.
* Jeroen (PE1RXQ) Removed old MKISS_MAGIC stuff and calls to
* MOD_*_USE_COUNT
*/ */
#include <linux/config.h> #include <linux/config.h>
...@@ -55,15 +57,6 @@ ...@@ -55,15 +57,6 @@
static char banner[] __initdata = KERN_INFO "mkiss: AX.25 Multikiss, Hans Albas PE1AYX\n"; static char banner[] __initdata = KERN_INFO "mkiss: AX.25 Multikiss, Hans Albas PE1AYX\n";
#define NR_MKISS 4
#define MKISS_SERIAL_TYPE_NORMAL 1
struct mkiss_channel {
int magic; /* magic word */
int init; /* channel exists? */
struct tty_struct *tty; /* link to tty control structure */
};
typedef struct ax25_ctrl { typedef struct ax25_ctrl {
struct ax_disp ctrl; /* */ struct ax_disp ctrl; /* */
struct net_device dev; /* the device */ struct net_device dev; /* the device */
...@@ -310,19 +303,11 @@ static inline void ax_unlock(struct ax_disp *ax) ...@@ -310,19 +303,11 @@ static inline void ax_unlock(struct ax_disp *ax)
/* Send one completely decapsulated AX.25 packet to the AX.25 layer. */ /* Send one completely decapsulated AX.25 packet to the AX.25 layer. */
static void ax_bump(struct ax_disp *ax) static void ax_bump(struct ax_disp *ax)
{ {
struct ax_disp *tmp_ax;
struct sk_buff *skb; struct sk_buff *skb;
struct mkiss_channel *mkiss;
int count; int count;
tmp_ax = ax;
if (ax->rbuff[0] > 0x0f) { if (ax->rbuff[0] > 0x0f) {
if (ax->mkiss != NULL) { if (ax->rbuff[0] & 0x20) {
mkiss= ax->mkiss->tty->driver_data;
if (mkiss->magic == MKISS_DRIVER_MAGIC)
tmp_ax = ax->mkiss;
} else if (ax->rbuff[0] & 0x20) {
ax->crcmode = CRC_MODE_FLEX; ax->crcmode = CRC_MODE_FLEX;
if (check_crc_flex(ax->rbuff, ax->rcount) < 0) { if (check_crc_flex(ax->rbuff, ax->rcount) < 0) {
ax->rx_errors++; ax->rx_errors++;
...@@ -346,14 +331,14 @@ static void ax_bump(struct ax_disp *ax) ...@@ -346,14 +331,14 @@ static void ax_bump(struct ax_disp *ax)
return; return;
} }
skb->dev = tmp_ax->dev; skb->dev = ax->dev;
memcpy(skb_put(skb,count), ax->rbuff, count); memcpy(skb_put(skb,count), ax->rbuff, count);
skb->mac.raw = skb->data; skb->mac.raw = skb->data;
skb->protocol = htons(ETH_P_AX25); skb->protocol = htons(ETH_P_AX25);
netif_rx(skb); netif_rx(skb);
tmp_ax->dev->last_rx = jiffies; ax->dev->last_rx = jiffies;
tmp_ax->rx_packets++; ax->rx_packets++;
tmp_ax->rx_bytes+=count; ax->rx_bytes+=count;
} }
/* Encapsulate one AX.25 packet and stuff into a TTY queue. */ /* Encapsulate one AX.25 packet and stuff into a TTY queue. */
...@@ -361,7 +346,6 @@ static void ax_encaps(struct ax_disp *ax, unsigned char *icp, int len) ...@@ -361,7 +346,6 @@ static void ax_encaps(struct ax_disp *ax, unsigned char *icp, int len)
{ {
unsigned char *p; unsigned char *p;
int actual, count; int actual, count;
struct mkiss_channel *mkiss = ax->tty->driver_data;
if (ax->mtu != ax->dev->mtu + 73) /* Someone has been ifconfigging */ if (ax->mtu != ax->dev->mtu + 73) /* Someone has been ifconfigging */
ax_changedmtu(ax); ax_changedmtu(ax);
...@@ -376,7 +360,6 @@ static void ax_encaps(struct ax_disp *ax, unsigned char *icp, int len) ...@@ -376,7 +360,6 @@ static void ax_encaps(struct ax_disp *ax, unsigned char *icp, int len)
p = icp; p = icp;
if (mkiss->magic != MKISS_DRIVER_MAGIC) {
switch (ax->crcmode) { switch (ax->crcmode) {
unsigned short crc; unsigned short crc;
...@@ -397,16 +380,6 @@ static void ax_encaps(struct ax_disp *ax, unsigned char *icp, int len) ...@@ -397,16 +380,6 @@ static void ax_encaps(struct ax_disp *ax, unsigned char *icp, int len)
ax->dev->trans_start = jiffies; ax->dev->trans_start = jiffies;
ax->xleft = count - actual; ax->xleft = count - actual;
ax->xhead = ax->xbuff + actual; ax->xhead = ax->xbuff + actual;
} else {
count = kiss_esc(p, (unsigned char *) ax->mkiss->xbuff, len);
ax->mkiss->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
actual = ax->mkiss->tty->driver->write(ax->mkiss->tty, 0, ax->mkiss->xbuff, count);
ax->tx_packets++;
ax->tx_bytes+=actual;
ax->mkiss->dev->trans_start = jiffies;
ax->mkiss->xleft = count - actual;
ax->mkiss->xhead = ax->mkiss->xbuff + actual;
}
} }
/* /*
...@@ -417,7 +390,6 @@ static void ax25_write_wakeup(struct tty_struct *tty) ...@@ -417,7 +390,6 @@ static void ax25_write_wakeup(struct tty_struct *tty)
{ {
int actual; int actual;
struct ax_disp *ax = (struct ax_disp *) tty->disc_data; struct ax_disp *ax = (struct ax_disp *) tty->disc_data;
struct mkiss_channel *mkiss;
/* First make sure we're connected. */ /* First make sure we're connected. */
if (ax == NULL || ax->magic != AX25_MAGIC || !netif_running(ax->dev)) if (ax == NULL || ax->magic != AX25_MAGIC || !netif_running(ax->dev))
...@@ -428,12 +400,6 @@ static void ax25_write_wakeup(struct tty_struct *tty) ...@@ -428,12 +400,6 @@ static void ax25_write_wakeup(struct tty_struct *tty)
*/ */
tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
if (ax->mkiss != NULL) {
mkiss= ax->mkiss->tty->driver_data;
if (mkiss->magic == MKISS_DRIVER_MAGIC)
ax_unlock(ax->mkiss);
}
netif_wake_queue(ax->dev); netif_wake_queue(ax->dev);
return; return;
} }
...@@ -447,32 +413,12 @@ static void ax25_write_wakeup(struct tty_struct *tty) ...@@ -447,32 +413,12 @@ static void ax25_write_wakeup(struct tty_struct *tty)
static int ax_xmit(struct sk_buff *skb, struct net_device *dev) static int ax_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct ax_disp *ax = (struct ax_disp *) dev->priv; struct ax_disp *ax = (struct ax_disp *) dev->priv;
struct mkiss_channel *mkiss = ax->tty->driver_data;
struct ax_disp *tmp_ax;
tmp_ax = NULL;
if (mkiss->magic == MKISS_DRIVER_MAGIC) {
if (skb->data[0] < 0x10)
skb->data[0] = skb->data[0] + 0x10;
tmp_ax = ax->mkiss;
}
if (!netif_running(dev)) { if (!netif_running(dev)) {
printk(KERN_ERR "mkiss: %s: xmit call when iface is down\n", dev->name); printk(KERN_ERR "mkiss: %s: xmit call when iface is down\n", dev->name);
return 1; return 1;
} }
if (tmp_ax != NULL)
if (netif_queue_stopped(tmp_ax->dev))
return 1;
if (tmp_ax != NULL)
if (netif_queue_stopped(dev)) {
printk(KERN_ERR "mkiss: dev busy while serial dev is free\n");
ax_unlock(ax);
}
if (netif_queue_stopped(dev)) { if (netif_queue_stopped(dev)) {
/* /*
* May be we must check transmitter timeout here ? * May be we must check transmitter timeout here ?
...@@ -495,8 +441,6 @@ static int ax_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -495,8 +441,6 @@ static int ax_xmit(struct sk_buff *skb, struct net_device *dev)
/* We were not busy, so we are now... :-) */ /* We were not busy, so we are now... :-) */
if (skb != NULL) { if (skb != NULL) {
ax_lock(ax); ax_lock(ax);
if (tmp_ax != NULL)
ax_lock(tmp_ax);
ax_encaps(ax, skb->data, skb->len); ax_encaps(ax, skb->data, skb->len);
kfree_skb(skb); kfree_skb(skb);
} }
...@@ -634,9 +578,7 @@ static void ax25_receive_buf(struct tty_struct *tty, const unsigned char *cp, ch ...@@ -634,9 +578,7 @@ static void ax25_receive_buf(struct tty_struct *tty, const unsigned char *cp, ch
static int ax25_open(struct tty_struct *tty) static int ax25_open(struct tty_struct *tty)
{ {
struct ax_disp *ax = (struct ax_disp *) tty->disc_data; struct ax_disp *ax = (struct ax_disp *) tty->disc_data;
struct ax_disp *tmp_ax; int err;
struct mkiss_channel *mkiss;
int err, cnt;
/* First make sure we're not already connected. */ /* First make sure we're not already connected. */
if (ax && ax->magic == AX25_MAGIC) if (ax && ax->magic == AX25_MAGIC)
...@@ -649,9 +591,6 @@ static int ax25_open(struct tty_struct *tty) ...@@ -649,9 +591,6 @@ static int ax25_open(struct tty_struct *tty)
ax->tty = tty; ax->tty = tty;
tty->disc_data = ax; tty->disc_data = ax;
ax->mkiss = NULL;
tmp_ax = NULL;
if (tty->driver->flush_buffer) if (tty->driver->flush_buffer)
tty->driver->flush_buffer(tty); tty->driver->flush_buffer(tty);
if (tty->ldisc.flush_buffer) if (tty->ldisc.flush_buffer)
...@@ -664,29 +603,6 @@ static int ax25_open(struct tty_struct *tty) ...@@ -664,29 +603,6 @@ static int ax25_open(struct tty_struct *tty)
if ((err = ax_open(ax->dev))) if ((err = ax_open(ax->dev)))
return err; return err;
mkiss = ax->tty->driver_data;
if (mkiss->magic == MKISS_DRIVER_MAGIC) {
for (cnt = 1; cnt < ax25_maxdev; cnt++) {
if (ax25_ctrls[cnt]) {
if (netif_running(&ax25_ctrls[cnt]->dev)) {
if (ax == &ax25_ctrls[cnt]->ctrl) {
cnt--;
tmp_ax = &ax25_ctrls[cnt]->ctrl;
break;
}
}
}
}
}
if (tmp_ax != NULL) {
ax->mkiss = tmp_ax;
tmp_ax->mkiss = ax;
}
MOD_INC_USE_COUNT;
/* Done. We have linked the TTY line to a channel. */ /* Done. We have linked the TTY line to a channel. */
return ax->dev->base_addr; return ax->dev->base_addr;
} }
...@@ -705,7 +621,6 @@ static void ax25_close(struct tty_struct *tty) ...@@ -705,7 +621,6 @@ static void ax25_close(struct tty_struct *tty)
ax->tty = NULL; ax->tty = NULL;
ax_free(ax); ax_free(ax);
MOD_DEC_USE_COUNT;
} }
......
...@@ -19,7 +19,6 @@ struct ax_disp { ...@@ -19,7 +19,6 @@ struct ax_disp {
/* Various fields. */ /* Various fields. */
struct tty_struct *tty; /* ptr to TTY structure */ struct tty_struct *tty; /* ptr to TTY structure */
struct net_device *dev; /* easy for intr handling */ struct net_device *dev; /* easy for intr handling */
struct ax_disp *mkiss; /* mkiss txport if mkiss channel*/
/* These are pointers to the malloc()ed frame buffers. */ /* These are pointers to the malloc()ed frame buffers. */
unsigned char *rbuff; /* receiver buffer */ unsigned char *rbuff; /* receiver buffer */
...@@ -60,4 +59,3 @@ struct ax_disp { ...@@ -60,4 +59,3 @@ struct ax_disp {
}; };
#define AX25_MAGIC 0x5316 #define AX25_MAGIC 0x5316
#define MKISS_DRIVER_MAGIC 1215
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment