aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorSven Eckelmann <sven@narfation.org>2012-08-20 17:37:26 -0400
committerAntonio Quartulli <ordex@autistici.org>2012-10-29 04:42:36 -0400
commitbd5b80d51a6c4a68f7d4b9b92c495329f47e53d4 (patch)
tree8650acb5b824f001651186e1357f4b7666437330 /net
parent8e7c15d6b5468f0dcdd887db1e5df88e629c00d6 (diff)
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>
Diffstat (limited to 'net')
-rw-r--r--net/batman-adv/debugfs.c6
-rw-r--r--net/batman-adv/icmp_socket.c12
-rw-r--r--net/batman-adv/main.c10
-rw-r--r--net/batman-adv/main.h2
4 files changed, 12 insertions, 18 deletions
diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c
index 391d4fb2026f..bd032bc4e262 100644
--- a/net/batman-adv/debugfs.c
+++ b/net/batman-adv/debugfs.c
@@ -99,15 +99,17 @@ int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
99 99
100static int batadv_log_open(struct inode *inode, struct file *file) 100static int batadv_log_open(struct inode *inode, struct file *file)
101{ 101{
102 if (!try_module_get(THIS_MODULE))
103 return -EBUSY;
104
102 nonseekable_open(inode, file); 105 nonseekable_open(inode, file);
103 file->private_data = inode->i_private; 106 file->private_data = inode->i_private;
104 batadv_inc_module_count();
105 return 0; 107 return 0;
106} 108}
107 109
108static int batadv_log_release(struct inode *inode, struct file *file) 110static int batadv_log_release(struct inode *inode, struct file *file)
109{ 111{
110 batadv_dec_module_count(); 112 module_put(THIS_MODULE);
111 return 0; 113 return 0;
112} 114}
113 115
diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c
index bde3cf747507..5874c0e84846 100644
--- a/net/batman-adv/icmp_socket.c
+++ b/net/batman-adv/icmp_socket.c
@@ -42,12 +42,16 @@ static int batadv_socket_open(struct inode *inode, struct file *file)
42 unsigned int i; 42 unsigned int i;
43 struct batadv_socket_client *socket_client; 43 struct batadv_socket_client *socket_client;
44 44
45 if (!try_module_get(THIS_MODULE))
46 return -EBUSY;
47
45 nonseekable_open(inode, file); 48 nonseekable_open(inode, file);
46 49
47 socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL); 50 socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL);
48 51 if (!socket_client) {
49 if (!socket_client) 52 module_put(THIS_MODULE);
50 return -ENOMEM; 53 return -ENOMEM;
54 }
51 55
52 for (i = 0; i < ARRAY_SIZE(batadv_socket_client_hash); i++) { 56 for (i = 0; i < ARRAY_SIZE(batadv_socket_client_hash); i++) {
53 if (!batadv_socket_client_hash[i]) { 57 if (!batadv_socket_client_hash[i]) {
@@ -59,6 +63,7 @@ static int batadv_socket_open(struct inode *inode, struct file *file)
59 if (i == ARRAY_SIZE(batadv_socket_client_hash)) { 63 if (i == ARRAY_SIZE(batadv_socket_client_hash)) {
60 pr_err("Error - can't add another packet client: maximum number of clients reached\n"); 64 pr_err("Error - can't add another packet client: maximum number of clients reached\n");
61 kfree(socket_client); 65 kfree(socket_client);
66 module_put(THIS_MODULE);
62 return -EXFULL; 67 return -EXFULL;
63 } 68 }
64 69
@@ -71,7 +76,6 @@ static int batadv_socket_open(struct inode *inode, struct file *file)
71 76
72 file->private_data = socket_client; 77 file->private_data = socket_client;
73 78
74 batadv_inc_module_count();
75 return 0; 79 return 0;
76} 80}
77 81
@@ -96,7 +100,7 @@ static int batadv_socket_release(struct inode *inode, struct file *file)
96 spin_unlock_bh(&socket_client->lock); 100 spin_unlock_bh(&socket_client->lock);
97 101
98 kfree(socket_client); 102 kfree(socket_client);
99 batadv_dec_module_count(); 103 module_put(THIS_MODULE);
100 104
101 return 0; 105 return 0;
102} 106}
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index a4a337d9af9c..f9bcfa17f50f 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -160,16 +160,6 @@ void batadv_mesh_free(struct net_device *soft_iface)
160 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE); 160 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
161} 161}
162 162
163void batadv_inc_module_count(void)
164{
165 try_module_get(THIS_MODULE);
166}
167
168void batadv_dec_module_count(void)
169{
170 module_put(THIS_MODULE);
171}
172
173int batadv_is_my_mac(const uint8_t *addr) 163int batadv_is_my_mac(const uint8_t *addr)
174{ 164{
175 const struct batadv_hard_iface *hard_iface; 165 const struct batadv_hard_iface *hard_iface;
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 5c0be5b13415..9b94f05f8a17 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -150,8 +150,6 @@ extern struct workqueue_struct *batadv_event_workqueue;
150 150
151int batadv_mesh_init(struct net_device *soft_iface); 151int batadv_mesh_init(struct net_device *soft_iface);
152void batadv_mesh_free(struct net_device *soft_iface); 152void batadv_mesh_free(struct net_device *soft_iface);
153void batadv_inc_module_count(void);
154void batadv_dec_module_count(void);
155int batadv_is_my_mac(const uint8_t *addr); 153int batadv_is_my_mac(const uint8_t *addr);
156struct batadv_hard_iface * 154struct batadv_hard_iface *
157batadv_seq_print_text_primary_if_get(struct seq_file *seq); 155batadv_seq_print_text_primary_if_get(struct seq_file *seq);