diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index 0bbb283f23c96ff434d9f7c427971ed44236c3af..046d3fee66a9017e45ef9988d98917dde97d8be5 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -825,7 +825,7 @@ static int x25_connect(struct socket *sock, struct sockaddr *uaddr,
 	sock->state = SS_CONNECTED;
 	rc = 0;
 out_put_neigh:
-	if (rc) {
+	if (rc && x25->neighbour) {
 		read_lock_bh(&x25_list_lock);
 		x25_neigh_put(x25->neighbour);
 		x25->neighbour = NULL;