Commit 6a5d3621 authored by Jesper Juhl's avatar Jesper Juhl Committed by David S. Miller

[WAN]: kfree of NULL pointer is valid

kfree(0) is perfectly valid, checking pointers for NULL before calling 
kfree() on them is redundant. The patch below cleans away a few such 
redundant checks (and while I was around some of those bits I couldn't 
stop myself from making a few tiny whitespace changes as well).
Signed-off-by: default avatarJesper Juhl <juhl-lkml@dif.dk>
Acked-by: default avatarArnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent db46edc6
...@@ -436,9 +436,7 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev, ...@@ -436,9 +436,7 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev,
} }
if (err) { if (err) {
if (chan->local_addr)
kfree(chan->local_addr); kfree(chan->local_addr);
kfree(chan); kfree(chan);
return err; return err;
} }
...@@ -458,9 +456,7 @@ static int cycx_wan_del_if(struct wan_device *wandev, struct net_device *dev) ...@@ -458,9 +456,7 @@ static int cycx_wan_del_if(struct wan_device *wandev, struct net_device *dev)
struct cycx_x25_channel *chan = dev->priv; struct cycx_x25_channel *chan = dev->priv;
if (chan->svc) { if (chan->svc) {
if (chan->local_addr)
kfree(chan->local_addr); kfree(chan->local_addr);
if (chan->state == WAN_CONNECTED) if (chan->state == WAN_CONNECTED)
del_timer(&chan->timer); del_timer(&chan->timer);
} }
......
...@@ -400,10 +400,8 @@ static void cpc_tty_close(struct tty_struct *tty, struct file *flip) ...@@ -400,10 +400,8 @@ static void cpc_tty_close(struct tty_struct *tty, struct file *flip)
cpc_tty->buf_rx.last = NULL; cpc_tty->buf_rx.last = NULL;
} }
if (cpc_tty->buf_tx) {
kfree(cpc_tty->buf_tx); kfree(cpc_tty->buf_tx);
cpc_tty->buf_tx = NULL; cpc_tty->buf_tx = NULL;
}
CPC_TTY_DBG("%s: TTY closed\n",cpc_tty->name); CPC_TTY_DBG("%s: TTY closed\n",cpc_tty->name);
...@@ -666,7 +664,7 @@ static void cpc_tty_rx_work(void * data) ...@@ -666,7 +664,7 @@ static void cpc_tty_rx_work(void * data)
unsigned long port; unsigned long port;
int i, j; int i, j;
st_cpc_tty_area *cpc_tty; st_cpc_tty_area *cpc_tty;
volatile st_cpc_rx_buf * buf; volatile st_cpc_rx_buf *buf;
char flags=0,flg_rx=1; char flags=0,flg_rx=1;
struct tty_ldisc *ld; struct tty_ldisc *ld;
...@@ -680,9 +678,9 @@ static void cpc_tty_rx_work(void * data) ...@@ -680,9 +678,9 @@ static void cpc_tty_rx_work(void * data)
cpc_tty = &cpc_tty_area[port]; cpc_tty = &cpc_tty_area[port];
if ((buf=cpc_tty->buf_rx.first) != 0) { if ((buf=cpc_tty->buf_rx.first) != 0) {
if(cpc_tty->tty) { if (cpc_tty->tty) {
ld = tty_ldisc_ref(cpc_tty->tty); ld = tty_ldisc_ref(cpc_tty->tty);
if(ld) { if (ld) {
if (ld->receive_buf) { if (ld->receive_buf) {
CPC_TTY_DBG("%s: call line disc. receive_buf\n",cpc_tty->name); CPC_TTY_DBG("%s: call line disc. receive_buf\n",cpc_tty->name);
ld->receive_buf(cpc_tty->tty, (char *)(buf->data), &flags, buf->size); ld->receive_buf(cpc_tty->tty, (char *)(buf->data), &flags, buf->size);
...@@ -691,7 +689,7 @@ static void cpc_tty_rx_work(void * data) ...@@ -691,7 +689,7 @@ static void cpc_tty_rx_work(void * data)
} }
} }
cpc_tty->buf_rx.first = cpc_tty->buf_rx.first->next; cpc_tty->buf_rx.first = cpc_tty->buf_rx.first->next;
kfree((unsigned char *)buf); kfree(buf);
buf = cpc_tty->buf_rx.first; buf = cpc_tty->buf_rx.first;
flg_rx = 1; flg_rx = 1;
} }
...@@ -742,7 +740,7 @@ void cpc_tty_receive(pc300dev_t *pc300dev) ...@@ -742,7 +740,7 @@ void cpc_tty_receive(pc300dev_t *pc300dev)
int rx_len, rx_aux; int rx_len, rx_aux;
volatile unsigned char status; volatile unsigned char status;
unsigned short first_bd = pc300chan->rx_first_bd; unsigned short first_bd = pc300chan->rx_first_bd;
st_cpc_rx_buf *new=NULL; st_cpc_rx_buf *new = NULL;
unsigned char dsr_rx; unsigned char dsr_rx;
if (pc300dev->cpc_tty == NULL) { if (pc300dev->cpc_tty == NULL) {
...@@ -762,7 +760,7 @@ void cpc_tty_receive(pc300dev_t *pc300dev) ...@@ -762,7 +760,7 @@ void cpc_tty_receive(pc300dev_t *pc300dev)
if (status & DST_EOM) { if (status & DST_EOM) {
break; break;
} }
ptdescr=(pcsca_bd_t __iomem *)(card->hw.rambase+cpc_readl(&ptdescr->next)); ptdescr = (pcsca_bd_t __iomem *)(card->hw.rambase+cpc_readl(&ptdescr->next));
} }
if (!rx_len) { if (!rx_len) {
...@@ -771,10 +769,7 @@ void cpc_tty_receive(pc300dev_t *pc300dev) ...@@ -771,10 +769,7 @@ void cpc_tty_receive(pc300dev_t *pc300dev)
cpc_writel(card->hw.scabase + DRX_REG(EDAL, ch), cpc_writel(card->hw.scabase + DRX_REG(EDAL, ch),
RX_BD_ADDR(ch, pc300chan->rx_last_bd)); RX_BD_ADDR(ch, pc300chan->rx_last_bd));
} }
if (new) {
kfree(new); kfree(new);
new = NULL;
}
return; return;
} }
...@@ -787,7 +782,7 @@ void cpc_tty_receive(pc300dev_t *pc300dev) ...@@ -787,7 +782,7 @@ void cpc_tty_receive(pc300dev_t *pc300dev)
continue; continue;
} }
new = (st_cpc_rx_buf *) kmalloc(rx_len + sizeof(st_cpc_rx_buf), GFP_ATOMIC); new = (st_cpc_rx_buf *)kmalloc(rx_len + sizeof(st_cpc_rx_buf), GFP_ATOMIC);
if (new == 0) { if (new == 0) {
cpc_tty_rx_disc_frame(pc300chan); cpc_tty_rx_disc_frame(pc300chan);
continue; continue;
......
...@@ -3664,15 +3664,10 @@ static void wanpipe_tty_close(struct tty_struct *tty, struct file * filp) ...@@ -3664,15 +3664,10 @@ static void wanpipe_tty_close(struct tty_struct *tty, struct file * filp)
chdlc_disable_comm_shutdown(card); chdlc_disable_comm_shutdown(card);
unlock_adapter_irq(&card->wandev.lock,&smp_flags); unlock_adapter_irq(&card->wandev.lock,&smp_flags);
if (card->tty_buf){
kfree(card->tty_buf); kfree(card->tty_buf);
card->tty_buf=NULL; card->tty_buf = NULL;
}
if (card->tty_rx){
kfree(card->tty_rx); kfree(card->tty_rx);
card->tty_rx=NULL; card->tty_rx = NULL;
}
} }
return; return;
} }
......
...@@ -107,13 +107,9 @@ static struct x25_asy *x25_asy_alloc(void) ...@@ -107,13 +107,9 @@ static struct x25_asy *x25_asy_alloc(void)
static void x25_asy_free(struct x25_asy *sl) static void x25_asy_free(struct x25_asy *sl)
{ {
/* Free all X.25 frame buffers. */ /* Free all X.25 frame buffers. */
if (sl->rbuff) {
kfree(sl->rbuff); kfree(sl->rbuff);
}
sl->rbuff = NULL; sl->rbuff = NULL;
if (sl->xbuff) {
kfree(sl->xbuff); kfree(sl->xbuff);
}
sl->xbuff = NULL; sl->xbuff = NULL;
if (!test_and_clear_bit(SLF_INUSE, &sl->flags)) { if (!test_and_clear_bit(SLF_INUSE, &sl->flags)) {
...@@ -134,9 +130,7 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu) ...@@ -134,9 +130,7 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu)
{ {
printk("%s: unable to grow X.25 buffers, MTU change cancelled.\n", printk("%s: unable to grow X.25 buffers, MTU change cancelled.\n",
dev->name); dev->name);
if (xbuff != NULL)
kfree(xbuff); kfree(xbuff);
if (rbuff != NULL)
kfree(rbuff); kfree(rbuff);
return -ENOMEM; return -ENOMEM;
} }
...@@ -169,9 +163,7 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu) ...@@ -169,9 +163,7 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu)
spin_unlock_bh(&sl->lock); spin_unlock_bh(&sl->lock);
if (xbuff != NULL)
kfree(xbuff); kfree(xbuff);
if (rbuff != NULL)
kfree(rbuff); kfree(rbuff);
return 0; return 0;
} }
......
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