Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

caif: Bugfix debugfs directory name must be unique.

Race condition caused debugfs_create_dir() to fail due to duplicate
name. Use atomic counter to create unique directory name.

net_ratelimit() is introduced to limit debug printouts.

Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

sjur.brandeland@stericsson.com and committed by
David S. Miller
33b2f559 c85c2951

+22 -12
+22 -12
net/caif/caif_socket.c
··· 48 48 #ifdef CONFIG_DEBUG_FS 49 49 struct debug_fs_counter { 50 50 atomic_t caif_nr_socks; 51 + atomic_t caif_sock_create; 51 52 atomic_t num_connect_req; 52 53 atomic_t num_connect_resp; 53 54 atomic_t num_connect_fail_resp; ··· 60 59 atomic_t num_rx_flow_on; 61 60 }; 62 61 static struct debug_fs_counter cnt; 63 - #define dbfs_atomic_inc(v) atomic_inc(v) 64 - #define dbfs_atomic_dec(v) atomic_dec(v) 62 + #define dbfs_atomic_inc(v) atomic_inc_return(v) 63 + #define dbfs_atomic_dec(v) atomic_dec_return(v) 65 64 #else 66 - #define dbfs_atomic_inc(v) 67 - #define dbfs_atomic_dec(v) 65 + #define dbfs_atomic_inc(v) 0 66 + #define dbfs_atomic_dec(v) 0 68 67 #endif 69 68 70 69 struct caifsock { ··· 156 155 157 156 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >= 158 157 (unsigned)sk->sk_rcvbuf && rx_flow_is_on(cf_sk)) { 159 - pr_debug("sending flow OFF (queue len = %d %d)\n", 160 - atomic_read(&cf_sk->sk.sk_rmem_alloc), 161 - sk_rcvbuf_lowwater(cf_sk)); 158 + if (net_ratelimit()) 159 + pr_debug("sending flow OFF (queue len = %d %d)\n", 160 + atomic_read(&cf_sk->sk.sk_rmem_alloc), 161 + sk_rcvbuf_lowwater(cf_sk)); 162 162 set_rx_flow_off(cf_sk); 163 163 dbfs_atomic_inc(&cnt.num_rx_flow_off); 164 164 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ); ··· 170 168 return err; 171 169 if (!sk_rmem_schedule(sk, skb->truesize) && rx_flow_is_on(cf_sk)) { 172 170 set_rx_flow_off(cf_sk); 173 - pr_debug("sending flow OFF due to rmem_schedule\n"); 171 + if (net_ratelimit()) 172 + pr_debug("sending flow OFF due to rmem_schedule\n"); 174 173 dbfs_atomic_inc(&cnt.num_rx_flow_off); 175 174 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ); 176 175 } ··· 841 838 sock->state = SS_CONNECTING; 842 839 sk->sk_state = CAIF_CONNECTING; 843 840 844 - /* Check priority value coming from socket */ 841 + /* Check priority value comming from socket */ 845 842 /* if priority value is out of range it will be ajusted */ 846 843 if (cf_sk->sk.sk_priority > CAIF_PRIO_MAX) 847 844 cf_sk->conn_req.priority = CAIF_PRIO_MAX; ··· 945 942 946 943 dbfs_atomic_inc(&cnt.num_disconnect); 947 944 945 + WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir)); 948 946 if (cf_sk->debugfs_socket_dir != NULL) 949 947 debugfs_remove_recursive(cf_sk->debugfs_socket_dir); 950 948 ··· 1051 1047 caif_assert(sk_unhashed(sk)); 1052 1048 caif_assert(!sk->sk_socket); 1053 1049 if (!sock_flag(sk, SOCK_DEAD)) { 1054 - pr_info("Attempt to release alive CAIF socket: %p\n", sk); 1050 + pr_debug("Attempt to release alive CAIF socket: %p\n", sk); 1055 1051 return; 1056 1052 } 1057 1053 sk_stream_kill_queues(&cf_sk->sk); ··· 1062 1058 static int caif_create(struct net *net, struct socket *sock, int protocol, 1063 1059 int kern) 1064 1060 { 1061 + int num; 1065 1062 struct sock *sk = NULL; 1066 1063 struct caifsock *cf_sk = NULL; 1067 1064 static struct proto prot = {.name = "PF_CAIF", ··· 1125 1120 cf_sk->conn_req.protocol = protocol; 1126 1121 /* Increase the number of sockets created. */ 1127 1122 dbfs_atomic_inc(&cnt.caif_nr_socks); 1123 + num = dbfs_atomic_inc(&cnt.caif_sock_create); 1128 1124 #ifdef CONFIG_DEBUG_FS 1129 1125 if (!IS_ERR(debugfsdir)) { 1126 + 1130 1127 /* Fill in some information concerning the misc socket. */ 1131 - snprintf(cf_sk->name, sizeof(cf_sk->name), "cfsk%d", 1132 - atomic_read(&cnt.caif_nr_socks)); 1128 + snprintf(cf_sk->name, sizeof(cf_sk->name), "cfsk%d", num); 1133 1129 1134 1130 cf_sk->debugfs_socket_dir = 1135 1131 debugfs_create_dir(cf_sk->name, debugfsdir); 1132 + 1136 1133 debugfs_create_u32("sk_state", S_IRUSR | S_IWUSR, 1137 1134 cf_sk->debugfs_socket_dir, 1138 1135 (u32 *) &cf_sk->sk.sk_state); ··· 1178 1171 debugfs_create_u32("num_sockets", S_IRUSR | S_IWUSR, 1179 1172 debugfsdir, 1180 1173 (u32 *) &cnt.caif_nr_socks); 1174 + debugfs_create_u32("num_create", S_IRUSR | S_IWUSR, 1175 + debugfsdir, 1176 + (u32 *) &cnt.caif_sock_create); 1181 1177 debugfs_create_u32("num_connect_req", S_IRUSR | S_IWUSR, 1182 1178 debugfsdir, 1183 1179 (u32 *) &cnt.num_connect_req);