Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

[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
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -436,9 +436,7 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev,
	}

	if (err) {
		if (chan->local_addr)
		kfree(chan->local_addr);

		kfree(chan);
		return err;
	}
@@ -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;

		if (chan->svc) {
			if (chan->local_addr)
			kfree(chan->local_addr);

			if (chan->state == WAN_CONNECTED)
				del_timer(&chan->timer);
		}
+11 −16
Original line number Diff line number Diff line
@@ -400,10 +400,8 @@ static void cpc_tty_close(struct tty_struct *tty, struct file *flip)
		cpc_tty->buf_rx.last = NULL;
	}
	
	if (cpc_tty->buf_tx) {
	kfree(cpc_tty->buf_tx);
	cpc_tty->buf_tx = NULL;
	}

	CPC_TTY_DBG("%s: TTY closed\n",cpc_tty->name);
	
@@ -691,7 +689,7 @@ static void cpc_tty_rx_work(void * data)
					}
				}	
				cpc_tty->buf_rx.first = cpc_tty->buf_rx.first->next;
				kfree((unsigned char *)buf);
				kfree(buf);
				buf = cpc_tty->buf_rx.first;
				flg_rx = 1;
			}
@@ -771,10 +769,7 @@ void cpc_tty_receive(pc300dev_t *pc300dev)
				cpc_writel(card->hw.scabase + DRX_REG(EDAL, ch), 
						RX_BD_ADDR(ch, pc300chan->rx_last_bd)); 
			}
			if (new) {
			kfree(new);
				new = NULL;
			}
			return; 
		}
		
+4 −9
Original line number Diff line number Diff line
@@ -3664,16 +3664,11 @@ static void wanpipe_tty_close(struct tty_struct *tty, struct file * filp)
		chdlc_disable_comm_shutdown(card);
		unlock_adapter_irq(&card->wandev.lock,&smp_flags);

		if (card->tty_buf){
		kfree(card->tty_buf);
		card->tty_buf = NULL;			
		}

		if (card->tty_rx){
		kfree(card->tty_rx);
		card->tty_rx = NULL;
	}
	}
	return;
}
static int wanpipe_tty_open(struct tty_struct *tty, struct file * filp)
+6 −14
Original line number Diff line number Diff line
@@ -107,13 +107,9 @@ static struct x25_asy *x25_asy_alloc(void)
static void x25_asy_free(struct x25_asy *sl)
{
	/* Free all X.25 frame buffers. */
	if (sl->rbuff)  {
	kfree(sl->rbuff);
	}
	sl->rbuff = NULL;
	if (sl->xbuff)  {
	kfree(sl->xbuff);
	}
	sl->xbuff = NULL;

	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)
	{
		printk("%s: unable to grow X.25 buffers, MTU change cancelled.\n",
		       dev->name);
		if (xbuff != NULL)  
		kfree(xbuff);
		if (rbuff != NULL)  
		kfree(rbuff);
		return -ENOMEM;
	}
@@ -169,9 +163,7 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu)

	spin_unlock_bh(&sl->lock);

	if (xbuff != NULL) 
	kfree(xbuff);
	if (rbuff != NULL)
	kfree(rbuff);
	return 0;
}