Commit bd5b80d51a6c4a68f7d4b9b92c495329f47e53d4
Committed by
Antonio Quartulli
1 parent
8e7c15d6b5
batman-adv: Check return value of try_module_get
New operations should not be started when they need an increased module reference counter and try_module_get failed. This patch addresses Coverity #712284: Unchecked return value Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Showing 4 changed files with 12 additions and 18 deletions Side-by-side Diff
net/batman-adv/debugfs.c
... | ... | @@ -99,15 +99,17 @@ |
99 | 99 | |
100 | 100 | static int batadv_log_open(struct inode *inode, struct file *file) |
101 | 101 | { |
102 | + if (!try_module_get(THIS_MODULE)) | |
103 | + return -EBUSY; | |
104 | + | |
102 | 105 | nonseekable_open(inode, file); |
103 | 106 | file->private_data = inode->i_private; |
104 | - batadv_inc_module_count(); | |
105 | 107 | return 0; |
106 | 108 | } |
107 | 109 | |
108 | 110 | static int batadv_log_release(struct inode *inode, struct file *file) |
109 | 111 | { |
110 | - batadv_dec_module_count(); | |
112 | + module_put(THIS_MODULE); | |
111 | 113 | return 0; |
112 | 114 | } |
113 | 115 |
net/batman-adv/icmp_socket.c
... | ... | @@ -42,12 +42,16 @@ |
42 | 42 | unsigned int i; |
43 | 43 | struct batadv_socket_client *socket_client; |
44 | 44 | |
45 | + if (!try_module_get(THIS_MODULE)) | |
46 | + return -EBUSY; | |
47 | + | |
45 | 48 | nonseekable_open(inode, file); |
46 | 49 | |
47 | 50 | socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL); |
48 | - | |
49 | - if (!socket_client) | |
51 | + if (!socket_client) { | |
52 | + module_put(THIS_MODULE); | |
50 | 53 | return -ENOMEM; |
54 | + } | |
51 | 55 | |
52 | 56 | for (i = 0; i < ARRAY_SIZE(batadv_socket_client_hash); i++) { |
53 | 57 | if (!batadv_socket_client_hash[i]) { |
... | ... | @@ -59,6 +63,7 @@ |
59 | 63 | if (i == ARRAY_SIZE(batadv_socket_client_hash)) { |
60 | 64 | pr_err("Error - can't add another packet client: maximum number of clients reached\n"); |
61 | 65 | kfree(socket_client); |
66 | + module_put(THIS_MODULE); | |
62 | 67 | return -EXFULL; |
63 | 68 | } |
64 | 69 | |
... | ... | @@ -71,7 +76,6 @@ |
71 | 76 | |
72 | 77 | file->private_data = socket_client; |
73 | 78 | |
74 | - batadv_inc_module_count(); | |
75 | 79 | return 0; |
76 | 80 | } |
77 | 81 | |
... | ... | @@ -96,7 +100,7 @@ |
96 | 100 | spin_unlock_bh(&socket_client->lock); |
97 | 101 | |
98 | 102 | kfree(socket_client); |
99 | - batadv_dec_module_count(); | |
103 | + module_put(THIS_MODULE); | |
100 | 104 | |
101 | 105 | return 0; |
102 | 106 | } |
net/batman-adv/main.c
... | ... | @@ -160,16 +160,6 @@ |
160 | 160 | atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE); |
161 | 161 | } |
162 | 162 | |
163 | -void batadv_inc_module_count(void) | |
164 | -{ | |
165 | - try_module_get(THIS_MODULE); | |
166 | -} | |
167 | - | |
168 | -void batadv_dec_module_count(void) | |
169 | -{ | |
170 | - module_put(THIS_MODULE); | |
171 | -} | |
172 | - | |
173 | 163 | int batadv_is_my_mac(const uint8_t *addr) |
174 | 164 | { |
175 | 165 | const struct batadv_hard_iface *hard_iface; |
net/batman-adv/main.h
... | ... | @@ -150,8 +150,6 @@ |
150 | 150 | |
151 | 151 | int batadv_mesh_init(struct net_device *soft_iface); |
152 | 152 | void batadv_mesh_free(struct net_device *soft_iface); |
153 | -void batadv_inc_module_count(void); | |
154 | -void batadv_dec_module_count(void); | |
155 | 153 | int batadv_is_my_mac(const uint8_t *addr); |
156 | 154 | struct batadv_hard_iface * |
157 | 155 | batadv_seq_print_text_primary_if_get(struct seq_file *seq); |